Added controller activation signal
This commit is contained in:
parent
3ba39992bc
commit
d1b46fb9e0
@ -16,7 +16,7 @@ func _ready():
|
|||||||
Global.account.id = "test"
|
Global.account.id = "test"
|
||||||
Global.account.name = "Local"
|
Global.account.name = "Local"
|
||||||
Global.account.auth_token = "test"
|
Global.account.auth_token = "test"
|
||||||
Global.player = %PlayerAdd.spawn_player(Global.account.id)
|
Global.player = %PlayerAdd.spawn_player(Global.account.id, Global.account.name, Vector3.ZERO)
|
||||||
%Login.success.emit()
|
%Login.success.emit()
|
||||||
else:
|
else:
|
||||||
%Login.send_login()
|
%Login.send_login()
|
||||||
|
@ -1,7 +1,2 @@
|
|||||||
class_name Enemy
|
class_name Enemy
|
||||||
extends Character
|
extends Character
|
||||||
|
|
||||||
func _init():
|
|
||||||
controller = EnemyController.new()
|
|
||||||
add_child(controller)
|
|
||||||
controller.owner = self
|
|
@ -21,10 +21,9 @@ func handle_packet(data: PackedByteArray):
|
|||||||
|
|
||||||
%Client.log("Add player: %s %s @ %v" % [player_id, player_name, server_position])
|
%Client.log("Add player: %s %s @ %v" % [player_id, player_name, server_position])
|
||||||
|
|
||||||
var player := spawn_player(player_id, server_position)
|
spawn_player(player_id, player_name, server_position)
|
||||||
player.set_player_name(player_name)
|
|
||||||
|
|
||||||
func spawn_player(id: String, position: Vector3) -> Player:
|
func spawn_player(id: String, nick: String, position: Vector3) -> Player:
|
||||||
var player: Player
|
var player: Player
|
||||||
|
|
||||||
if Global.players.has(id):
|
if Global.players.has(id):
|
||||||
@ -38,14 +37,17 @@ func spawn_player(id: String, position: Vector3) -> Player:
|
|||||||
player = player_scene.instantiate()
|
player = player_scene.instantiate()
|
||||||
player.id = id
|
player.id = id
|
||||||
player.position = position
|
player.position = position
|
||||||
|
var controller: Controller
|
||||||
|
|
||||||
if id == Global.account.id:
|
if id == Global.account.id:
|
||||||
player.controller = PlayerController.new(player)
|
controller = PlayerController.new(player)
|
||||||
Global.player = player
|
Global.player = player
|
||||||
main_player_spawned.emit(player)
|
main_player_spawned.emit(player)
|
||||||
else:
|
else:
|
||||||
player.controller = ProxyController.new(player)
|
controller = ProxyController.new(player)
|
||||||
|
|
||||||
player.add_child(player.controller)
|
player.set_player_name(nick)
|
||||||
|
player.add_child(controller)
|
||||||
Global.players.add(player)
|
Global.players.add(player)
|
||||||
|
controller.control(player)
|
||||||
return player
|
return player
|
||||||
|
@ -4,7 +4,10 @@ func _ready():
|
|||||||
%PlayerAdd.main_player_spawned.connect(on_main_player_spawned)
|
%PlayerAdd.main_player_spawned.connect(on_main_player_spawned)
|
||||||
|
|
||||||
func on_main_player_spawned(player: Player):
|
func on_main_player_spawned(player: Player):
|
||||||
player.controller.jumped.connect(on_jump)
|
player.controlled.connect(on_main_player_controlled)
|
||||||
|
|
||||||
|
func on_main_player_controlled(controller: Controller):
|
||||||
|
controller.jumped.connect(on_jump)
|
||||||
|
|
||||||
func on_jump():
|
func on_jump():
|
||||||
var buffer := StreamPeerBuffer.new()
|
var buffer := StreamPeerBuffer.new()
|
||||||
|
@ -4,7 +4,10 @@ func _ready():
|
|||||||
%PlayerAdd.main_player_spawned.connect(on_main_player_spawned)
|
%PlayerAdd.main_player_spawned.connect(on_main_player_spawned)
|
||||||
|
|
||||||
func on_main_player_spawned(player: Player):
|
func on_main_player_spawned(player: Player):
|
||||||
player.controller.used_skill.connect(on_skill_used)
|
player.controlled.connect(on_main_player_controlled)
|
||||||
|
|
||||||
|
func on_main_player_controlled(controller: Controller):
|
||||||
|
controller.used_skill.connect(on_skill_used)
|
||||||
|
|
||||||
func on_skill_used(slot: int):
|
func on_skill_used(slot: int):
|
||||||
var buffer := StreamPeerBuffer.new()
|
var buffer := StreamPeerBuffer.new()
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
class_name Character
|
class_name Character
|
||||||
extends CharacterBody3D
|
extends CharacterBody3D
|
||||||
|
|
||||||
|
signal controlled(Controller)
|
||||||
|
|
||||||
var controller: Controller
|
var controller: Controller
|
@ -4,3 +4,7 @@ extends Node
|
|||||||
signal direction_changed(direction: Vector3)
|
signal direction_changed(direction: Vector3)
|
||||||
signal jumped
|
signal jumped
|
||||||
signal used_skill(slot: int)
|
signal used_skill(slot: int)
|
||||||
|
|
||||||
|
func control(character: Character):
|
||||||
|
character.controller = self
|
||||||
|
character.controlled.emit(self)
|
||||||
|
@ -10,10 +10,13 @@ var direction: Vector3
|
|||||||
var gravity: float
|
var gravity: float
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
body = owner as Character
|
|
||||||
body.controller.direction_changed.connect(on_direction_changed)
|
|
||||||
body.controller.jumped.connect(jump)
|
|
||||||
gravity = ProjectSettings.get_setting("physics/3d/default_gravity")
|
gravity = ProjectSettings.get_setting("physics/3d/default_gravity")
|
||||||
|
body = owner as Character
|
||||||
|
body.controlled.connect(on_controlled)
|
||||||
|
|
||||||
|
func on_controlled(controller: Controller):
|
||||||
|
controller.direction_changed.connect(on_direction_changed)
|
||||||
|
controller.jumped.connect(jump)
|
||||||
|
|
||||||
func _physics_process(delta):
|
func _physics_process(delta):
|
||||||
if direction:
|
if direction:
|
||||||
|
@ -9,11 +9,14 @@ var angle: float
|
|||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
assert(root, "Rotation root needs to be set")
|
assert(root, "Rotation root needs to be set")
|
||||||
owner.controller.direction_changed.connect(on_direction_changed)
|
(owner as Character).controlled.connect(on_controlled)
|
||||||
|
|
||||||
func _process(delta):
|
func _process(delta):
|
||||||
root.rotation.y = Math.damp_angle(root.rotation.y, angle, rotation_speed * delta)
|
root.rotation.y = Math.damp_angle(root.rotation.y, angle, rotation_speed * delta)
|
||||||
|
|
||||||
|
func on_controlled(controller: Controller):
|
||||||
|
controller.direction_changed.connect(on_direction_changed)
|
||||||
|
|
||||||
func on_direction_changed(new_direction: Vector3):
|
func on_direction_changed(new_direction: Vector3):
|
||||||
direction = new_direction
|
direction = new_direction
|
||||||
|
|
||||||
|
@ -7,7 +7,10 @@ var character: Character
|
|||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
character = owner
|
character = owner
|
||||||
character.controller.used_skill.connect(use_skill)
|
character.controlled.connect(on_controlled)
|
||||||
|
|
||||||
|
func on_controlled(controller: Controller):
|
||||||
|
controller.used_skill.connect(use_skill)
|
||||||
|
|
||||||
func use_skill(slot: int):
|
func use_skill(slot: int):
|
||||||
if slot < 0 || slot >= skills.size():
|
if slot < 0 || slot >= skills.size():
|
||||||
|
Loading…
Reference in New Issue
Block a user