Infinite Ammo 4k Source Code Released

Infinite Ammo 4k

Well everyone else seems to be blogging about the release of their 4k games, so I’m doing so too :) I managed to get mine finished and submitted on-time. I don’t expect it to win a thing (results are in 3 days time), but I had great fun participating all the same.

I have created a games page entry for it, and in a slightly unusual move for me I have released the full source code for the game too. You can get it from it’s games page. What you learn from it I have no idea. At the very least there’s a pretty explosion / particle system, and a massively optimised and compressed Tween engine! Or you could just skim down through the code, shaking your head thinking “and he ENJOYED coding this?!” :)

Posted on March 11th 2009 at 12:21 am by .
View more posts in ActionScript3. Follow responses via the RSS 2.0 feed.


14 Responses

Leave a comment
  • dVyper
    March 11th 2009 at 8:29 am

    On the games page for this game the link to the source code doesn’t work :(

  • spalios
    March 11th 2009 at 9:25 am

    source code : page not found…

  • March 11th 2009 at 10:04 am

    Sorry guys, should have checked (or should have not written the post at 1am) – link fixed.

  • Jonathan
    March 12th 2009 at 7:42 am

    and you spelt Urbansquall incorrectly too.

    Anyways, good job.

  • March 12th 2009 at 10:05 am

    Thanks for sharing.

  • Jonathan
    March 12th 2009 at 5:42 pm

    Hey,

    Why is it when I build it the size comes to 4555 bytes? :S

    I’m quite sure I can squeeze out about 500 bytes or so looking at your code. Most of it from getting rid of your class.

  • March 12th 2009 at 5:46 pm

    Have you disabled XMP Metadata and Omit traces?

    Removing the class and putting the code entirely on the timeline will add several hundred bytes to the SWF size. I tried it already.

  • Jonathan
    March 12th 2009 at 5:48 pm

    Yes I did disable xmp metadata and omit traces. I have no idea why it’s 4555 bytes though. It’s not because of the comments either because they add nothing to swf size.

  • Jonathan
    March 12th 2009 at 5:49 pm

    Edit: Oops my fault. Down to 4096 now. I’ll email you a smaller version later. It’ll probably have enough space for you to fix your boss animation…

  • March 12th 2009 at 6:05 pm

    Good luck! It’d be better to fix the enemy spawning than the boss, at the moment they cluster in the center before chasing you – changing that to randomise where they come on, in relation to where the player is at the time, would give a much nicer experience later on in the game.

  • Jonathan
    March 13th 2009 at 1:12 am

    Couldn’t find your email. Oh well.

    Could’ve shaved more off but I’m too tired and lazy to do it now, and most likely won’t be bored enough to do it later lol.

    This should be enough space for you to fix your enemy spawning thing. Maybe even enough to put in a simple shooting sound clip! or more eye candy. Actually, you better fix the boss too, because right now you pretty much die instantaneously when you hit it (put in a timer that stops you taking damage too often)

    Three major things you didn’t do to save space:
    1. substitute 1 and 0 for true and false. Saves 1 byte.
    2. Reuse temporary variables for your for loops.
    3. Why’d you add the :void after the functions? They add to the size…

    Another major thing is… you used AS3 instead of AS2! But you wanted that copy function so … meh. AS2 also can’t draw competent circles when you’re trying to limit the size of your file.

    Still, when I tried using classes vs using no classes in as2 using no classes resulted in a smaller file size. But apparently AS3 is different, maybe because it was built to be Object Oriented…

    Anyways, here.

    http://www.sendspace.com/file/5x7o1p

  • March 13th 2009 at 1:52 am

    My email is in the readme.txt in the source zip, or on the “Contact” page on this site!

    Just had a quick peek at the changed source, interesting stuff. 219 bytes saved mostly by making my var and function names single/double characters and removing the :void’s which I neglected to do. Surprised they took up 13 bytes each actually, a lesson learnt for next time, so thanks for that.

    By un-obfuscating your code I have made the swf smaller. Mixing ints and arrays on a single var line took up more bytes than unrolling it. I split out all vars except fx and the arrays and it compiled smaller. Also moved the Textfield back into the constructor (it saved nothing where it was)

    Swapping the bools for 1/0 did indeed save 1 byte, sadly at the expense of compiler warnings.

    It’s a shame you didn’t change something fundamental to the core of it, I’d loved to have seen how it could have been made smaller in that respect. Things I could have done but ran out of time include using drawPath instead of my graphics rout at the start, and I could have held ALL data (player, enemy, everything) in a single array with a few offsets. But at that point it becomes an exercise in obfuscation over making a game.

  • Jonathan
    March 13th 2009 at 2:57 am

    I rather didn’t want to change anything at the source, because I wanted to keep it as much as the original game as possible. If I was looking to change stuff at the source, I’m sure there are plenty that can be changed, but your code is already pretty optimal. One thing I personally would do would be to try to limit the number of floating point numbers used. Like, in your rotate to face the player code, I changed your 57.xxxxxxx to just 57, and it saves 13 bytes. The result is no different from when you had it a bit more exact. Also, it was quite interesting to find that in AS3 having local variables actually saves more space than declaring it all at the start, which is the opposite for AS2 (local variables take up a lot of space, even iterator variables, like var i, was declared at the top to save space).

    And also mixing ints and arrays on a single var line takes more space than unfolding it? Really? That wasn’t the case for AS2, but it probably was because AS2 vars have a lot more freedom to take different variable types…

    Also, I forgot to test this for AS3, but for AS2 using dynamic variables saves more space than declaring it.

    By the way, of the 219 bytes saved, using smaller variable names only saved around 20 bytes, which is not a lot. Most of the savings came from moving stuff around, just changing the order your code was written in.

    I strongly suggest AGAINST putting everything in a single array unless you’re really disparate for space because the amount of stress for your brain is not worth it ^^ Other possible changes include: getting rid of your easing system and putting in an alternative (which might even look better because right now the tweening looks weird), drawpath, as you said, as a substitute to your extremely cryptic drawing system (which is almost like a packet writer lol), finding an alternative way to using your mask (the mask takes up lots of space), and a reworking on the timers and stuff, you don’t really need that many timers, and rather than basing weapon upgrades on number of kills you can base it on score or after every boss, it might even be possible that using two textfields will save more space than using one and moving it around. Then again, probably not.

    But yeah there’s no point talking about it now since the competition is over, unless you are deciding on fixing the game up for a proper release, but even then you wouldn’t need code optimizations, because you would be able to be as lazy as you want lol.

  • April 18th 2009 at 2:41 am

    You’re amazing man!

Make yourself heard