Breakout in 30 lines of JavaScript
jsfiddle.net
jsfiddle.net
All these Thing in 30 lines posts would make an excellent collection for people to type in, debug, modify, debug, expand, debug, etc.
Someone could make an RPi friendly page and collate these. Maybe include some gentle competitive edge - code golfing or neatest added feature or somesuch.
I've been programming for 15 years now and that Excel-like thinger taught me a thing or two, and it didn't take tearing it apart to figure out how it worked.
This game, and the Snake one from yesterday, didn't even go so far as to generate the DOM objects in a loop. That was another big part of how the Excel thinger worked, it wouldn't have been nearly as succinct without it.
Now, I can see using the HTML if there were significant text data you wanted to include, e.g. text-adventure room descriptions, but this just seems like they're focusing on the "30 lines" part of the challenge and not the "super-dynamic" part.
For example, here's the 552 character Ruby code to print the lyrics of a song.
i=44
s="We; n7trangMsL8loT63Ke rules5s8d8I
AJull commit4nt'sChatFKink: of6CHldn'tRetKisJrom<ny@Ruy-/A= if?<sk 42DS'tLE 4?;Lo8bli=L7ee..
O,R1)O,R001)/-.."
"
I justCannaLE?2Gotta >u=Msta=.|
Ng1Nlet? downNrun<rH=5desMt?N>cryNsayRoodbyeNtE< lie5hurt?|
We'T3n each@Jor s8lSg6r hear9<ch: but6;Lo7hyL7BInsideCe both3Cha9Ro: S
We3KeRa45we;QplB|1)O)NgiT, nPgiT
(G|iT? up| howFJeel:
| know|me|<= |
YH|8s|o |t's been|ing|'re| a|nd|make? | yH| othM|A|ay it
| w|D|ell| I'm|G|ou|I| f|Lh| t|er|
NP|
(Ooh|eTrQ|RSna | g|on|ve".scan(/[^|]+/){s.gsub!((i+=1).chr,$&)}
puts s+ CSS as well
It's still impressive to see. Though I did cheat; I set my lives to 99999 then let the game complete itself like a screen saver
http://jsfiddle.net/icodeforlove/Fq8F4/310/
it always gets stuck for me though :(
- This stackoverflow answer has a good back story on this: (TLDR, it's not standard... yet) http://stackoverflow.com/a/3434388/1339100
but it is in this HTML 5.1 draft: http://www.w3.org/html/wg/drafts/html/master/browsers.html#n...
- It's slower than document.getElementById, somehow: http://jsperf.com/implicit-dom-element-variables
Most rigid body simulations use discrete collision detection with fixed time steps, so it only checks for collisions at specific points in time. This is fast, but can cause issues where fast moving objects passing through thin objects (such as a bullet through a pane of glass). The alternative is called Continuous Collision Detection in which you calculate exactly when two objects will collide (or have collided) and can then simulate up to that point (or roll back to that point) and deal with the collision. One naive technique to do this is after integrating your simulation forwards, you use the volume each object swept out in that time step as its collision geometry instead of just the shape of the object at its new position. This solution has issues; it doesn't tell you when two objects collided and it can give false positives, but it works ok for rigid body simulations.
Some recent papers on the subject with more exact (and complicated) techniques:
http://www.cs.columbia.edu/cg/ACM/
http://www.cs.ubc.ca/~rbridson/docs/brochu-siggraph2012-ccd....
Edit: To put it more simply, as soon as the ball leaves the paddle, isn't it immediately possible to exactly compute its complete path up to the next contact with the paddle "axis"? Do any Breakout games do this?
Breakout doesn't even pretend to use real-world physics: The ball bounces vertically off of the bricks and ceiling and horizontally off of the walls. After hitting one brick, it ignores and passes through all others until it hits either the ceiling or the paddle; together, these make the ball much less chaotic, which enables faster speeds and longer runs.
But the title doesn't mention that there are also 57 lines of HTML and 121 lines of CSS (with some line breaks).
Still amazing though. =)
Pretty cool btw.