1
0
Fork 0

Added turn indicator animation

This commit is contained in:
Michaël Lemaire 2020-02-23 23:59:01 +01:00
parent 2860e9181c
commit 65f0aa6dbf
4 changed files with 84 additions and 3 deletions

View File

@ -92,4 +92,6 @@ func on_dragged(active, relative, absolute):
if relative:
set_position(position + relative)
z_index = 31 if active else 30
update_anchors()

View File

@ -7,6 +7,7 @@ export(PackedScene) var deck_defend
export(PackedScene) var hero_unit_attack
export(PackedScene) var hero_unit_defend
export(Script) var defend_ai
export var interactive = false setget set_interactive
onready var deck_attack_cards = deck_attack.instance()
onready var deck_defend_cards = deck_defend.instance()
@ -25,9 +26,18 @@ func _ready():
fill_hands()
adjust_playable()
set_interactive(false)
#print(BattleHelper.get_state(get_tree()))
show_turn_indicator()
func set_interactive(val: bool):
interactive = val
func show_turn_indicator():
$turn_indicator.start("Player Turn" if turn_attack else "AI Turn")
func find_free_anchor(anchor_type: String):
for anchor in get_tree().get_nodes_in_group("anchors"):
if anchor.anchor_type == anchor_type and anchor.is_empty():
@ -54,18 +64,23 @@ func fill_hand(hand: Node, deck: Node, hero: Node, limit=4):
hand.rearrange()
func fill_hands():
randomize()
fill_hand($hand_attack, deck_attack_cards, hero_attack)
fill_hand($hand_defend, deck_defend_cards, hero_defend)
func end_turn():
set_interactive(false)
turn_attack = not turn_attack
fill_hands()
adjust_playable()
for unit in BattleHelper.list_units(get_tree()):
unit.turn_ended()
show_turn_indicator()
func _process(delta):
if not turn_attack and defend_ai:
if not turn_attack and defend_ai and interactive:
defend_ai.play($arena, hero_defend, $hand_defend)
func adjust_playable():

View File

@ -1,4 +1,4 @@
[gd_scene load_steps=12 format=2]
[gd_scene load_steps=14 format=2]
[ext_resource path="res://screens/battle/mechanolith.ogg" type="AudioStream" id=1]
[ext_resource path="res://theme/ui.tres" type="Theme" id=2]
@ -12,6 +12,42 @@
[ext_resource path="res://units/heroes/tomahawk.tscn" type="PackedScene" id=10]
[ext_resource path="res://units/heroes/rhino.tscn" type="PackedScene" id=11]
[sub_resource type="GDScript" id=2]
script/source = "extends Polygon2D
func start(text):
$label.text = text
$anim.play(\"show\")
"
[sub_resource type="Animation" id=1]
resource_name = "show"
length = 1.5
tracks/0/type = "value"
tracks/0/path = NodePath(".:position")
tracks/0/interp = 2
tracks/0/loop_wrap = true
tracks/0/imported = false
tracks/0/enabled = true
tracks/0/keys = {
"times": PoolRealArray( 0, 0.4, 1.1, 1.5 ),
"transitions": PoolRealArray( 1, 1, 1, 1 ),
"update": 0,
"values": [ Vector2( -1430, 80 ), Vector2( 170, 80 ), Vector2( 170, 80 ), Vector2( 1660, 80 ) ]
}
tracks/1/type = "value"
tracks/1/path = NodePath("..:interactive")
tracks/1/interp = 1
tracks/1/loop_wrap = true
tracks/1/imported = false
tracks/1/enabled = true
tracks/1/keys = {
"times": PoolRealArray( 0, 1.5 ),
"transitions": PoolRealArray( 1, 1 ),
"update": 1,
"values": [ false, true ]
}
[node name="view" type="Panel"]
anchor_right = 1.0
anchor_bottom = 1.0
@ -91,6 +127,35 @@ position = Vector2( 260, -167.5 )
[node name="defender_points" parent="combat_info" instance=ExtResource( 7 )]
position = Vector2( 840, -167.5 )
[node name="turn_indicator" type="Polygon2D" parent="."]
position = Vector2( 170, 80 )
z_index = 50
color = Color( 0.227451, 0.392157, 0.47451, 1 )
polygon = PoolVector2Array( -570, 980, -470, 780, 1420, 780, 1320, 980 )
script = SubResource( 2 )
__meta__ = {
"_edit_group_": true
}
[node name="label" type="Label" parent="turn_indicator"]
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
margin_left = -570.0
margin_top = 780.0
margin_right = 1420.0
margin_bottom = 980.0
text = "Whose turn?"
align = 1
valign = 1
__meta__ = {
"_edit_use_anchors_": false
}
[node name="anim" type="AnimationPlayer" parent="turn_indicator"]
anims/show = SubResource( 1 )
[connection signal="unit_created" from="hand_attack" to="." method="_on_unit_created"]
[connection signal="pressed" from="hand_attack/skip" to="hand_attack" method="emit_turn_end"]
[connection signal="unit_created" from="hand_defend" to="." method="_on_unit_created"]

View File

@ -5,7 +5,6 @@
[ext_resource path="res://cards/spawns/spawn_breeze.tscn" type="PackedScene" id=3]
[ext_resource path="res://theme/ui.tres" type="Theme" id=4]
[sub_resource type="GDScript" id=1]
script/source = "extends Node2D