Game Development Community

A Deck of Cards

by Charles "monkeyboy" Gibson · in Torque Game Engine · 09/14/2006 (1:27 pm) · 1 replies

How can I access 52 static sprites that represent each card in a deck of playing cards in my script. Currently, I have used the TGB to set the class of each sprite to its card face (i.e. the Ace of Clubs has a class of aceClub). Then in my script code I define a block for each card like so:

function ::onLevelLoad(...)
{
$thisCardGlobal = %this;
}

Then later in the code I reference the global. This pains me so bad. I made 52 of these code blocks that represents all 52 cards and map to each of their static sprites. I want to know how I can refactor this. This is killing me. I would like to make one class and instance it for each card and be able to represent that in my scripts.

I am sure there is an easy way to accomplish so sorry in advance for my noobness.

Thanks

#1
09/14/2006 (3:08 pm)
Okay, I made a change but still do not like it. It feels like it is a step in the right direction, but am looking for some feedback.

Okay, I was able to remove the ridiculous code blocks mentioned above and collapse that into a single card class. So when the card sprites are loaded into the level they add themselves to a global card collection. I use that to reference which sprite I want to use.

The problem I am having with that is I created dynamic fields in the level builder that identifies each face and suit of the card (i.e. face = 10 and suit = 0 where 0-3 is either clubs, spades, hearts, or diamonds). I would like to remove this duplication if possible.

If you have any thoughts I would really appreciate it.

Thanks