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.

54 lines
1.4 KiB
GDScript3
Raw Permalink Normal View History

2020-04-30 19:16:46 -04:00
extends KinematicBody2D
2020-05-04 06:42:47 -04:00
const BASE_SPEED : float = 50.0
2020-04-30 19:16:46 -04:00
export var user : String = ""
2020-05-04 02:45:04 -04:00
var main : bool = false
var input_locks = 0
2020-05-04 06:42:47 -04:00
const SPEED_VAL = 75
2020-05-04 02:45:04 -04:00
func set_main():
main = true
$Label.hide()
$Camera.show()
$Camera.current = true
$"/root/ImportantEntities".main_player = self
2020-04-30 19:16:46 -04:00
func _ready():
2020-05-04 02:45:04 -04:00
$Camera.hide()
2020-05-02 16:36:51 -04:00
set_username("")
func set_username(username):
user = username
2020-04-30 19:16:46 -04:00
$Label.text = user
2020-05-04 06:42:47 -04:00
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)
2020-04-30 19:16:46 -04:00
func _process(delta):
2020-05-04 02:45:04 -04:00
if main and input_locks <= 0:
2020-05-04 06:42:47 -04:00
var relative_movement : Vector2 = Vector2(0,0)
2020-05-04 02:45:04 -04:00
2020-05-04 06:42:47 -04:00
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)
2020-04-30 19:16:46 -04:00
2020-05-04 02:45:04 -04:00
func lock_input():
input_locks = input_locks + 1
func unlock_input():
input_locks = input_locks - 1