-
Notifications
You must be signed in to change notification settings - Fork 0
/
Warrior.gd
51 lines (33 loc) · 1.14 KB
/
Warrior.gd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
extends CharacterBody2D
class_name Warrior
var speed = 150
var acceleration = 300
var noise_signal = 0
@export var animation_scene: PackedScene
@onready var player = $"."
func _physics_process(delta: float)-> void:
if is_multiplayer_authority():
var move_input_x = Input.get_axis("move_left","move_right")
var move_input_y = Input.get_axis("move_up","move_down")
velocity.x = move_toward(velocity.x, move_input_x * speed, acceleration * delta)
velocity.y = move_toward(velocity.y, move_input_y * speed, acceleration * delta)
send_data.rpc(global_position)
move_and_slide()
func _input(event: InputEvent)-> void:
if is_multiplayer_authority():
if event.is_action_pressed("action"):
var echo_visu = animation_scene.instantiate()
add_child(echo_visu)
noise.rpc()
func setup(player_data: Statics.PlayerData):
name = str(player_data.id)
set_multiplayer_authority(player_data.id)
@rpc("authority","call_local","reliable")
func noise()-> void:
noise_signal = 1
@rpc("authority","call_local","reliable")
func action():
pass
@rpc("authority", "call_local","reliable")
func send_data(pos: Vector2):
global_position = pos