This repository has been archived on 2023-04-11. You can view files and clone it, but cannot push or open issues or pull requests.
defend-together/client/scripts/entities/Player.gd

44 lines
949 B
GDScript3
Raw Normal View History

2020-05-01 01:16:46 +02:00
extends KinematicBody2D
export var user : String = ""
2020-05-04 08:45:04 +02:00
var main : bool = false
var input_locks = 0
func set_main():
main = true
$Label.hide()
$Camera.show()
$Camera.current = true
$"/root/ImportantEntities".main_player = self
2020-05-01 01:16:46 +02:00
func _ready():
2020-05-04 08:45:04 +02:00
$Camera.hide()
2020-05-02 22:36:51 +02:00
set_username("")
func set_username(username):
user = username
2020-05-01 01:16:46 +02:00
$Label.text = user
func _process(delta):
2020-05-04 08:45:04 +02:00
if main and input_locks <= 0:
var movePos : 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
2020-05-01 01:16:46 +02:00
2020-05-04 08:45:04 +02:00
if movePos != Vector2.ZERO:
$"/root/NetworkManager".move_player(movePos.x, movePos.y)
2020-05-01 01:16:46 +02:00
2020-05-04 08:45:04 +02:00
func lock_input():
input_locks = input_locks + 1
func unlock_input():
input_locks = input_locks - 1