Compare commits

..

5 Commits

Author SHA1 Message Date
CactiChameleon9
862fb41a32 Plumb the basics of input control and limit player movement to range 2022-07-16 23:56:52 +01:00
CactiChameleon9
e9adc58583 Fix a lost precision warning 2022-07-16 22:58:24 +01:00
CactiChameleon9
219921d51b Fix returning dice1 twice 2022-07-16 22:57:52 +01:00
CactiChameleon9
5d638e3f5b Keep aspect ratio on UI so horizontal stretching looks fine 2022-07-16 22:55:03 +01:00
CactiChameleon9
2dc7dfc3f6 Fix running on raspi 2022-07-16 22:54:09 +01:00
8 changed files with 59 additions and 11 deletions

View File

@ -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

View File

@ -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,13 +47,17 @@ 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 )]
margin_top = 367.0
margin_right = -314.0
[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 )]
margin_left = 966.0
margin_top = 367.0
[node name="DiceView" parent="UI" instance=ExtResource( 5 )]
anchor_left = 0.754687
anchor_top = 0.509722
margin_left = 1.52588e-05
margin_top = -7.62939e-06
grow_horizontal = 0

View File

@ -112,7 +112,7 @@ func run_card():
new_dice2 += 0.5
emit_signal("return_dice", new_dice1)
emit_signal("return_dice", new_dice1)
emit_signal("return_dice", new_dice2)
if card_info.EFFECT.DOUBLE in card_info.effects:
var new_dice1 = dice_number * 2

3
UI/CardView.gd Normal file
View File

@ -0,0 +1,3 @@
extends Control
var selected : bool = false

View File

@ -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

View File

@ -13,4 +13,4 @@ func _set_dice_value(new_value):
func _ready():
randomize()
self.dice_value = round(rand_range(0.5, 6.49999999))
self.dice_value = int(round(rand_range(0.5, 6.49999999)))

View File

@ -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):

View File

@ -36,4 +36,5 @@ common/enable_pause_aware_picking=true
[rendering]
quality/driver/fallback_to_gles2=true
environment/default_environment="res://default_env.tres"