fixed movements
This commit is contained in:
parent
77a13eb2c8
commit
84fd007069
|
@ -17,6 +17,7 @@ __meta__ = {
|
||||||
[node name="Player" parent="." instance=ExtResource( 2 )]
|
[node name="Player" parent="." instance=ExtResource( 2 )]
|
||||||
position = Vector2( 445, 205 )
|
position = Vector2( 445, 205 )
|
||||||
z_index = 1
|
z_index = 1
|
||||||
speed = 20
|
speed = 20.0
|
||||||
|
rest = 0.2
|
||||||
tile_position = Vector2( 4, 2 )
|
tile_position = Vector2( 4, 2 )
|
||||||
grid_path = NodePath("..")
|
grid_path = NodePath("..")
|
||||||
|
|
15
Player.gd
15
Player.gd
|
@ -2,13 +2,16 @@ tool
|
||||||
extends Area2D
|
extends Area2D
|
||||||
|
|
||||||
|
|
||||||
export var speed = 1
|
export var speed : float = 1
|
||||||
|
export var rest : float = 1
|
||||||
|
|
||||||
export var tile_position := Vector2(0,0)
|
export var tile_position := Vector2(0,0)
|
||||||
export(NodePath) var grid_path
|
export(NodePath) var grid_path
|
||||||
|
|
||||||
onready var grid = get_node(grid_path) as TileMap
|
onready var grid = get_node(grid_path) as TileMap
|
||||||
|
|
||||||
|
var last_move_time := 0.0
|
||||||
|
|
||||||
class Movement:
|
class Movement:
|
||||||
var action: String
|
var action: String
|
||||||
var direction: Vector2
|
var direction: Vector2
|
||||||
|
@ -49,10 +52,11 @@ func _process(delta):
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
|
||||||
for movement in movements:
|
if (last_move_time + rest) * 1000 < OS.get_ticks_msec():
|
||||||
if Input.is_action_just_pressed(movement.action):
|
for movement in movements:
|
||||||
movement_queue.push_back(movement)
|
if Input.is_action_pressed(movement.action):
|
||||||
|
movement_queue.push_back(movement)
|
||||||
|
|
||||||
update_animation()
|
update_animation()
|
||||||
|
|
||||||
if not movement_queue.empty():
|
if not movement_queue.empty():
|
||||||
|
@ -72,6 +76,7 @@ func _process(delta):
|
||||||
movement_queue.pop_front()
|
movement_queue.pop_front()
|
||||||
|
|
||||||
update_position()
|
update_position()
|
||||||
|
last_move_time = OS.get_ticks_msec() / 1000.0
|
||||||
|
|
||||||
|
|
||||||
func update_position():
|
func update_position():
|
||||||
|
|
Loading…
Reference in a new issue