UDP movement
This commit is contained in:
@ -1,8 +1,10 @@
|
||||
extends KinematicBody2D
|
||||
|
||||
const BASE_SPEED : float = 50.0
|
||||
export var user : String = ""
|
||||
var main : bool = false
|
||||
var input_locks = 0
|
||||
const SPEED_VAL = 75
|
||||
|
||||
func set_main():
|
||||
main = true
|
||||
@ -19,23 +21,31 @@ func _ready():
|
||||
func set_username(username):
|
||||
user = username
|
||||
$Label.text = user
|
||||
|
||||
func update_position(pos : Vector2):
|
||||
if not main or abs(abs(pos.x) - abs(position.x)) > SPEED_VAL or abs(abs(pos.y) - abs(position.y)) > SPEED_VAL:
|
||||
position = pos
|
||||
|
||||
var velocity : Vector2 = Vector2(0,0)
|
||||
|
||||
func _process(delta):
|
||||
if main and input_locks <= 0:
|
||||
var movePos : Vector2 = Vector2(0,0)
|
||||
var relative_movement : Vector2 = Vector2(0,0)
|
||||
|
||||
|
||||
if(Input.is_action_just_pressed("ui_up")):
|
||||
movePos.y = movePos.y - 1
|
||||
if(Input.is_action_just_pressed("ui_down")):
|
||||
movePos.y = movePos.y + 1
|
||||
if(Input.is_action_just_pressed("ui_right")):
|
||||
movePos.x = movePos.x + 1
|
||||
if(Input.is_action_just_pressed("ui_left")):
|
||||
movePos.x = movePos.x - 1
|
||||
|
||||
if movePos != Vector2.ZERO:
|
||||
$"/root/NetworkManager".move_player(movePos.x, movePos.y)
|
||||
if(Input.is_action_pressed("ui_up")):
|
||||
relative_movement.y = relative_movement.y - 1
|
||||
if(Input.is_action_pressed("ui_down")):
|
||||
relative_movement.y = relative_movement.y + 1
|
||||
if(Input.is_action_pressed("ui_right")):
|
||||
relative_movement.x = relative_movement.x + 1
|
||||
if(Input.is_action_pressed("ui_left")):
|
||||
relative_movement.x = relative_movement.x - 1
|
||||
|
||||
if relative_movement != Vector2.ZERO:
|
||||
move_and_collide(relative_movement * delta * BASE_SPEED)
|
||||
var dest = $"/root/ImportantEntities".tile_map.world_to_map(self.position)
|
||||
dest = dest + (position - (dest * 16))/16
|
||||
$"/root/NetworkManager".move_player(dest.x, dest.y)
|
||||
|
||||
func lock_input():
|
||||
input_locks = input_locks + 1
|
||||
|
Reference in New Issue
Block a user