Tag Archives: Actionscript

unFocus.Games – Tetris clone

I made a promise on someone else’s blog to post the code for the Tetris clone I made a while back, probably in fatigue induced delirium, a little bit ago, so here it is in a new Google Code project called unFocus.Games. The post on bit-101 post was about game architecture. While developing the code for the clone, I did play with concepts around architecture quite a bit. I also played with learning about Flash 10 features – adding PixelBender filters, and even having an Ogg Vorbis based soundtrack for a while (tried both the HaXe decoder, and the Alchemy decoder). I took them both out for now though, as well as some of the more unorthodox uses of Actionscript 3.0 I had in there – I was experimenting, and besides, Flash CS4′s compiler is a bit more finicky than Flash CS3′s was. One of these days I’ll get around to blogging about some of that stuff.

The Tetris game has an event driven engine under the graphics. I wanted it to feel close to the old NES and GameBoy version of the game I remember as a kid, and didn’t want the animation stuff to get in the way of that. The text version of the game in the demo I posted is almost a raw dump of the engine data. The field is a 2D array of 1s and 0s (looking to learn bit shifting and similar concepts at some point, by converting that to a ByteArray of ints). I also did the pieces (tetrads) as 2D array representations of bitmaps at one point, but didn’t feel like working out the rotation math, so I ported a pre-calculated coordinate version of the tetrads from an old Actionscript 1.0 version of a basic tetris game I once wrote.

Quick note about the code – I used TweenLite to do some of the quick animations, but I did not include that in the repository. You’ll need to grab a copy of that yourself, and add it to your class path to compile the source code as it is. At some point I plan to remove that either entirely or replace it with Tweener (because of the licensing).

In regards to game architecture, I don’t know if it follows any particular pattern (MVC seems to be quite popular these days – can’t talk about software design without hearing of that). Anyway, the code is probably far from efficient, as that hasn’t necessarily been a goal as I wrote it, and it’s far from finished, but there are some fun bits in there. Feel free to take a look, and share any thoughts. :-)

AS3 unFocus.HistoryKeeper in SVN trunk

I added an initial round of AS3 files to the SVN trunk to make HistoryKeeper more accessible from Actionscript 3.0. If you are feeling adventurous, feel free to check it out of the trunk, and give it a try.

There is also a small resurrected Actionscript to Javascript communicator (eh, it’s totally new actually, but I got to use old knowledge!). The theory is that if you use fscommand to send simple strings to Javascript, you save on Flash setting up a lock to wait for a Javascript call to return a value or finish executing, which should conceivably avoid a short hiccup in the Flash Player. I’m not sure if there’s a real world benefit or not yet – one day I might get around to testing to make sure. At the very least, this framework will make it easier to setup fscommand, since it takes care of creating the javascript snippet for you. After that, it will simply eval whatever you put in the command argument (unless it’s a simple function on window, then it’ll just execute that).

Any comments are welcome. Please note, these classes may change quite a bit, they’re not to be considered stable (though the API probably is, there’s not much there really).

MouseWheel on Mac

So for some reason MouseWheel.SCROLL events don’t work on Mac OS X. There is a fix! Gabriel over at Pixel Breaker created a script which fixes it up nicely.

The script did require some modification to get it to work with SwfHTML, since it was designed to work with SwfObject. It took very little modification to the JavaScript to make it work with any flash embedding script. The script has a register method that takes an id, and uses SwfObject’s getObjectById method to get the swf ref – I just changed the register method to take a swf reference instead of an id string, and viola! It works with anything now. While I was at it, I also took care of some errors you might get on non-mac browsers. Here’s how to use it:

// with SwfHTML
swfmacmousewheel.registerObject(
unFocus.SwfUtilities.getSwfReference("swfId")
);

// with SwfObject
swfmacmousewheel.registerObject(
SwfObject.getObjectById("swfId")
);

You can really use any method you want to get a reference to the swf object, and pass that in.

Here is the updated swfmacmousewheel javascript file. Note, you will still need to grab the source and follow the instructions from Pixel Breaker.

New Paint and Tetris

I thought the site needed a new coat of paint, and so I think Tetris is in order!

Update: Moved to a separate page.

Click to give flash focus – arrows move, up arrow rotates.

There’s no start button, or end to the game – and no levels or scores either. But it’s a start. :-)

Quick Update – HistoryKeeper, SwfHTML, SwfShim

Just a quick post.

There have been a couple of fixes and changes that have gone into HistoryKeeper, SwfHTML and SwfShim that are now in the SVN trunk, as well as a few other issues that have been nailed down, and put into the issue tracker.

Among the fixes are finally a fix for the incorrect use of Javascript Errors in SwfHTML, as well as fixing the previously unfinished SwfShim.

Despite the fact that I can’t figure out how to pass flashvars from SwfShim to loaded AS3 based swfs, I’m still going to include it anyway, with a note about that caveat. It does solve some other issues, and adds an easy way to utilize ExpressInstall even if you are using html to embed the swf (rather than javascript). More on that in a future post.

I’ll also be cleaning house around the site, here and on google code. I’ve already removed some old lingering (and useless) ad stuff.

Also, since Microsoft removed the “click to activate” silliness, I went ahead and deprecated PatentMagic. It was buggy anyway.

Check back for more updates, and hopefully, an actual release!