The technology that you do not master, will master you.

New Flash Demo #11: A Card Shuffler

Date/Time Permalink: 02/24/09 10:22:46 am
Category: Flash

It's nothing to get too excited about, but I've made up a small deck of Poker card graphics and some Actionscript to shuffle them. Check the card shuffling demo and grab the GPL'd source code here, if you'd find it useful.

Note, however, that the card graphics are just suits and ranks. I did that to have them be small and yet readable, with an eye towards making a BlogSquare-sized Poker game for the sidebar later. If you want bigger, better cards, Wikimedia Commons has a whole playing-card category, to say nothing of the deck graphics that come with KDE and Gnome card games which should be reusable.

This is one of those classic "should be solved only once" type problems. So now everybody has a deck of cards and a way to shuffle them already pre-built for open-source Flash development, all you have to do is write the game around it. The code isn't brilliant or elegant, but "stupid and robust".

One note about the code that needs explaining: Actionscript uses zero-indexing when creating an array. But SWFTools doesn't seem to allow a "frame zero"; sprites have to start with 1. So I create the Actionscript arrays with an extra space at the beginning (NULL or 0) to avoid having Card_Value[x] correspond to card frame x-1.

Follow me on Twitter for an update every time this blog gets a post.
Stumble it Reddit this share on Facebook

suddenly the moon