diff --git a/Deck.gd b/Deck.gd index be124e2..e41bd55 100644 --- a/Deck.gd +++ b/Deck.gd @@ -65,6 +65,7 @@ onready var cards = [ ] var card_order = [] +var next_to_draw = 0 # Called when the node enters the scene tree for the first time. func _ready() -> void: @@ -83,3 +84,16 @@ func init_card_order() -> void: for i in range(cards.size()): card_order[i] = i card_order.shuffle() + next_to_draw = 0 + +func draw_card() -> int: + if next_to_draw >= card_order.size(): + return -1 + var card_id = card_order[next_to_draw] + next_to_draw += 1 + return card_id + +func card(index: int) -> HanafudaCard: + if index == -1: + printerr("Invalid card index") + return cards[index] diff --git a/HanafudaCard.gd b/HanafudaCard.gd index c58893b..aab743a 100644 --- a/HanafudaCard.gd +++ b/HanafudaCard.gd @@ -54,10 +54,8 @@ func reveal(new_reveal: bool) -> void: yield(self, "ready") if revealed: - print("Reveal card") $Frontside.show() $Backside.hide() else: - print("Conceal card") $Frontside.hide() $Backside.show() diff --git a/Main.gd b/Main.gd index fae3ad7..0a2154e 100644 --- a/Main.gd +++ b/Main.gd @@ -1,34 +1,54 @@ extends Node +signal state_completed var state_stack = [] +onready var deck = $Deck +onready var tween = $Tween + func _ready(): state_stack.push_back(funcref(self, "update_game")) state_stack.push_back(funcref(self, "update_oya")) func _process(delta): +# print("Main::_process()") if state_stack.empty(): return var state = state_stack.pop_back() +# print(state) if state == null: return - - if state is FuncRef: - state_stack.push_back(state.call_func()) - return - - if not (state is GDScriptFunctionState and state.is_valid()): - printerr("Invalid state") - return - - state_stack.push_back(state.resume()) + + state.call_func() + yield(self, "state_completed") +# state_stack.pop_back() func update_oya(): - yield() + var card_1 = $Deck.card($Deck.draw_card()) + card_1.show() + + tween.start() + + tween.interpolate_property(card_1, "position", + Vector2(0, 0), Vector2(100, 100), 3, + Tween.TRANS_LINEAR, Tween.EASE_IN_OUT) + + yield(tween, "tween_all_completed") + yield(tween, "tween_completed") + +# var card_2 = $Deck.card($Deck.draw_card()) +# card_2.show() +# tween.interpolate_property(card_2, "position", +# Vector2(0, 0), Vector2(-100, 100), 0.4, +# Tween.TRANS_LINEAR, Tween.EASE_IN_OUT) +# +# yield(tween, "tween_all_completed") + print("update oya") - yield() + emit_signal("state_completed") func update_game(): print("update game") + emit_signal("state_completed") diff --git a/Main.tscn b/Main.tscn index 9687049..10393bf 100644 --- a/Main.tscn +++ b/Main.tscn @@ -23,3 +23,5 @@ month = 2 [node name="Deck" type="Node2D" parent="."] position = Vector2( 293, 412 ) script = ExtResource( 3 ) + +[node name="Tween" type="Tween" parent="."]