Face Values for Cards?

Get help using Construct 2

Post » Wed May 23, 2012 7:44 am

http://timbanon.com/games/Dreamers.capx

How do I assign values to objects created?

There are three different sprites for cards. HandCard, FieldCard, and CardBack. I'm thinking maybe I should just make a sprite for all FieldCards only hold a variable for each instance. A deck of 54 cards would be 54 instance variables on 54 different FieldCard objects holding 1 valute out out of 54 (0-based) numbers. When HandCards are played, a globalvar would change to the HandCard's variable. The variable would be the frame of the HandCard sprite. So they can be compared with the you can set position to the FieldCard with this same variable as the HandCard played. Each HandCard would have their own instance variable.

The key is to summon FieldCards from the respective HandCards. Like YGO, so each FieldCard object is linked to a HandCard created from the Array.
Would that be a global variable that holds the destroyed HandCard Sprite's frame number which is used to draw when facedown or faceup?


On left button clicked 'Play Face-Up' -> Create object at C1. Set animation frame to C1
On left button clicked 'Play Face-Up' -> Create object at C2. Set animation frame to C2
On left button clicked 'Play Face-Up' -> Create object at C3. Set animation frame to C3
On left button clicked 'Play Face-Down' -> Create object at C1. Set animation frame to C1.
On left button clicked 'Play Face-Down' -> Create object at C2. Set animation frame to C2
On left button clicked 'Play Face-Down' -> Create object at C3. Set animation frame to C3
B
5
Posts: 38
Reputation: 501

Post » Wed May 23, 2012 3:41 pm

Since I never played Yu-Gi-Oh, I'm not 100% sure what you want. But here is a shot at it. I'll talk about the cards as if they are a standard 52 card deck with 2 jokers for 54 cards total. You can adapt to your own deck.

I'll also be referring to my Memory match tutorial, which shows how to make the Memory Match card game in the Arcade.)

I would create one sprite with two animations: Card face and Card back (like in the Memory Match example.) The Card face animation would have one frame for every different card in the deck (54 frames.)

When the card is turned face down you play the Card Back animation. When it is turned face up you play the Card Face animation and set the frame to the frame assigned to that card.

-----------------------------------------------------------------
EDIT: Changed next few paragraphs to show 2 options for organizing and use division and modulus operators to determine the card suit and number.

Create two instance variables on the card object: Suit and Number.

When you create the frames, you might want to organize the frames of cards so that all of the cards of a suit are together in order, or so that all of the card numbers are together. In either case, put the jokers at the end.

If want to organize by suit (Ace Spades, 2 Spades, 3 Spades, ...Ace Hearts, 2 Hearts, 3 Hearts...Ace Diamonds, 2 Diamonds, 3 Diamonds...Ace of Clubs, 2 Clubs, 3 Clubs...Joker, Joker.)

To find the suit of the card:

if Card.animationFrame <52
   Card.Suit=floor(card.AnimationFrame/13)

This gives 0 for spades, 1 for hearts, 2 for diamonds and 3 for clubs.

To find the card number:

if Card.animationFrame <52
Card.Suit = Card.AnimationFrame%13

This gives 0 for Ace, 1 for 2, ...10 for Jack, 11 for Queen and 12 for King.

If you organize the cards A Spades, A Hearts, A Diamonds, A Clubs, 2 Spades, 2 Hearts...

To find the suit of the card:

if Card.animationFrame <52
   Card.Suit=card.AnimationFrame%4

This gives 0 for spades, 1 for hearts, 2 for diamonds and 3 for clubs.

To find the card number:

if Card.animationFrame <52
Card.Suit = Floor(Card.AnimationFrame/4)

This gives 0 for Ace, 1 for 2, ...10 for Jack, 11 for Queen and 12 for King.


End EDIT
--------------------------------------------------------------------

Now you need to create an array containing one value for each frame in your card face animation, and insert the numbers from 0 to 54 in the array and shuffle the deck (as shown in the memory match tutorial.)

Now create the card instances and assign a card frame to each, storing it in an instance variable. EDIT: In addition, use one of the approaches above, depending on how you sorted your card frames in the card face animation, to assign the value of Card.Suit and Card.Number.

From this point on your card objects can be treated just like regular real world cards. You can move them to different locations -- the hand, the deck, the extra deck, etc.

Hope that helps.kittiewan2012-05-23 16:18:29
B
29
S
11
G
12
Posts: 281
Reputation: 11,878

Post » Wed Jun 06, 2012 3:20 am

There are HandCards and FieldCards. FieldCards have values on em according to the card, color and power (like suit and number). ThI have 54 cards each with their own frame in the object FieldCards. How can I assign a color and number to each frame? Should I organize the Frames in a certain w
ay?

The pseudo-code should read:

If CardA.Color=Blue & CardB.Color=Green; Then CardA.Power=/2
If CardA.Color=Blue & CardB.Color=Red; Then CardB.Power=/2
If CardA.Color=Blue & CardB.Color=Blue; Then nothing.
---
If CardA.Color=Red & CardB.Color=Blue; Then CardA.Power=/2
If CardA.Color=Red & CardB.Color=Green; Then CardB.Power=/2
If CardA.Color=Red & CardB.Color=Red; Then nothing.
---
If CardA.Color=Green & CardB.Color=Red; Then CardA.Power=/2
If CardA.Color=Green & CardB.Color=Blue; Then CardB.Power=/2
If CardA.Color=Green & CardB.Color=Green; Then nothing

If CardA.Power>CardB.Power; Then destroy CardB
---
If CardA.Power<CardB.Power; Then destroy CardA
---
If CardA.Power=CardB.Power; Then destroy CardA & CardB
B
5
Posts: 38
Reputation: 501


Return to How do I....?

Who is online

Users browsing this forum: bluemonkey, Khamsou and 23 guests