pong0.5k, a game in 510bytes

Mr.doob created a 1k pong game in as3. Which made my fingers itch to do better. So here it is, in as2, less than half the filesize and the same functionality.

//
// Pong.5k (510 bytes game)
// by Kristof Neirynck
//
// inspired by monoPong-1k and mrdoob
// http://pouet.net/prod.php?which=48976
// http://mrdoob.com/blog/post/485/
//
Stage.align = "TL";
Stage.scaleMode = "noScale";

// making 10 a variable to shave off some bytes
var t:Number = 10;

// speed
var vx:Number = -t;
var vy:Number = t;

// player 1
var p:MovieClip = createEmptyMovieClip("p", 1);

// player 2
var q:MovieClip = createEmptyMovieClip("q", 2);

// ball
var b:MovieClip = createEmptyMovieClip("b", 3);

// drawing the squares
d(p,20,40);
d(q,20,40);
d(b,t,t);

// magic loop
function onEnterFrame() {
  b._x += vx;
  b._y += vy;

  q._x = Stage.width;

  p._y = _ymouse;
  q._y = Stage.height-_ymouse;

  // bounce top or bottom border
  if (b._y<t || b._y>Stage.height-t) {
    vy = -vy;
  }
  // bounce player1 or left border
  // or player 2 or right border  
  if ((b.hitTest(p) && b._x>20) 
  || (b.hitTest(q) && b._x<Stage.width-20)) {
    vx = -vx;
  }
  // someone scored
  if (-t>b._x || b._x>Stage.width+t) {
    b._x = Stage.width*0.5;
    b._y = Stage.height*0.5;
    vx = -vx;
  }
};

// square drawing function
function d(m:MovieClip, w:Number, h:Number):Void {
  //w and h are already / 2
  //w /= 2;
  //h /= 2;
  m.beginFill(0xFFFFFF);
  m.moveTo(-w,-h);
  m.lineTo(w,-h);
  m.lineTo(w,h);
  m.lineTo(-w,h);
  //not needed
  //m.lineTo(-w,-h);
  //m.endFill();
}

17 Responses to “pong0.5k, a game in 510bytes”

  1. Lexi says:

    Lol. I just spent 5-10 minutes trying to play. I remember when I was pretty good at games like Pong and Breakout.

    Jeremy, I agree with your statement. Some of the most fun games I have ever played have been short on the graphics end … Civilization, Colonization. What was the UFO one?

  2. Jeremy G. says:

    Pretty amazing you can make this game so small! Playing this just reminds me of something I have said for years and years: Game play will always be more important than graphics, PERIOD. I haven’t found a single PS3 game I really love yet, and I haven’t touched my Xbox 360 in I don’t know how long.

  3. beech says:

    hey there – i saw this the other day and thought i might join in the fun ;)

    I’ve been able to get it down to 338bytes – but a single player version – you can see it here: http://forums.flashgods.org/micro-pong-as3-t424.html

    I wanted to hide the mouse too but that take 16bytes. the main differences are using the bitmapData class to construct the pieces and reversing the color scheme actual shaved off 4 bytes! LOL!!!

  4. Navier says:

    WOW, wait a second i have a question

    The code that you posted above…is that ALL the code for this neat little game?

    Kristof, do you think that if you add a score to it, the size will increase dramatically?

    Anyway, its amazing that you can write that in 510bytes!

  5. @Matthew: You’re really pushing it to the limit, aren’t you. You could probably win a few more bytes by setting the width and height to numbers you already use in the program and flasm would also help you to a byte or two. Maybe if you compiled it with mtasc it might also be a tiny bit smaller. It’ll never be 200 bytes though.

  6. After a tip off Chris Benjamensen over at nonoba.com I managed to drop it down to 374 bytes. I’d love to see if anyone else can get any better. I have officially ran out of ideas now. Even going so far as to encorporate a basic form of Huffman encoding to the variables names.

    You can see it at: http://www.devslash.com/?p=103

  7. Christophe says:

    Having difficulty with the right paddle :-S

    @Matthew: Good Job

  8. @Mario: 5k and no compression? No way!

    @Matthew: Nice work.

  9. A friend of mine challenged me to try and beat this, so I did.

    Here is a 393 byte version: http://www.devslash.com/?p=103

    I tried to resist using __bytecode__, but I did have to sacrafice scalability of the stage.

  10. I’m sure you could do that Joa ;-)

    Damn, I have to look for that file on an old machine of mine – in 2001 I had a 5K PONG made in Flash 5 entered to the 5kAward. That version included scoring, sounds, one and two player mode and since it was Flash 5 it didn’t even use zlib compression. What a pity that those bastards simply shut down the old site so all the good stuff is gone. And no luck on archive.org either.

  11. Mr.doob says:

    As3c? :)

  12. Joa Ebert says:

    I guess you could make a 200b version using the right tools ;)

  13. Mr.doob says:

    Interesting, I’ve done some more tests and it went down to 505bytes. I wonder if when is this something that scales or what. I mean, I have the feeling that AS3 would beat AS2 in 4kbytes. But here its clear who wins.

  14. benny! says:

    Very nice. My windows version (http://www.pouet.net/prod.php?which=48976) is also getting smaller. With some help the executable is now ~890bytes big. Now I am thinking about adding some sound / scoring system!

    Anyway, nice and tiny pong clone!

  15. @julien: Yes this is merely an experiment. Adding the score would be trivial, but it would also cost a few bytes extra.

    @Mr.doob: It’s pretty much the same as the one you wrote. AS2 is indeed a lot smaller. Took a bit of tweaking here and there to make it half the filesize tough.

  16. Mr.doob says:

    Haha! That’s great! I would asume that AS2 gets compressed better than AS3, isn’t it? Cos the code is basicaly a port of the AS3. Isn’t it?

  17. julien says:

    Very nice…. There’s just one thing I don’t really understand about those “less than 1K games” that have been shown the last few day …where’s the score, and how come I can play the whole night without ever loosing?
    Is it really meant to be a game? or just an AS experiment