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.name = "Local"
|
||||
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()
|
||||
else:
|
||||
%Login.send_login()
|
||||
|
@ -1,7 +1,2 @@
|
||||
class_name Enemy
|
||||
extends Character
|
||||
|
||||
func _init():
|
||||
controller = EnemyController.new()
|
||||
add_child(controller)
|
||||
controller.owner = self
|
||||
extends Character
|
@ -21,10 +21,9 @@ func handle_packet(data: PackedByteArray):
|
||||
|
||||
%Client.log("Add player: %s %s @ %v" % [player_id, player_name, server_position])
|
||||
|
||||
var player := spawn_player(player_id, server_position)
|
||||
player.set_player_name(player_name)
|
||||
spawn_player(player_id, player_name, server_position)
|
||||
|
||||
func spawn_player(id: String, position: Vector3) -> Player:
|
||||
func spawn_player(id: String, nick: String, position: Vector3) -> Player:
|
||||
var player: Player
|
||||
|
||||
if Global.players.has(id):
|
||||
@ -32,20 +31,23 @@ func spawn_player(id: String, position: Vector3) -> Player:
|
||||
|
||||
if id == Global.account.id:
|
||||
Global.player = player
|
||||
|
||||
|
||||
return player
|
||||
|
||||
|
||||
player = player_scene.instantiate()
|
||||
player.id = id
|
||||
player.position = position
|
||||
var controller: Controller
|
||||
|
||||
if id == Global.account.id:
|
||||
player.controller = PlayerController.new(player)
|
||||
controller = PlayerController.new(player)
|
||||
Global.player = player
|
||||
main_player_spawned.emit(player)
|
||||
else:
|
||||
player.controller = ProxyController.new(player)
|
||||
|
||||
player.add_child(player.controller)
|
||||
controller = ProxyController.new(player)
|
||||
|
||||
player.set_player_name(nick)
|
||||
player.add_child(controller)
|
||||
Global.players.add(player)
|
||||
controller.control(player)
|
||||
return player
|
||||
|
@ -4,7 +4,10 @@ func _ready():
|
||||
%PlayerAdd.main_player_spawned.connect(on_main_player_spawned)
|
||||
|
||||
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():
|
||||
var buffer := StreamPeerBuffer.new()
|
||||
|
@ -4,7 +4,10 @@ func _ready():
|
||||
%PlayerAdd.main_player_spawned.connect(on_main_player_spawned)
|
||||
|
||||
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):
|
||||
var buffer := StreamPeerBuffer.new()
|
||||
|
@ -1,4 +1,6 @@
|
||||
class_name Character
|
||||
extends CharacterBody3D
|
||||
|
||||
signal controlled(Controller)
|
||||
|
||||
var controller: Controller
|
@ -3,4 +3,8 @@ extends Node
|
||||
|
||||
signal direction_changed(direction: Vector3)
|
||||
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
|
||||
|
||||
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")
|
||||
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):
|
||||
if direction:
|
||||
|
@ -9,11 +9,14 @@ var angle: float
|
||||
|
||||
func _ready():
|
||||
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):
|
||||
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):
|
||||
direction = new_direction
|
||||
|
||||
|
@ -7,7 +7,10 @@ var character: Character
|
||||
|
||||
func _ready():
|
||||
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):
|
||||
if slot < 0 || slot >= skills.size():
|
||||
|
Loading…
Reference in New Issue
Block a user