Plumb the basics of input control and limit player movement to range
This commit is contained in:
@ -2,8 +2,32 @@ extends Node2D
|
||||
|
||||
var movement_queue = []
|
||||
|
||||
var player_to_move : bool = false
|
||||
var player_original_position : Vector2 = Vector2.ZERO
|
||||
var player_movement_range = 5
|
||||
|
||||
func _physics_process(delta):
|
||||
|
||||
# player should carry on queued movements no matter what
|
||||
player_movement()
|
||||
|
||||
# note down the player position before moving
|
||||
if not player_to_move:
|
||||
player_original_position = $Player.map_position
|
||||
|
||||
# if the player needs to move, allow the input to be for the player
|
||||
if player_to_move:
|
||||
player_movement_input()
|
||||
return
|
||||
|
||||
# select the card chooser if dice is selected
|
||||
if (Input.is_action_just_pressed("ui_accept")
|
||||
and $UI/DiceView.selected == true):
|
||||
$UI/DiceView.selected = false
|
||||
$UI/CardView.selected = true
|
||||
|
||||
|
||||
func player_movement_input():
|
||||
if Input.is_action_just_pressed("ui_up"):
|
||||
movement_queue.append(Vector2.UP)
|
||||
if Input.is_action_just_pressed("ui_down"):
|
||||
@ -13,6 +37,11 @@ func _physics_process(delta):
|
||||
if Input.is_action_just_pressed("ui_right"):
|
||||
movement_queue.append(Vector2.RIGHT)
|
||||
|
||||
if Input.is_action_just_pressed("ui_accept"):
|
||||
player_to_move = false
|
||||
|
||||
|
||||
func player_movement():
|
||||
#remove uneeded inputs from the queue
|
||||
for i in len(movement_queue) - 1:
|
||||
#remove if adjacent values are opposites
|
||||
@ -28,8 +57,14 @@ func _physics_process(delta):
|
||||
if len(movement_queue) == 0:
|
||||
return
|
||||
|
||||
#move the character once space in the queue if not moving
|
||||
if not $Player.moving:
|
||||
#if the player is moving too far, cancel movement and empty queue
|
||||
if (($Player.map_position + movement_queue[0]
|
||||
- player_original_position).length() > player_movement_range):
|
||||
movement_queue = []
|
||||
return
|
||||
|
||||
#move the character once space in the queue if not moving
|
||||
$Player.map_position += movement_queue.pop_front()
|
||||
$Player.target_position = $TileMap.map_to_world($Player.map_position)
|
||||
$Player.target_position += $TileMap.cell_size/2
|
||||
|
@ -37,6 +37,7 @@ tile_data = PoolIntArray( 65540, 0, 0, 131074, 0, 0, 131075, 0, 0, 131076, 0, 0,
|
||||
[node name="Player" parent="." instance=ExtResource( 2 )]
|
||||
|
||||
[node name="Camera2D" type="Camera2D" parent="Player"]
|
||||
visible = false
|
||||
offset = Vector2( 0, 200 )
|
||||
current = true
|
||||
drag_margin_h_enabled = true
|
||||
@ -46,15 +47,15 @@ drag_margin_top = 0.05
|
||||
drag_margin_right = 0.3
|
||||
editor_draw_drag_margin = true
|
||||
|
||||
[node name="CanvasLayer" type="CanvasLayer" parent="."]
|
||||
[node name="UI" type="CanvasLayer" parent="."]
|
||||
|
||||
[node name="CardView" parent="CanvasLayer" instance=ExtResource( 4 )]
|
||||
[node name="CardView" parent="UI" instance=ExtResource( 4 )]
|
||||
anchor_top = 0.509722
|
||||
anchor_right = 0.754687
|
||||
margin_top = -7.62939e-06
|
||||
margin_right = 1.52588e-05
|
||||
|
||||
[node name="DiceView" parent="CanvasLayer" instance=ExtResource( 5 )]
|
||||
[node name="DiceView" parent="UI" instance=ExtResource( 5 )]
|
||||
anchor_left = 0.754687
|
||||
anchor_top = 0.509722
|
||||
margin_left = 1.52588e-05
|
||||
|
Reference in New Issue
Block a user