added camera
This commit is contained in:
@@ -1,7 +1,12 @@
|
|||||||
extends CharacterBody2D
|
extends CharacterBody2D
|
||||||
class_name Player
|
class_name Player
|
||||||
|
|
||||||
var session_id: String
|
var session_id: String#
|
||||||
|
var is_current_player: bool
|
||||||
|
|
||||||
func _enter_tree() -> void:
|
func _enter_tree() -> void:
|
||||||
$NameTag.text = session_id
|
$NameTag.text = session_id
|
||||||
|
|
||||||
|
func make_current() -> void:
|
||||||
|
$Camera2D.enabled = true
|
||||||
|
is_current_player = true
|
||||||
|
@@ -27,3 +27,6 @@ offset_right = 20.0
|
|||||||
offset_bottom = 11.5
|
offset_bottom = 11.5
|
||||||
grow_horizontal = 2
|
grow_horizontal = 2
|
||||||
grow_vertical = 2
|
grow_vertical = 2
|
||||||
|
|
||||||
|
[node name="Camera2D" type="Camera2D" parent="."]
|
||||||
|
enabled = false
|
||||||
|
@@ -6,16 +6,18 @@ func _ready():
|
|||||||
UdpClient.player_disconnect.connect(_on_player_disconnect)
|
UdpClient.player_disconnect.connect(_on_player_disconnect)
|
||||||
|
|
||||||
func _on_player_join(player_client: Dictionary, clients: Array) -> void:
|
func _on_player_join(player_client: Dictionary, clients: Array) -> void:
|
||||||
add_player(player_client)
|
add_player(player_client, true)
|
||||||
for client in clients:
|
for client in clients:
|
||||||
add_player(client)
|
add_player(client, false)
|
||||||
|
|
||||||
|
|
||||||
func add_player(client: Dictionary):
|
func add_player(client: Dictionary, is_current_player: bool):
|
||||||
var player: Player = preload("res://scenes/player.tscn").instantiate()
|
var player: Player = preload("res://scenes/player.tscn").instantiate()
|
||||||
player.session_id = client.session_id
|
player.session_id = client.session_id
|
||||||
player.position = Vector2(client.position.x, client.position.y)
|
player.position = Vector2(client.position.x, client.position.y)
|
||||||
add_child(player)
|
add_child(player)
|
||||||
|
if is_current_player:
|
||||||
|
player.make_current()
|
||||||
|
|
||||||
func _on_button_pressed():
|
func _on_button_pressed():
|
||||||
var payload: Dictionary = {
|
var payload: Dictionary = {
|
||||||
|
Reference in New Issue
Block a user