retro
Super Mario Bros. In 14 Kilobytes Of Javascript
Posted by Michael McWhertor at 1:27 PM on April 10, 2008
It may be lacking in Koopas, power ups and an underworld—not to mention the dreaded embedded MIDI soundtrack—but this Super Mario Bros. clone packed into 14 KB of Javascript is still damn impressive. Using no graphics, rendered entirely in compressed script, the exercise is definitely worth a few minutes of your time, even if the collision detection leaves a bit to be desired. It's only World 1-1, so you won't have to invest much time to get the gist, but a fantastic accomplishment regardless.
Super Mario in 14kB Javascript [nihilogic]

Comments (AU Comments · US Comments)
There are currently no AU comments for this post.
eelmonger
Posted 1:31 PM 10/4/08
Given the size of the original game (40k) and the fact that this javascript is actually compressed from 35k, the size is nothing special.
@Dakobah: He used sprites, just not from external files. Basically he defines a big chunk of memory with a space for each pixel and puts 0-3 in each space to define which of the 4 colors will be used. It's a bit more complicated than this because you squish it by putting 4 of these in 1 byte, but basically it is exactly how you'd make sprites for the NES, just in javascript instead of assembler.
eelmonger
Erwin
Posted 1:27 PM 10/4/08
Wrong placement of Goombas, no Koopas, stars, mushrooms, or ending, and the enemies don't even drop off ledges? Still cool though.
Erwin
GREY GECKO
Posted 1:22 PM 10/4/08
its a little step for the developers
one giant leap for gaming
GREY GECKO
riffleraffle
Posted 1:11 PM 10/4/08
uch, disregard the doublepost
riffleraffle
NitrousO
Posted 1:10 PM 10/4/08
I am awaiting the version that uses a single bit to create a fully functioning version with extra levels and CD quality music :D
Played it and I have to ask, does anyone remember there being like 8 goombas in a row anywhere on level 1-1? I ran into them not expecting it and got shuffled into (Mario used to be such a wuss).
NitrousO
riffleraffle
Posted 1:10 PM 10/4/08
Creepy serial killer version of the Mario theme in the background.
*shudders*
riffleraffle
Tulkamir
Posted 1:10 PM 10/4/08
Hmm, yea, not that impressive when compared to other things.
Kkrieger being the best example that comes to mind.
Tulkamir
riffleraffle
Posted 1:09 PM 10/4/08
That's a really creepy serial-killer version of the Mario Brothers theme playing in the MIDI, Jesus.
riffleraffle
DimensionWarped
Posted 1:08 PM 10/4/08
It's a pretty poor duplication lacking all but the simplest elements of the game and the memory being so low really isn't very impressive considering what Golds had to say.
I've seen far more impressive tech demos take up less space.
DimensionWarped
Seraphim84
Posted 1:07 PM 10/4/08
don't walk left!
Seraphim84
Dakobah
Posted 1:06 PM 10/4/08
i havent run it, but he was able to draw using code?
so no sprite was used it was just drawn by code?
fascinating
*note* im not a programmer so easily ammused.
Dakobah
BigChiefSmokem
Posted 1:03 PM 10/4/08
no castle, no cake
BigChiefSmokem
Golds
Posted 1:00 PM 10/4/08
This is a cool exercise in javascript, but the 14kb isn't really all that impressive when you consider that the original game, in its entirety, is only 40k of data and code.
Golds
bobtheduck
Posted 1:47 PM 10/4/08
It ran way too slow, you could get stuck on jumps, jump mechanics had the super bounce that started with SMB3, goombas never left the screen once stepped on, but even midi files tend to be large, so this was probably a big feat.
bobtheduck
MisterSleep
Posted 1:42 PM 10/4/08
I'm still pretty impressed. Javascript is a high-level language, so even with compression, there's a good amount of syntax that cannot be compressed and still have to be followed, and each character adds to the memory total. In addition, working with browser display limitations and coding for multiple browsers (IE always requires workarounds), I'd say that this is no mean feat. Kkrieger was damn impressive but it's a totally different playing field.
MisterSleep
Owen Good
Posted 2:28 PM 10/4/08
This sumbitch is hard. Why am I playing it and not Xbox?
Owen Good
Dakobah
Posted 2:19 PM 10/4/08
@ShintoCross1:
dude not only wrong blog post but you triple post, chill out you look like a tool.
Dakobah
THECapedCaper
Posted 2:15 PM 10/4/08
I'm not impressed in particular, but if the goal was to make a recognizable game using such little space then my hat's off to them. I would've been more impressed if the game was actually playable. The hit detection is just awful and the lack of items/proper places for blocks/enemies/pipes/music/wtfever leaves a lot to be desired.
Somebody must've spent a lot of time on it though...yeah.
THECapedCaper
ShintoCross1
Posted 2:08 PM 10/4/08
HALFWAY.
ShintoCross1
ShintoCross1
Posted 2:08 PM 10/4/08
I WAS HALFWAY FINISHED WITH MY COSTUME.
ShintoCross1
ShintoCross1
Posted 2:08 PM 10/4/08
WHAT THE FUCK I WAS HALFWAY DONE MAKING MY COSTUME.
ShintoCross1
L0velime
Posted 2:04 PM 10/4/08
being coded with javascript makes it kind of cool, but I can't stop comparing it to Kkrieger mentioned above several times, but it is because of the visual differences that I find Kkrieger more impressive, a 14k game that looks like Super Mario Bros or a 96k FPS that looks almost like Doom III.
I have no skill in programming, so I can't tell which one is the most impressive from that point of view
L0velime
Yourspace
Posted 1:46 PM 10/4/08
14 kb is really good though. I'm only in my 3rd semester of comp sci classes, and I've wrote bigger programs (in Java).
Yourspace
Yourspace
Posted 1:43 PM 10/4/08
The graphics look really good, but I keep outrunning the screen. Also, wtf is up with the music?
Yourspace
Killer6
Posted 1:00 PM 10/4/08
Only 1-1? Damn, I thought it was the whole thing by how the headline read.
Killer6
dowingba
Posted 2:57 PM 10/4/08
If they made the whole game this way it'd be 896kb. Which is 22.4 times the size of the actual game Super Mario Bros. for the NES.
dowingba
Doomstink
Posted 3:08 PM 10/4/08
Didn't someone create a 3D FPS game in under 20Kb? Mario isn't to impressive when you consider that.
Doomstink
Highlander Wolf
Posted 3:46 PM 10/4/08
*sigh*
Okay guys. Everyone who is comparing this (really impressive!) 14KB JavaScript verison with the 40KB original are missing the point.
This JavaScript is 14KB of text. The original mario was 40KB of machine-code. That's the end result after you compile a program; every function and expression written in text is converted to computer logic - a bunch of 0s and 1s - which tells the hardware what to do in language it can understand.
Mario was likely written in assembly or a higher-level programming language; these are compiled and reduced to its smaller form, the machine-code executable. JavaScript is a scripting language. It runs inside your web browser. It isn't compiled; the browser interprets the scripts, written as text, at run-time. Text files are MUCH larger than machine code.
IMHO, this is really remarkable; The performance/framerate is great on my browser, better than the other JavaScript attempts at mario I've seen. The graphics are nearly identical to the original. The code is elegant, and WTF? No external graphics files???
It's all text. Brilliant.
Highlander Wolf
sanjiyan
Posted 3:42 PM 10/4/08
I like how the end of the level was like the "end of memory", the boundary of the game universe.
I wonder if Beverly Crusher felt like that seeing the edge of the donut universe.
@dowingba: 896kb would be the size of the source code. Javascript is not a compiled language, so comparing it with the size of executable code on a cartridge is nonsense.
Besides, IIRC, SMB was probably mostly written in 6502 assembly.
sanjiyan
Marlor
Posted 3:29 PM 10/4/08
@Dakobah:
Back in the day, all of our sprites were "drawn by code".
I remember sitting at school spending half the day calculating values on a "sprite grid" so I could generate sprites for my half-arsed, home-made C64 games.
Marlor
elislider
Posted 4:00 PM 10/4/08
@Highlander Wolf: ah yes, a true code junkie sheds some light. i was waiting for that
elislider
Highlander Wolf
Posted 3:59 PM 10/4/08
@Doomstink:
You might be thinking of ".kkrieger", which was made by some German Demoscene guys a while back. .kkrieger is a 96KB FPS, and looks amazing considering its size:
+ Watch video
They built most of the game with procedural generation, a programming technique, instead of using larger graphics or sound files. They're using this technique for games like Spore.
Highlander Wolf
peteer02
Posted 4:48 PM 10/4/08
Looking at the source code, (the uncompressed script is linked to on the main page) even someone who's never programmed should recognize how cool this is. Music, graphics, everything in one short file...very impressive.
peteer02
dowingba
Posted 4:47 PM 10/4/08
@sanjiyan: Huh? That doesn't change that it would still be 22 times larger than the original SMB. My point was simply that this was way larger, than the original SMB. Which I'm pretty sure is all I said.
I'm sure this was an amazing feat, but so was the original SMB, and it's smaller.
dowingba
bangbangblah
Posted 5:08 PM 10/4/08
@ShintoCross1: You're hurting my ears!
bangbangblah
Marlor
Posted 6:04 PM 10/4/08
@dowingba:
It's not a fair comparison. There's no way you can even compare machine code with source code from an interpreted language.
This isn't compiled. He's implemented things that would have been done in hardware in the NES. It's with a language that was designed for simple tasks like validating web forms.
Doing this in 14K of Javascript is impressive. Doing this in Javascript at all is impressive.
Marlor
Fireblast
Posted 6:58 PM 10/4/08
That makes the original look bad because this is more polished!
Fireblast
Ultrasinc
Posted 7:35 PM 10/4/08
I lol'd when i first walked left...
Ultrasinc
kiigan
Posted 7:22 PM 10/4/08
In fairness, 14kb is quite a lot of Javascript.
The only people who think this is impressive are people who aren't programmers :)
If you want impressive, check out some of the 4kb demoscene stuff!
kiigan
Marlor
Posted 8:02 PM 10/4/08
@kiigan wrote:
"The only people who think this is impressive are people who aren't programmers :)"
I'm a programmer, and I find it pretty damn impressive. The code is actually tidy enough (when uncompressed), and it's all pretty efficient. Plus, it's Javascript.
Comparing this to compiled code is just silly (unless you are referring to some 4kb demoscene Javascript that I'm not aware of).
Marlor
in5ane
Posted 8:53 PM 10/4/08
Nah, this isn't impressive, and I can code. For starters, Firebug reports this as 15KB... 14KB is LIES! And it's compressed, so comparisons to the compiled 40KB full game are certainly valid.
I'm not saying it's not neat, but it's not impressive I'm afraid. Any coder saying it is hasn't finished their degree yet :)
in5ane
Marlor
Posted 9:57 PM 10/4/08
@in5ane:
By compressed, they mean that superfluous data has been removed from the code (making it harder to read, but smaller). By doing this, they have actually reduced the size to 13.7 KB.
If it was zipped up (for example, using 7zip), it would be around 6.5 KB. Even then, it's not comparable with the NES game at all. Coding for the NES is largely about invoking hardware routines in as quick and efficient manner as possible. Coding a game in Javascript largely involves trickery and hackery to get functions that were designed for rudimentary web page manipulation to actually work in a gaming context. There is no way you could rationally compare the two.
And saying "any coder saying it is [impressive] hasn't finished their degree yet" just smacks of unjustified hubris. Have you looked at the code? I'm no Javascript expert, but it really doesn't look bad at all. It manages to strike a really nice balance between brevity and readability (in its uncompressed form). I'm about three months from finishing off my Computer Science PhD thesis, and I thought it was pretty neat.
Maybe I'm just easily impressed by things like this. But I really do feel bad for people who put a lot of effort into a neat tech-demo like this one, only to have people put them down. If you think this is unimpressive, then let's see what kind of game you can create in around 14K of Javascript. If it's good, I'll be the first one to say "congratulations". But until then, I really don't think you have any right to demean this guy's efforts.
Marlor
Rebelphoenix83
Posted 11:41 PM 10/4/08
This is kinda... not good.
Rebelphoenix83
220
Posted 12:58 AM 11/4/08
Size aside, this is a very impressive feat. The browser environment was never EVER designed with this in mind. It is developed and primarily used to display static documents. Developing this type of application requires a lot of outside-the-box thinking and creativity.
I would not be in the least surprised if witting this game in javascript is more cumbersome then creating it in machine code for the original 25+yr hardware.
@kiigan : The only Programmers who wouldn't find this impressive are those who know nothing about web application development.
220
Airan
Posted 4:36 AM 11/4/08
Looking at the code, I've no idea how those sprites are drawn. It all looks like a mass of jumbled characters. Fascinating stuff :o
Airan
kftgr
Posted 4:51 AM 11/4/08
@in5ane:
LOL. You say you can code, but think that the simple YUI compression makes it comparable to 6502 code.
@bobtheduck:
Slow? Could be your browser. Try the latest Webkit or Opera Wingogi build ([labs.opera.com] then click on the Windows or Linux links).
kftgr
SuperMaxZero
Posted 3:09 PM 12/4/08
The music didn't work for me, for some reason. I wanted to hear the alleged serial killer Mario theme MIDI.
SuperMaxZero