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 card_order = []
|
||||||
|
var next_to_draw = 0
|
||||||
|
|
||||||
# Called when the node enters the scene tree for the first time.
|
# Called when the node enters the scene tree for the first time.
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
|
@ -83,3 +84,16 @@ func init_card_order() -> void:
|
||||||
for i in range(cards.size()):
|
for i in range(cards.size()):
|
||||||
card_order[i] = i
|
card_order[i] = i
|
||||||
card_order.shuffle()
|
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")
|
yield(self, "ready")
|
||||||
|
|
||||||
if revealed:
|
if revealed:
|
||||||
print("Reveal card")
|
|
||||||
$Frontside.show()
|
$Frontside.show()
|
||||||
$Backside.hide()
|
$Backside.hide()
|
||||||
else:
|
else:
|
||||||
print("Conceal card")
|
|
||||||
$Frontside.hide()
|
$Frontside.hide()
|
||||||
$Backside.show()
|
$Backside.show()
|
||||||
|
|
42
Main.gd
42
Main.gd
|
@ -1,34 +1,54 @@
|
||||||
extends Node
|
extends Node
|
||||||
|
|
||||||
|
signal state_completed
|
||||||
|
|
||||||
var state_stack = []
|
var state_stack = []
|
||||||
|
|
||||||
|
onready var deck = $Deck
|
||||||
|
onready var tween = $Tween
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
state_stack.push_back(funcref(self, "update_game"))
|
state_stack.push_back(funcref(self, "update_game"))
|
||||||
state_stack.push_back(funcref(self, "update_oya"))
|
state_stack.push_back(funcref(self, "update_oya"))
|
||||||
|
|
||||||
func _process(delta):
|
func _process(delta):
|
||||||
|
# print("Main::_process()")
|
||||||
if state_stack.empty():
|
if state_stack.empty():
|
||||||
return
|
return
|
||||||
|
|
||||||
var state = state_stack.pop_back()
|
var state = state_stack.pop_back()
|
||||||
|
# print(state)
|
||||||
if state == null:
|
if state == null:
|
||||||
return
|
return
|
||||||
|
|
||||||
if state is FuncRef:
|
state.call_func()
|
||||||
state_stack.push_back(state.call_func())
|
yield(self, "state_completed")
|
||||||
return
|
# state_stack.pop_back()
|
||||||
|
|
||||||
if not (state is GDScriptFunctionState and state.is_valid()):
|
|
||||||
printerr("Invalid state")
|
|
||||||
return
|
|
||||||
|
|
||||||
state_stack.push_back(state.resume())
|
|
||||||
|
|
||||||
func update_oya():
|
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")
|
print("update oya")
|
||||||
yield()
|
emit_signal("state_completed")
|
||||||
|
|
||||||
func update_game():
|
func update_game():
|
||||||
print("update game")
|
print("update game")
|
||||||
|
emit_signal("state_completed")
|
||||||
|
|
Loading…
Reference in a new issue