I really should let this whole 4k game thing go. But as I was sitting on the train today, idly hacking away at a completely different game I remembered a curious thing that I didn’t have time to investigate then. The mysterious bytes.
Archive for the '4k' Category
So, here it is, the full 4089 bytes of it, a-steroids4k for the gamepoetry 4k flash game compo.
I’ve been wanting to remake an old retro game with new mechanics for some time now but I’ve never had an idea I though worthwhile, there’s way too many half assed remakes out there and it’s hard to beat really innovative ones like 1D tetris or some crazy space invaders version. This is my take on asteroids. I played the original on the proper hardware a few weeks ago and was amazed by two things; The XY-vector screen is *really* bright and it’s hard. Very hard.
So I wanted to juxtapose the underpowered feel and make the player way more powerful, this is a bit tricky without making the game far too easy. The easyness wouldn’t be a problem in itself, but to feel really powerful you need to have a baseline of “weakness” to contrast against.
The basic mechanics came to me on a train ride, luckily I had my trusty laptop near and could churn out some quick proof of concept code then and there. It was only later the 4k competition was announced. I’ve done a game for a 5k compo in the past and enjoyed it immensely, the result of this was lost in a hdd crash and is unfortunately not available anymore. When I started slimming down the game was at about 29k. I ripped out all the sound and got down to 18k (yes, the sounds were tiny). I’d love to post screenshots, but, honestly the game has looked more or less the same ever since it’s conception. Ever since then it’s been a lot of aggressive cutting and small amounts of putting back in.
The full source code is under the MIT License, but a word of warning is in place, this is essentially obfuscated code seeing that I needed to shave of some extra bytes to get the text in there. I also put it up on wonderfl for your fiddling pleasure. I bet there’s a good 20% of savings in there that I just missed, I’ll be thrilled by any modifications to it!
I’ve been toying with an entry into the 4k game competition held at gamepoetry. The game I’m making uses the keyboard for controls which is a bit rare for me.
AS2 had a very useful method called Key.isDown() whose functionality is pretty self explanatory. This isn’t available in the much more event driven AS3, but when doing something as tiny as 4k it’s a pretty useful thing to have. So I wrote my own tiny little version of it. A bare bones swf with nothing but this code weighs in at about 750bytes, but it’s not that big of an addition to your filesize since the swf has some basic stuff that adds to the size. The demo code adds another 200 bytes, but that’s meant to be stripped out.
Note that the trick is to add this into your main class, not to put is as a class of it’s own. That adds too much to your filesize.
I also recently discovered wonderfl which is a crazy cool online actionscript editor thingie. You can try the code live there! or the new even smaller version.
If that’s not your cup of tea, here’s the code in plain old boring text:
(This is an updated version, a whopping 17 bytes smaller)
package { import flash.display.Sprite; public class STKI extends Sprite { // this stores all key states // For some reason this seems to be smaller when typed public var k:Object; private var block:Sprite; public function STKI () { k = { }; // shorthand for initializing a object // the trick is to use the dynamic nature of objects, // if the property exists it's overwritten, // if it doesn't it's created // the function actually gets a KeyboardEvent, but // having it untyped makes it smaller // So does using a regular ("keyDown") string instead // of the static one provided by the event. stage.addEventListener("keyDown", function(e:*):void{ k[e["keyCode"]] = true}); stage.addEventListener("keyUp", function(e:*):void{ k[e["keyCode"]] = false}); // this is just to show that it works block = new Sprite(); block.graphics.beginFill(0xff00ff); block.graphics.drawRect(-4, -4, 8, 8); block.x = 250; block.y = 250; addChild(block); addEventListener("enterFrame", handleEnterFrame); } private function handleEnterFrame(e:*):void{ // this is how you use it, just access the keyCode // in the object, it acts just as good old Key.isDown // from AS2 if (k[37]) { //left block.x -= 1; } else if (k[39]) { // right block.x += 1; } if (k[38]){ // up block.y -= 1; } else if (k[40]) { // down block.y += 1; } } } }







Recent Comments
I'm picking up AS3 from learning C++, and I don't really understand what's going on with [Embed(source='../../assets/gardengnome.png')] private static const GfxGnome:Class; Is ...
Basically I just made sure the import was correct and that it extended bitmap instead of sprite, and it worked ...
@comment above me iv not done this tut yet but did another one earlier that used that trace thing, i didnt ...
what the fuck? it wont let me save the leek the I'm Alive message doesnt work either! im completely new to this ...
I like that one of your level screenshots appears to be a phallic shape, hah.