-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
927d48d
commit 17a4302
Showing
6 changed files
with
155 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[gd_scene load_steps=3 format=3 uid="uid://dbodpfxyefg37"] | ||
|
||
[ext_resource type="Script" path="res://player.gd" id="1_jtuqy"] | ||
[ext_resource type="Texture2D" uid="uid://crb5lx2kqp0xl" path="res://icon.svg" id="1_t3xwi"] | ||
|
||
[node name="Player" type="CharacterBody2D"] | ||
motion_mode = 1 | ||
script = ExtResource("1_jtuqy") | ||
|
||
[node name="Sprite2D" type="Sprite2D" parent="."] | ||
position = Vector2(550, 334) | ||
scale = Vector2(0.671875, 0.65625) | ||
texture = ExtResource("1_t3xwi") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
extends CharacterBody2D | ||
class_name Player | ||
var this_players_peer_id: int | ||
var multiplayer_peer: ENetMultiplayerPeer | ||
var networking_client: NetworkingClient | ||
|
||
func _ready() -> void: | ||
networking_client = get_tree().root.get_node('Networking') | ||
multiplayer_peer = networking_client.multiplayer_peer | ||
|
||
func get_input(): | ||
var input_direction = Input.get_vector("left", "right", "up", "down") | ||
networking_client.move_player(this_players_peer_id, input_direction) | ||
|
||
func set_peer_id(peer_id: int): | ||
this_players_peer_id = peer_id | ||
|
||
func sync_current_position(): | ||
networking_client.set_position(this_players_peer_id, position) | ||
|
||
func _physics_process(delta): | ||
var my_peer_id = multiplayer_peer.get_unique_id() | ||
if this_players_peer_id == my_peer_id: | ||
sync_current_position() | ||
get_input() | ||
move_and_slide() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters