Build 10 classic Flash games and learn game development along the way with this ultra-fast paced game development course.

If you love this blog, this is the book for you.

Buy the book

Get the source code of 12 commercial Flash games, which have been loaded more than 50 million times!

Learn from real world successful examples.

Get it now

Box2D for Flash Games teaches you how to make Flash physics games from scratch with the most advanced features.

Create the new Flash game smashing hit.

Buy the book

Complete Flash Sokoban game in less than 2KB

Some days ago I blogged about 6 games you must be able to make in less than a day.

Among these games I included Sokoban, and since I don’t remember if I’ve ever tried to make a complete Sokoban game, I did it today.

In less than a day and, above all, in less than 2KB!!

And don’t expect an incomplete prototype… my Sokoban game features:

* 10 levels
* Tiles of different color and shape
* Shared objects to save the games
* Eye-candy effects (being only 2KB!!) to show completed levels and current level
* Copyable level moves to publish your own level solution
* In game instructions
* No external files or other tricks to reduce file size.

As said, in less than 2KB. My latest build is 2,002 bytes that’s less than 2,048.

This is the source code, that wasn’t written with readability or performance in mind, just aiming to stay under 2KB… just an exercise:

This class was compiled with “Compress movie” checked and “Include XMP metadata” unchecked

And this is the result:

Move with arrow keys, select levels with 0-9, leave a comment with your solutions… and try to give me an idea about another game to make it fit under 2KB.

If you want to check file size, save this file and see…

Rate this post: 1 Star2 Stars3 Stars4 Stars5 Stars (21 votes, average: 4.95 out of 5)
Loading ... Loading ...
Flash Templates provided by Template Monster are pre-made web design products developed using Flash technology.
They can be easily customized to meet the unique requirements of your project.
Be my fan on Facebook and follow me on Twitter! Exclusive content for my Facebook fans and Twitter followers

