add CardValue
This commit is contained in:
parent
a4ca3c3a34
commit
af58e4438c
9
CardValue.gd
Normal file
9
CardValue.gd
Normal file
|
@ -0,0 +1,9 @@
|
|||
class_name CardValue
|
||||
extends Node
|
||||
|
||||
var month: int
|
||||
var type: int
|
||||
|
||||
func _init(month: int, type: int):
|
||||
self.month = month
|
||||
self.type = type
|
116
Deck.gd
116
Deck.gd
|
@ -1,83 +1,74 @@
|
|||
extends Node2D
|
||||
|
||||
var HanafudaCard = preload("res://HanafudaCard.tscn")
|
||||
const CardValue = preload("res://CardValue.gd")
|
||||
|
||||
onready var cards = [
|
||||
HanafudaCard.instance().init_card(Enums.Month.JANUARY, Enums.Type.LIGHT),
|
||||
HanafudaCard.instance().init_card(Enums.Month.JANUARY, Enums.Type.RIBBON),
|
||||
HanafudaCard.instance().init_card(Enums.Month.JANUARY, Enums.Type.SCRAP_1),
|
||||
HanafudaCard.instance().init_card(Enums.Month.JANUARY, Enums.Type.SCRAP_2),
|
||||
CardValue.new(Enums.Month.JANUARY, Enums.Type.LIGHT),
|
||||
CardValue.new(Enums.Month.JANUARY, Enums.Type.RIBBON),
|
||||
CardValue.new(Enums.Month.JANUARY, Enums.Type.SCRAP_1),
|
||||
CardValue.new(Enums.Month.JANUARY, Enums.Type.SCRAP_2),
|
||||
|
||||
HanafudaCard.instance().init_card(Enums.Month.FEBRUARY, Enums.Type.ANIMAL),
|
||||
HanafudaCard.instance().init_card(Enums.Month.FEBRUARY, Enums.Type.RIBBON),
|
||||
HanafudaCard.instance().init_card(Enums.Month.FEBRUARY, Enums.Type.SCRAP_1),
|
||||
HanafudaCard.instance().init_card(Enums.Month.FEBRUARY, Enums.Type.SCRAP_2),
|
||||
CardValue.new(Enums.Month.FEBRUARY, Enums.Type.ANIMAL),
|
||||
CardValue.new(Enums.Month.FEBRUARY, Enums.Type.RIBBON),
|
||||
CardValue.new(Enums.Month.FEBRUARY, Enums.Type.SCRAP_1),
|
||||
CardValue.new(Enums.Month.FEBRUARY, Enums.Type.SCRAP_2),
|
||||
|
||||
HanafudaCard.instance().init_card(Enums.Month.MARCH, Enums.Type.LIGHT),
|
||||
HanafudaCard.instance().init_card(Enums.Month.MARCH, Enums.Type.RIBBON),
|
||||
HanafudaCard.instance().init_card(Enums.Month.MARCH, Enums.Type.SCRAP_1),
|
||||
HanafudaCard.instance().init_card(Enums.Month.MARCH, Enums.Type.SCRAP_2),
|
||||
CardValue.new(Enums.Month.MARCH, Enums.Type.LIGHT),
|
||||
CardValue.new(Enums.Month.MARCH, Enums.Type.RIBBON),
|
||||
CardValue.new(Enums.Month.MARCH, Enums.Type.SCRAP_1),
|
||||
CardValue.new(Enums.Month.MARCH, Enums.Type.SCRAP_2),
|
||||
|
||||
HanafudaCard.instance().init_card(Enums.Month.APRIL, Enums.Type.ANIMAL),
|
||||
HanafudaCard.instance().init_card(Enums.Month.APRIL, Enums.Type.RIBBON),
|
||||
HanafudaCard.instance().init_card(Enums.Month.APRIL, Enums.Type.SCRAP_1),
|
||||
HanafudaCard.instance().init_card(Enums.Month.APRIL, Enums.Type.SCRAP_2),
|
||||
CardValue.new(Enums.Month.APRIL, Enums.Type.ANIMAL),
|
||||
CardValue.new(Enums.Month.APRIL, Enums.Type.RIBBON),
|
||||
CardValue.new(Enums.Month.APRIL, Enums.Type.SCRAP_1),
|
||||
CardValue.new(Enums.Month.APRIL, Enums.Type.SCRAP_2),
|
||||
|
||||
HanafudaCard.instance().init_card(Enums.Month.MAY, Enums.Type.ANIMAL),
|
||||
HanafudaCard.instance().init_card(Enums.Month.MAY, Enums.Type.RIBBON),
|
||||
HanafudaCard.instance().init_card(Enums.Month.MAY, Enums.Type.SCRAP_1),
|
||||
HanafudaCard.instance().init_card(Enums.Month.MAY, Enums.Type.SCRAP_2),
|
||||
CardValue.new(Enums.Month.MAY, Enums.Type.ANIMAL),
|
||||
CardValue.new(Enums.Month.MAY, Enums.Type.RIBBON),
|
||||
CardValue.new(Enums.Month.MAY, Enums.Type.SCRAP_1),
|
||||
CardValue.new(Enums.Month.MAY, Enums.Type.SCRAP_2),
|
||||
|
||||
HanafudaCard.instance().init_card(Enums.Month.JUNE, Enums.Type.ANIMAL),
|
||||
HanafudaCard.instance().init_card(Enums.Month.JUNE, Enums.Type.RIBBON),
|
||||
HanafudaCard.instance().init_card(Enums.Month.JUNE, Enums.Type.SCRAP_1),
|
||||
HanafudaCard.instance().init_card(Enums.Month.JUNE, Enums.Type.SCRAP_2),
|
||||
CardValue.new(Enums.Month.JUNE, Enums.Type.ANIMAL),
|
||||
CardValue.new(Enums.Month.JUNE, Enums.Type.RIBBON),
|
||||
CardValue.new(Enums.Month.JUNE, Enums.Type.SCRAP_1),
|
||||
CardValue.new(Enums.Month.JUNE, Enums.Type.SCRAP_2),
|
||||
|
||||
HanafudaCard.instance().init_card(Enums.Month.JULY, Enums.Type.ANIMAL),
|
||||
HanafudaCard.instance().init_card(Enums.Month.JULY, Enums.Type.RIBBON),
|
||||
HanafudaCard.instance().init_card(Enums.Month.JULY, Enums.Type.SCRAP_1),
|
||||
HanafudaCard.instance().init_card(Enums.Month.JULY, Enums.Type.SCRAP_2),
|
||||
CardValue.new(Enums.Month.JULY, Enums.Type.ANIMAL),
|
||||
CardValue.new(Enums.Month.JULY, Enums.Type.RIBBON),
|
||||
CardValue.new(Enums.Month.JULY, Enums.Type.SCRAP_1),
|
||||
CardValue.new(Enums.Month.JULY, Enums.Type.SCRAP_2),
|
||||
|
||||
HanafudaCard.instance().init_card(Enums.Month.AUGUST, Enums.Type.LIGHT),
|
||||
HanafudaCard.instance().init_card(Enums.Month.AUGUST, Enums.Type.ANIMAL),
|
||||
HanafudaCard.instance().init_card(Enums.Month.AUGUST, Enums.Type.SCRAP_1),
|
||||
HanafudaCard.instance().init_card(Enums.Month.AUGUST, Enums.Type.SCRAP_2),
|
||||
CardValue.new(Enums.Month.AUGUST, Enums.Type.LIGHT),
|
||||
CardValue.new(Enums.Month.AUGUST, Enums.Type.ANIMAL),
|
||||
CardValue.new(Enums.Month.AUGUST, Enums.Type.SCRAP_1),
|
||||
CardValue.new(Enums.Month.AUGUST, Enums.Type.SCRAP_2),
|
||||
|
||||
HanafudaCard.instance().init_card(Enums.Month.SEPTEMBER, Enums.Type.ANIMAL),
|
||||
HanafudaCard.instance().init_card(Enums.Month.SEPTEMBER, Enums.Type.RIBBON),
|
||||
HanafudaCard.instance().init_card(Enums.Month.SEPTEMBER, Enums.Type.SCRAP_1),
|
||||
HanafudaCard.instance().init_card(Enums.Month.SEPTEMBER, Enums.Type.SCRAP_2),
|
||||
CardValue.new(Enums.Month.SEPTEMBER, Enums.Type.ANIMAL),
|
||||
CardValue.new(Enums.Month.SEPTEMBER, Enums.Type.RIBBON),
|
||||
CardValue.new(Enums.Month.SEPTEMBER, Enums.Type.SCRAP_1),
|
||||
CardValue.new(Enums.Month.SEPTEMBER, Enums.Type.SCRAP_2),
|
||||
|
||||
HanafudaCard.instance().init_card(Enums.Month.OCTOBER, Enums.Type.ANIMAL),
|
||||
HanafudaCard.instance().init_card(Enums.Month.OCTOBER, Enums.Type.RIBBON),
|
||||
HanafudaCard.instance().init_card(Enums.Month.OCTOBER, Enums.Type.SCRAP_1),
|
||||
HanafudaCard.instance().init_card(Enums.Month.OCTOBER, Enums.Type.SCRAP_2),
|
||||
CardValue.new(Enums.Month.OCTOBER, Enums.Type.ANIMAL),
|
||||
CardValue.new(Enums.Month.OCTOBER, Enums.Type.RIBBON),
|
||||
CardValue.new(Enums.Month.OCTOBER, Enums.Type.SCRAP_1),
|
||||
CardValue.new(Enums.Month.OCTOBER, Enums.Type.SCRAP_2),
|
||||
|
||||
HanafudaCard.instance().init_card(Enums.Month.NOVEMBER, Enums.Type.LIGHT),
|
||||
HanafudaCard.instance().init_card(Enums.Month.NOVEMBER, Enums.Type.ANIMAL),
|
||||
HanafudaCard.instance().init_card(Enums.Month.NOVEMBER, Enums.Type.RIBBON),
|
||||
HanafudaCard.instance().init_card(Enums.Month.NOVEMBER, Enums.Type.SCRAP_1),
|
||||
CardValue.new(Enums.Month.NOVEMBER, Enums.Type.LIGHT),
|
||||
CardValue.new(Enums.Month.NOVEMBER, Enums.Type.ANIMAL),
|
||||
CardValue.new(Enums.Month.NOVEMBER, Enums.Type.RIBBON),
|
||||
CardValue.new(Enums.Month.NOVEMBER, Enums.Type.SCRAP_1),
|
||||
|
||||
HanafudaCard.instance().init_card(Enums.Month.DECEMBER, Enums.Type.LIGHT),
|
||||
HanafudaCard.instance().init_card(Enums.Month.DECEMBER, Enums.Type.SCRAP_1),
|
||||
HanafudaCard.instance().init_card(Enums.Month.DECEMBER, Enums.Type.SCRAP_2),
|
||||
HanafudaCard.instance().init_card(Enums.Month.DECEMBER, Enums.Type.SCRAP_3),
|
||||
CardValue.new(Enums.Month.DECEMBER, Enums.Type.LIGHT),
|
||||
CardValue.new(Enums.Month.DECEMBER, Enums.Type.SCRAP_1),
|
||||
CardValue.new(Enums.Month.DECEMBER, Enums.Type.SCRAP_2),
|
||||
CardValue.new(Enums.Month.DECEMBER, Enums.Type.SCRAP_3),
|
||||
]
|
||||
|
||||
var card_order = []
|
||||
var next_to_draw = 0
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
init_card_order()
|
||||
for c in cards:
|
||||
add_child(c)
|
||||
c.hide()
|
||||
|
||||
|
||||
var card: HanafudaCard = cards[0]
|
||||
card.show()
|
||||
card.reveal(false)
|
||||
|
||||
func init_card_order() -> void:
|
||||
card_order.resize(cards.size())
|
||||
|
@ -86,14 +77,9 @@ func init_card_order() -> void:
|
|||
card_order.shuffle()
|
||||
next_to_draw = 0
|
||||
|
||||
func draw_card() -> int:
|
||||
func draw_card() -> CardValue:
|
||||
if next_to_draw >= card_order.size():
|
||||
return -1
|
||||
return null
|
||||
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]
|
||||
|
|
|
@ -1,27 +1,30 @@
|
|||
tool
|
||||
extends Node2D
|
||||
class_name HanafudaCard
|
||||
extends Node2D
|
||||
|
||||
const CardValue = preload("res://CardValue.gd")
|
||||
|
||||
export var revealed: bool = true setget reveal
|
||||
export(Enums.Month) var month: int
|
||||
export(Enums.Type) var type: int
|
||||
export(Enums.Month) var month: int setget _set_card_month
|
||||
export(Enums.Type) var type: int setget _set_card_type
|
||||
|
||||
onready var value = CardValue.new(Enums.Month.JANUARY, Enums.Type.LIGHT)
|
||||
onready var _is_ready := true
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
|
||||
var texture_path := card_texture()
|
||||
$Frontside.texture = load(texture_path)
|
||||
reveal(revealed)
|
||||
|
||||
func init_card(month_: int, type_: int) -> HanafudaCard:
|
||||
month = month_
|
||||
type = type_
|
||||
func init_card(value_: CardValue) -> HanafudaCard:
|
||||
value = value_
|
||||
return self
|
||||
|
||||
func card_texture() -> String:
|
||||
var m := ""
|
||||
match month:
|
||||
match value.month:
|
||||
Enums.Month.JANUARY: m = "January"
|
||||
Enums.Month.FEBRUARY: m = "February"
|
||||
Enums.Month.MARCH: m = "March"
|
||||
|
@ -36,7 +39,7 @@ func card_texture() -> String:
|
|||
Enums.Month.DECEMBER: m = "December"
|
||||
|
||||
var t := ""
|
||||
match type:
|
||||
match value.type:
|
||||
Enums.Type.LIGHT: t = "Hikari"
|
||||
Enums.Type.ANIMAL: t = "Tane"
|
||||
Enums.Type.RIBBON: t = "Tanzaku"
|
||||
|
@ -59,3 +62,9 @@ func reveal(new_reveal: bool) -> void:
|
|||
else:
|
||||
$Frontside.hide()
|
||||
$Backside.show()
|
||||
|
||||
func _set_card_month(new_month: int) -> void:
|
||||
value.month = new_month
|
||||
|
||||
func _set_card_type(new_type: int) -> void:
|
||||
value.type = new_type
|
||||
|
|
17
Main.gd
17
Main.gd
|
@ -1,5 +1,7 @@
|
|||
extends Node
|
||||
|
||||
onready var HanafudaCard = preload("res://HanafudaCard.tscn")
|
||||
|
||||
onready var deck = $Deck
|
||||
onready var tween = $Tween
|
||||
|
||||
|
@ -8,18 +10,19 @@ func _ready():
|
|||
|
||||
func oya():
|
||||
tween.start()
|
||||
var card_1 = $Deck.card($Deck.draw_card())
|
||||
card_1.show()
|
||||
var card_1 = HanafudaCard.instance().init_card($Deck.draw_card())
|
||||
add_child(card_1)
|
||||
# card_1.show()
|
||||
|
||||
tween.interpolate_property(card_1, "position",
|
||||
Vector2(0, 0), Vector2(100, 100), 3,
|
||||
Tween.TRANS_LINEAR, Tween.EASE_IN_OUT)
|
||||
|
||||
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)
|
||||
# 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")
|
||||
|
||||
|
|
|
@ -18,7 +18,6 @@ __meta__ = {
|
|||
[node name="HanafudaCard" parent="." instance=ExtResource( 1 )]
|
||||
visible = false
|
||||
position = Vector2( 205, 447 )
|
||||
month = 2
|
||||
|
||||
[node name="Deck" type="Node2D" parent="."]
|
||||
position = Vector2( 293, 412 )
|
||||
|
|
|
@ -9,12 +9,18 @@
|
|||
config_version=4
|
||||
|
||||
_global_script_classes=[ {
|
||||
"base": "Node",
|
||||
"class": "CardValue",
|
||||
"language": "GDScript",
|
||||
"path": "res://CardValue.gd"
|
||||
}, {
|
||||
"base": "Node2D",
|
||||
"class": "HanafudaCard",
|
||||
"language": "GDScript",
|
||||
"path": "res://HanafudaCard.gd"
|
||||
} ]
|
||||
_global_script_class_icons={
|
||||
"CardValue": "",
|
||||
"HanafudaCard": ""
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue