HTML5 game written in 0 lines of JS
codepen.io
codepen.io
I'm not the original author. It was posted on russian HN/Reddit clone Habrahabr: http://habrahabr.ru/post/203048/ Habrahabr featured translations of "30 LOC of javascript" topics from HN, some people continued it for a bit, and this one was created as an ironic answer to that.
I for one want to watch TV programming from around the world just to experience the differences in culture and what they find humorous, sad, exciting, and so on. Sub-titles just don't always translate emotions very well.
-----
I didn't want to take part in this week's trend on Habra: "We can write everything in 30 lines of code!" I didn't have the time to spare.
But theaqua's post [0] about writing a "Hello, World" in a single line of pure JavaScript inspired me to beat that record. I had already written a game using JavaScript, HTML, and CSS, and here it is now with a grand total of zero lines of code.
After reading theaqua's post, I couldn't sleep. I was agonized by insomnia, so I gathered myself and sat down to re-write the game. Mindful that I had to use exactly zero lines of JavaScript, I was very scared. Writing a program in 1000 lines or more is no problem. But writing zero lines of code ... that's insane. It turns your brain inside out. It changes the way you look at the web. You realize that, before, you didn't do things right.
For those of you who don't like to wait, here's a demo [1].
It's not a fake. It's a full game. Details after the cut.
...
I've been programming for a long time. And it was for just that reason that I believed that I could manage a complex task like taking a game that was originally written using JS and re-writing it with zero lines of code.
Before this project I looked down on HTML programmers†. But now I realize that they'll soon rule the world. You'll remember how there was a time when JS programmers weren't taken seriously. Do you remember those dark ages? But now take a look ... JavaScript is not just a trend. It's everywhere. In the browser, on the server, running on microcontrollers and mobile OSes. You can write operating systems in it, and games. ... And now, HTML programming is quietly creeping up on it.
One of these days writing zero lines of JS will be the norm. JS will fall out of fashion in the same way Flash did. Why write JavaScript if it's slower than an HTML program written by an HTML programmer with the aid of CSS?
Repository: https://github.com/i0z/nojsgame
-----
† — The comment thread is dominated by responses to this one: "'HTML programmer'—are you serious? :)"
To the point I want to learn Russian!
https://developer.mozilla.org/en-US/demos/devderby/2012/july
One of them is similar in concept to the space game linked here:
https://developer.mozilla.org/en-US/demos/detail/onspacestar...
[1] Edit: "Games" in scare quotes because the lose state doesn't (can't) persist in a way that requires player action.
Collision detection however fails on Google Chrome 31 when the mouse pointer is not moving.
Edit: Managed to make it the whole way through by leaving the ship in the bottom left. And then when the bonuses kept flying by uncontested because the game was "over", I was able to click on them after a few tries. The issue must have been that the cursor wasn't where I thought it was. Still very cool!
This is exactly what I would expect at a site that calls itself hacker news.
If people in the history of computing had stayed conventional and avoided doing something the horrible way, demoscene probably wouldn't been born at all. Breaking the boundaries and pushing to the limits was the point. Of course the young programmers of 1980's could have just waited doing nothing for 1990's to come with more powerful personal computers :)
No-one is seriously suggesting we write CSS-only games. You're rather missing the point.
It's one thing to write something that uses 30 lines of JS code only, than to create this and say "Look Ma, no JS!!"
Nevertheless, demos like this are pretty cool.
We're hackers. We're supposed to like things such as obfuscated c competitions and 5k demos!
People going against perceived wisdom and doing the wrong things with the wrong tools is a great way to learn and innovate, I know CSS very well and I am fairly sure I wouldnt have been able to come up with this, it may not be the next big game engine but there definetely scope for very practical new techniques and insights from abusing tools in this way
I suspect the community feels the same. There's always something beneficial that comes out of these for me. Whether it's seeing how *not to do something or picking up a little piece of code that can be repurposed somewhere else.
Hacking things to make them do something they were not designed to do is the life and blood of all things computers. It's just so damn fun.
If you lose that sense of playfulness with tech you might as well go work in some other field, because tech is about using things in ways they were never designed to be used... because it's fun first, and later because your under a weird constraint and you have this corpus of seemingly useless (at the time of acquisition) knowledge to draw on.
Things like this only promote a deeper understanding of what can be done in pure CSS. Yes he took it too far, but that's the point.
Now that I understand the author's intent, it's furthermore impossible for me to go along with a narrative that every experiment has equal or potential to lead to some mind-rattling insight. If anything, the posts about how someday shaders might build entire games etc just demonstrate how, behind the wall of basic comprehension of how GLSL's inner workings and things like Chomsky grammar concepts create fundamental limitations, the barriers one will encounter are both insurmountable and undetectable. See http://stackoverflow.com/questions/1732348/regex-match-open-...
CSS itself has annoying limits that can be summed up with the existence of tools like LESS and Stylus that add expressions to generated CSS, giving us an infinitely more capable styling system, albeit still suffering from annoying limitations that keep me sour to many CSS uses. Quite simply, everything in CSS transitions has an API so far from how animation is dealt with programmatically that I find only the most basic utilizations to -ever- be appropriate. This doesn't even mention the fact of shims, fallbacks, and the JS that deals with them. The idea that we're "pushing limits", much less making progress with examples like this is not one I'm buying into.
"I wrote X in HTML5" yes can get tired, but this is a specific use of the technology that's interesting to web developers.
http://www.ryan-kahn.com/static/onlyCSS/
I ended up building a generator for the CSS+HTML and at the time I had a PHP script (2+ years ago, I would use Node now) that could allow me to pick the number of lanes, the difficulty etc. Now it's just a single snapshot. I built it in about a week. There is a new bug apparently where the cursor is not changing as expected in chrome.
EDIT: yep, definitely proxy, seems all the stuff from http://nojsgame.majorov.su/ is blocked.
Like, at all. Sorry. If you enable it and reload this page you'll be good to go. Need to know how? Go here." Okay, that's funny. When Javascript is on: Ah, Nice little game. Interested how it needs a .js file with just a comment. Can we improve this to remove it?
Edit: oh, so maybe the overall website need JS, not the game(?).
It says 0 lines of JS... Technically there is one line of JS!
technically
Little disappointed on the content quality of HN nowadays , rather than seeing stories of inspiring people solving some real problem and doing some real shit. All i see now is anything goes up at #1.
Btw, for someone complaining about losing time, you seem to have a lot of it. ;)
Several years ago, this game would be very resource heavy and use lots of JS, but as more common uses of JS are merged into CSS, JS is less and less relied on.
Doing something to make a statement and doing something useful are two different things.
I have two questions for you though i agree with you on couple of points:
- Are you ever going to use this in near future(say 1/2 years)?
- Will you ever be able to maintain or write something of this sort when complexity arises? CSS is a domain specific declarative language. A lot of cool things could be done with it.But for game development? Hell No!
You might find some sense in these arguments, i hope!