4k – prototyprally https://prototyprally.com/ rapid prototyping of games using flash Sun, 19 Feb 2017 18:52:37 +0000 en-US hourly 1 https://wordpress.org/?v=5.1.1 Another forty bytes the dust. https://prototyprally.com/another-forty-bytes-the-dust/ https://prototyprally.com/another-forty-bytes-the-dust/#comments Sun, 10 May 2009 20:12:58 +0000 https://prototyprally.com/?p=322 Continue reading ]]> 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.

The compiled size of the same actionscript file will vary with up 4 bytes between compiles. You can really just bring up the command line and recompile the same file a couple of times and it will be 4098 bytes the first time and 4094 the next. Very strange. I tweeted about this suspecting some kind of metadata was stored inside the file, someone told me this shouldn’t be the case so I let it go. Turns out metadata is stored, and more than you’d think. A standard swf compiled with mxmlc can have these values:

  • contributor
  • creator
  • date
  • description
  • language
  • localized-description
  • localized-title
  • publisher
  • title

The mysterious bytes come from the fact that there is a timestamp embedded, this will affect the compression of the swf making it compress a few bytes smaller if you’re lucky and a bit bigger on other occasions. These have default values, and these may be useful to keep track of stuff, they’re just a bunch of bloat to a 4k game. Luckily they’re a piece of cake to get rid off. Add these options to the compiler to set them all to be empty:

-contributor=''
-creator=''
-date=''
-description=''
-language=''
-publisher=''
-title=''

(In FlashDevelop you set these options in Project Properties -> Compiler Options -> Additional Compiler Options) However, the swf will still be up to three bytes bigger on occasion, I think the time still gets in there somehow. Nevertheless, this shaves of a whopping 40 bytes on my current version of asteroids4k!

]]>
https://prototyprally.com/another-forty-bytes-the-dust/feed/ 5
a-steroids4k https://prototyprally.com/a-steroids4k/ https://prototyprally.com/a-steroids4k/#comments Tue, 10 Mar 2009 19:43:27 +0000 https://prototyprally.com/?p=289 Continue reading ]]>

Get Adobe Flash player

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!

]]>
https://prototyprally.com/a-steroids4k/feed/ 12
4k – Tiny Keyboard Handler https://prototyprally.com/4k-tiny-keyboard-handler/ https://prototyprally.com/4k-tiny-keyboard-handler/#comments Fri, 13 Feb 2009 06:00:29 +0000 https://prototyprally.com/?p=232 Continue reading ]]> 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;
            }
        }

    }
}
]]>
https://prototyprally.com/4k-tiny-keyboard-handler/feed/ 9