Plumb the basics of input control and limit player movement to range
This commit is contained in:
parent
e9adc58583
commit
862fb41a32
@ -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
|
||||
|
3
UI/CardView.gd
Normal file
3
UI/CardView.gd
Normal file
@ -0,0 +1,3 @@
|
||||
extends Control
|
||||
|
||||
var selected : bool = false
|
@ -1,13 +1,15 @@
|
||||
[gd_scene load_steps=5 format=2]
|
||||
[gd_scene load_steps=6 format=2]
|
||||
|
||||
[ext_resource path="res://UI/Card.tscn" type="PackedScene" id=1]
|
||||
[ext_resource path="res://Assets/CardDB/Sprint.tres" type="Resource" id=2]
|
||||
[ext_resource path="res://Assets/CardDB/Poisonous apple.tres" type="Resource" id=3]
|
||||
[ext_resource path="res://Assets/CardDB/Broadsword.tres" type="Resource" id=4]
|
||||
[ext_resource path="res://UI/CardView.gd" type="Script" id=5]
|
||||
|
||||
[node name="CardView" type="Control"]
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
script = ExtResource( 5 )
|
||||
|
||||
[node name="Margin" type="MarginContainer" parent="."]
|
||||
anchor_right = 1.0
|
||||
|
@ -2,6 +2,8 @@ extends Control
|
||||
|
||||
const dice = preload("res://UI/Dice.tscn")
|
||||
|
||||
var selected : bool = true
|
||||
|
||||
var current_dice = []
|
||||
|
||||
func roll_dice(specific_value : int = 0):
|
||||
|
Loading…
x
Reference in New Issue
Block a user