Sequencers

posted in kiwibonga's Blog
Published February 28, 2011
Advertisement
Lots of bug hunting today.

Just finished the code to deal cards from a deck to an arbitrary hand. I don't know if anyone else will understand it, but here goes:

void BJDeck::giveCard(BJHand* hand)
{
// Create new sequencer object
Sequencer* cardgiver = new Sequencer();
cardgiver->attach(this); // attach it to the deck

// Create new card's sprite, face down
Sprite* s = new Sprite("Card back vertical"); // new sprite using "card back" graphic
s->relativeAttach(hand->cards); // attach with relative positioning to the target hand's "cards" actor group
s->setPosition(position); // spawn it at the position of the deck

s->hide(); // hide it for now

// 1. Add a sequence message to unhide the card sprite when the sequence starts
SeqMessage* sm = new SeqMessage();
sm->setCommand(&ScreenObj::unhide); // universal functor in action here
sm->attach(s);
cardgiver->sequenceQueue.addRelationship(sm); // we add the message to the sequence

// 2. Flush: move the card sprite in a straight line to a given position on the table
Flush* f = new Flush();
f->setCourse(hand->nextCardDest(),10); // here we ask the hand where to put the new card, and set it to get there in 10 frames
f->attach(s);
cardgiver->sequenceQueue.addRelationship(f);

// 3. Sequence message to change the graphics resource used by the card sprite
sm = new SeqMessage();
sm->setCommand(&Sprite::changeResource,buildArgSet("Card Grid")); // 13 x 4 grid of card tiles
sm->attach(s);
cardgiver->sequenceQueue.addRelationship(sm);

// 4. Sequence message to set the correct tile index on the card sprite
sm = new SeqMessage();
sm->setCommand(&Sprite::setTileIndex,buildArgSet(getNextCard())); // getNextCard gives you the next card number (0-52) in the shuffled deck (6 x 52 cards)
sm->attach(s);
cardgiver->sequenceQueue.addRelationship(sm);

// 5. Add a 20 frame delay after the card has moved
SeqCountdown* sc = new SeqCountdown(20);
sc->attach(s);
cardgiver->sequenceQueue.addRelationship(sc);

// Add this "cardgiver" sequence to the Scene Manager's sequence list
SceneMgr::getInstance()->sequenceListeners.addRelationship(cardgiver);
}


Spawns a new card, moves it, flips it over, and dies gracefully... Which reminds me, I'm supposed to create an actual card object class that can be flipped instead of manipulating sprites directly.

Well, back to work.
Previous Entry Introducing... Hardk
Next Entry Monkey Mind
0 likes 0 comments

Comments

Nobody has left a comment. You can be the first!
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement
Advertisement