This post has 25 comments

  1. AnotherGuest

    on May 19, 2010 at 5:30 pm

    Pac-man can probably be done in a few KBs…not sure it can be as small as 2KB but still, an interesting challenge, isn’t it ?

    Easier : checkers.

  2. Andreas Renberg

    on May 19, 2010 at 7:55 pm

    How about Snake? I’m pretty sure it could fit under 2kb.

  3. Shawn

    on May 19, 2010 at 10:13 pm

    On Sokoban: I notice that when you move right, the “level moves” indicates left and verse visa… Other than that, amazing! Also, it seems a bit awkward that Stages 1, 2 and 7 are harder than stages 8 and 9. (I’ve cleared all but 7 so far, that one makes me scratch my head.)

    On other possibilities: Can’t space invaders be crammed into a few K?

  4. grapefrukt

    on May 19, 2010 at 11:22 pm

    Yes! I love this bytehunting stuff, so I amused myself by seeing if I could slim your code down even more. I managed to shave 131 bytes off, that’s 6.5% smaller.

    I put both our versions on wonderfl, mostly to get the nice diff.

    your original version: http://wonderfl.net/c/4oMt
    my, slightly smaller, version: http://wonderfl.net/c/5PAV

    I think there’s a few more bytes to save if one could get rid of all those getChildByName calls, but that’ll require a bit more of a rewrite.

    Keep up the nice work!

  5. Emanuele Feronato

    on May 20, 2010 at 11:33 am

    Yeah, removing the “switch” was a great idea

  6. Colin Diam

    on May 20, 2010 at 11:40 am

    1st Level…
    RRRULRRRDLULLDDRULURDLLLURRDRRRUULDRDUDLLLUR

  7. Josh

    on May 20, 2010 at 12:54 pm

    I think Frogger would be a good one to try and do in under 2k

  8. Yago

    on May 21, 2010 at 1:43 pm

    There’s a bug, when I finished the first level debugger says:

    TypeError: Error #1009: No se puede acceder a una propiedad o a un método de una referencia a un objeto nulo (it’s in spanish, I think it could be traduced as “Can’t get access to a null object”).
    at s/w()
    at s/k()

    Any way, great game and incredible that 2Kbs optimization!! I still remember that little man with frozen arms moving blocks in the oldest version… Ciao!!

  9. Alon

    on May 21, 2010 at 8:42 pm

    There is no restart mechanism =D I will add one and post it if someone wants.

  10. Emanuele Feronato

    on May 21, 2010 at 11:22 pm

    You can restart a level simply pressing the relative 0-9 key…

  11. Bruno

    on May 23, 2010 at 3:18 am

    You could shrink it a little more by removing the first if in w() method by making

    var v:Boolean=(r[p[0]+b][p[1]+a]==0||r[p[0]+b][p[1]+a]==2);

    along with grapefrukt’s removal of the switch statement.

    Anyway, great code! I follow your blog since a while ago, and your codes are always inspiring.

  12. Yarden Refaeli

    on May 24, 2010 at 10:42 am

    You shouldn’t use one-letter names… Even when you want a lightweight game…

    Nice game!

  13. Nigel

    on May 27, 2010 at 1:42 am

    I can’t get past the first level :(

  14. Ezell Burke

    on May 27, 2010 at 7:34 am

    This is really great it inspires me to challenge myself. I am thinking of writing a graphical zork-like game.

  15. Wolfos

    on June 1, 2010 at 12:35 am

    normally it’s fun,but this game is impossible to beat.

  16. Lev Blake

    on June 9, 2010 at 6:27 pm

    Hi Emanuele

    Great coding tuitions, shall try them.

    I finished all the levels on this, with 5 being the trickiest for me.

    The coding IS clever, but even more than that the content, ie the puzzles you set, is fiendish!!! How did you work out the layout and problems for each level? Think you need to be a mathematical genius :-)

  17. Cum se inventeaza un joc? (2) « Gramo

    on June 14, 2010 at 11:29 am

    [...] acum ajung la problema mea. Cum am inventat jocul asta? E clar ca seamana cu Sokoban (vezi si aici), nu? La un nivel mai abstract, seamana cu toate jocurile care nu se desfasoara intr-un spatiu [...]

  18. Pepe

    on July 25, 2010 at 1:53 am

    Could someone explain the variables? 4 the noobs pls! That would be great.!

  19. Vingador

    on August 27, 2010 at 5:08 pm

    It doesnt working for me, sorry.
    Im using Adobe Flash Professional with AS3. Are this game for AS3 or AS2?

    Thanks and i will wait for an answer.

  20. Cyclone

    on October 27, 2010 at 11:47 pm

    I have a shorter solution: RRURRRDLULLDDRULURDLLLURRDRRRUULDRDLLLUR

  21. Anonymous

    on February 20, 2011 at 5:13 pm

    LVL0:RRRURRDLULLDLLURRRLDDRURRUULDRDLLLUR
    LVL1:RDRUDRRULLLUURDLDDLLUR

  22. Mike

    on February 21, 2011 at 12:42 am

    I am with Nigel on this one, I can not get past the first level either. To do this in less than a day and have 10 levels is good going.

  23. Simon Gleizes

    on May 1, 2011 at 2:17 pm

    :

    [0]:RRRURRDLULLDLLURRRLDDRURRUULDRDLLLUR

    [1]:DRRUDRRULLLUURDLDDLLUR

    [2]:RDRRULLDLDDRULURUULDDURRRDLLDDLLURDRUU

    [3]:DDRDDLURURULLLRRDDLURUULLDRURDULLLLDRR

    [4]:RRRDDLLLRRRUULLLDURRRDDLLURLLLLDDRULURRURRDDRRUULLRRDLDLLLULLDDRULUR

    [5]:DDRUDRRULLULUURDDDRDDLULURUULD

    [6]:URUULDDRDRRULDLULULLDRRRDDLURULUURDDLDDRRRUULDDLLURLURLULLDRURRDDLURULDDDRR RULLDLUDRRRUULDLU

    [7]:RDDLUDLLDDRRUDLLUURRURUULDDDLLDDRRURUUDDLDLLUURRURDLUUURD

    [8]:LLDLURRRDLLRRUUULDRDDLLURDRUDLLULLDRRRLLLUUURDLDRRR

    [9]:UDLLUDRRULUURDLLDRDLUURRDULLLULLDRRRDRRUULDD

    I know, I know…6 is a bit long, haha. Great game and nicely done making it ~2KB!!

  24. Simon Gleizes

    on May 2, 2011 at 10:13 pm

    Much shorter solutions to 3, 6, 7, 8, and 9:

    [3]: DDRRULLLRRDDDLUURUULLDRLULLDRRURRD

    [6]:URUULDDRDRRULDLULULLDRRRDDLURULUURDDLDRUULLLDRURRDDLURULDDDRRRUULRDLLDLURU
    (!!!)

    [7]: RDDLLLDDRRUDLLUURRURUULDDDLLDDRRURUUDDLDLLUURRURDULUURD

    [8]: LLDLURRRDLLRRUUULDRDDLLURDRULLLLUURDLDRRRLLLDRRR

    [9]: UDLLUDRRULULLRRURDDLULDULULLDRRRDRRUULDD

  25. mahongquan

    on March 10, 2012 at 4:29 pm

    I made a classic sokoban game ,It is on base of source code from your flash game making book.
    and I add solved methods in game,thus it is good news for sokoban newbie.