add draft for drawing card
This commit is contained in:
parent
916ea0fc49
commit
c1d63c214a
14
Deck.gd
14
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]
|
||||
|
|
|
@ -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()
|
||||
|
|
44
Main.gd
44
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")
|
||||
|
|
Loading…
Reference in a new issue