Godot Version
Question
Hi there. Thank you for reading my post. =)
I’m trying to make a match card game (match 2 or match 3) and I got stuck in middle.
This is what I did in project:
- Open 2D Scene, rename root “game”
- Add child Node2D “Card”, then add a Sprite2D image name “777” (size 150x200), save as scene “card”
- And I add cards to deck by this way:
(by the way, I used 3 cards + 6 copies = 9 total)
var cardTexture = [
preload("res://card/A.png"),
preload("res://card/B.png"),
preload("res://card/C.png"),
]
var Card = preload("res://card.tscn")
var deck = []
func make_card():
var a1 = Card.instantiate()
a.get_node("777").texture = preload("res://card/A.png")
var a2 = Card.instantiate()
a.get_node("777").texture = preload("res://card/A.png")
var a3 = Card.instantiate()
a.get_node("777").texture = preload("res://card/A.png")
var b1 = Card.instantiate()
a.get_node("777").texture = preload("res://card/B.png")
var b2 = Card.instantiate()
a.get_node("777").texture = preload("res://card/B.png")
var b3 = Card.instantiate()
a.get_node("777").texture = preload("res://card/B.png")
var c1 = Card.instantiate()
a.get_node("777").texture = preload("res://card/C.png")
var c2 = Card.instantiate()
a.get_node("777").texture = preload("res://card/C.png")
var c3 = Card.instantiate()
a.get_node("777").texture = preload("res://card/C.png")
deck.append(a1)
deck.append(a2)
deck.append(a3)
deck.append(b1)
deck.append(b2)
deck.append(b3)
deck.append(c1)
deck.append(c2)
deck.append(c3)
deck.shuffle()
- Then I place cards from deck like this: # (3x3) square
func _ready():
for i in 3:
for j in 3:
var a = deck[randi() % deck.size()]
a.position = Vector2(80,110) + Vector2(150 * i, 200 * j)
add_child(a)
- And then… I stuck
So, here are my questions:
- How can I tell GODOT that I clicked 2 cards and want to compare them?
(I don’t know how to count clicked card in the first place) - What (and how) to compare? Like: texture = texture (?), or var a1 = var a2 (???)
- Anything else that make the game better would be nice. (like, 2 matched cards removed, etc…)
- I know my script is clumsy and awkward.
So if there is a way to improve it, I would love to listen and learn from you.
Thank you again =)
And thanks GODOT’s community.