Topic: 20 Liners - July 08 - Your favorite video game (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=30391" title="Pages that link to Topic: 20 Liners - July 08 - Your favorite video game (Page 1 of 1)" rel="nofollow" >Topic: 20 Liners - July 08 - Your favorite video game <span class="small">(Page 1 of 1)</span>\

 
poi
Paranoid (IV) Inmate

From: Norway
Insane since: Jun 2002

posted posted 07-05-2008 22:32

This month, the theme is : Your favorite video game.

We all have a soft spot for some video games we played years ago. Well, the time has come to give them a JavaScript treatment. Make a tribute ( title screen, cut scene, visual gimmicks, ... ) or a even a playable version in roughly 20 lines of JavaScript.


As usual, the main rule is to make your script in 20 lines of (effective) code. Literal object declarations count as one line ( a variable assignment ) except for the body of the methods declared there. Comas shouldn't be used to execute several instructions on the same line, yaddia yadda.


This month, we'll try something different and see if the idea flies : The inmates are free to use any of the following JavaScript frameworks/libraries if they want : Prototype/Scriptaculous, jQuery, Moo, Processing.js.


Game on!

Ox0D06
Bipolar (III) Inmate

From: Germany
Insane since: Apr 2008

posted posted 07-05-2008 22:41

That sounds like fun! Should there be any rules or limitations on chaining? And just to clear things up: Does

code:
(function() {setTimeout(arguments.callee, 10)})()


count as 2 lines of code?

First thing I'll have to do is to figure out, which game actually is my favourite There are many to chose from, I think I'll stick to a "classic" atari game or something similar.

(Edited by Ox0D06 on 07-05-2008 22:41)

poi
Paranoid (IV) Inmate

From: Norway
Insane since: Jun 2002

posted posted 07-05-2008 23:17

Regarding chaining : I think I went it a little far last month with Hypno trip down the fractal rug, but on the other hand you pushed the it even further with your entry in the 20 Liners - April 08 - Split Screen and no one complained. We should simply try yo remain reasonable. Anyhow I think that chaining 100 methods would be slow enough to prevent any blatant abuse of this approach.


Yes, your code snippet counts as 2 lines : 1 for the setTimeout( ... ) and 1 to execute the anonymous function.


It doesn't have to be your utmost favorite game : just one you liked or that tingled your spider sense.



(Edited by poi on 07-05-2008 23:22)

Ox0D06
Bipolar (III) Inmate

From: Germany
Insane since: Apr 2008

posted posted 07-05-2008 23:33
quote:
...and no one complained


well, you can't say there was that much participation either :P

I just hope I won't run short on time this month. But I do have some good ideas

poi
Paranoid (IV) Inmate

From: Norway
Insane since: Jun 2002

posted posted 07-06-2008 13:07

People, make sure to check the KLOV® (Killer List of Videogames), Lemon64, Atari Age, virtualNES and MobyGames for inspiration and screenshots of mythical games on retro platforms.

And here's a bunch of video game title I can think of on top of my head as good candidates for 20 lines remake : Zaxxon, Dig Dug, Pac Man, Donkey Kong, Outrun, Space Harrier, Boulder Dash ( done by MaGnA not long ago ), Arkanoid, Excite Bike, Q*Bert, Pole position, Gauntlet, Frogger, Berzek, Robotron 2084, Defender, Space Invaders, Tetris, Joust, Tempest, Asteroid, Skweek, Sokoban, Super Sprint, 1942, Trailblazer, The 5th Axe, ...





(Edited by poi on 07-06-2008 13:38)

smoff
Obsessive-Compulsive (I) Inmate

From: Finland
Insane since: Jul 2008

posted posted 07-09-2008 12:03

(Hi everyone)
I found this community a month ago but I didn't have any time for making a 20 liner. But now I'll try to make something for this month's challenge (although I've several projects having deadline in this month).

poi
Paranoid (IV) Inmate

From: Norway
Insane since: Jun 2002

posted posted 07-10-2008 22:42

Welcome to the Asylum.

Looking forward to see something from you.

esskay
Nervous Wreck (II) Inmate

From:
Insane since: Jan 2005

posted posted 07-13-2008 21:17

Hi - it's been a while since I've popped in here. I've been lurking and peeking in from time to time though. I -just- missed last month's contest, but this month I'd like to put something together as it's one of my favorite topics.

I'm not an very active member but I'll just put in my 2 cents on the external framework stuff: I don't like it one bit. I am committed to doing 20-line contests without including external code. I feel like it defeats the purist essence and challenge of a contest such as this if you invite importing a multi-thousand line library that does half the hard work for you. Even so, poi I really enjoyed the effect of your recent roto-zoom piece.

Regards,
- SK

poi
Paranoid (IV) Inmate

From: Norway
Insane since: Jun 2002

posted posted 07-13-2008 21:58

esskay: I understand and, being a purist myself, share some of your arguments about allowing JS frameworks. However I'm ready to compromise if this can get some new blood in the 20 liners arena, and eventually transmutate it into JavaScript godly juice. There has been few entries recently, and I am curious as to whether the barrier to entry is too high or not. Obviously an entry using a JS framework would have to be pretty bad ass to outdo a decent "pure" 20 liner. Also most frameworks are designed for generic DOM/css manipulations. I doubt they lead to the most compact code.

Thanks for the kind words.

esskay
Nervous Wreck (II) Inmate

From:
Insane since: Jan 2005

posted posted 07-18-2008 06:13

Okay, I've got a start on something - I hope it works in 20 lines... it's a little complicated. Is there an "official" document anywhere yet with guidelines on what should or should not be considered a "line"?

* function declarations?
* variable initialization?
* if (); else if (); else if (); else (); ?
* onEventType="handler_function()" in the HTML?

Regards,
SK

poi
Paranoid (IV) Inmate

From: Norway
Insane since: Jun 2002

posted posted 07-18-2008 09:45

Don't worry no one will bite your head off if you make a 25 liner. Except maybe zombies.

We only count the lines of "effective" code. This eliminate function declarations and element.onFoo. What count as one "effective" line is basically anything else that constitue one JavaScript expression ( it can contain several statements of course ). Tho get an idea:

code:
// WARNING: nonsensical example approaching

            // declare a couple of variables
/* 01 */    var baz = "Fy",
/*  | */        foo =
/*  | */        {
/*  | */            name:"Bob",
/*  | */            kind:"cat",
/*  | */            yield:function( msg )
/*  . */            // the expressions of this function count
/*    */            {
/* 02 */                var msg = msg||"I'm "+ name +" the "+ kind +".";
/* 03 */                alert( "Meow! "+ msg );
/*    */            }
/*  . */            // resume to line 01
/*  | */            isAlive:Math.random()>.5;
/*  | */        },
/*  | */        bar = "it's candy";
            
/*    */    document.body.onclick = function()
/*    */    {
/* 04 */        val= prompt( 'enter a number' );
/* 04 */        for( i=0; i<10; i++ )
/*    */        {
/* 05 */            alert( stupidFunction( val, i ) );
/*    */        }
/*    */    }

            // like regular function, anonymous function declaration do not count
/*    */    (function()
/*    */    {
/* 06 */        setTimeout( arguments.callee, 10 );
/*    */    })
/* 07 */    (); // calling it, however counts as an expression
            
/*    */    function stupidFunction( a, b )
/*    */    {
/* 08 */        return a>b?a:b; // I said it was a stupid function
/*    */    }

But again, JavaScript's syntax is loose and we're doing this for fun so don't worry. Have fun.



(Edited by poi on 07-18-2008 10:09)

esskay
Nervous Wreck (II) Inmate

From:
Insane since: Jan 2005

posted posted 07-21-2008 00:12

Okay, the game I chose is not my "favorite" per se, but I remember it was fun when I was a kid. Use the direction arrows to move Peter Pepper within the confines of the level map.

I'm hesitant to spend any more time on this because it's too unclear to me on what is a "line" of code. I did a fair amount of work to work out an approach to condensing multiple code operations into single, clever lines. If this is going to be unrolled however it might end up being 50 lines just as it is. If someone could review the line counting, I can decide whether to even attempt to add the "baddies" and ponder the remaining interactive bits:

http://www.keenkelly.com/demo/games/burgertime/

Developed on FF2 and tested in IE7.

poi
Paranoid (IV) Inmate

From: Norway
Insane since: Jun 2002

posted posted 07-21-2008 01:42

Sweet!

Really don't worry about the line count. It's ALWAYS possible to gain something somewhere.

FWIW I counted 22 lines in your script:

code:
// pseudo code

/* 01 */ variables initialization

/* 02 */ onkeydown if
/* 03 */ onkeydown if statement

/* 04 */ onkeyup if
/* 05 */ onkeyup if statement

/* 06 */ init_level if#1
/* 07 */ init_level if#1 statement
/* 08 */ init_level if#2
/* 09 */ init_level if#2 statement
/* 10 */ init_level setTimeout

/* 11 */ start_level if#1
/* 12 */ start_level if#1 statement
/* 13 */ start_level if#2
/* 14 */ start_level if#2 statment

/* 15 */ animate if
/* 16 */ animate if statement
/* 17 */ animate else
/* 18 */ animate else statement

/* 19 */ move statement

/* 20 */ test statement

/* 21 */ walk statement

/* 22 */ update statement

But many/most of the if, statement and if, statement, else, statement can be combined in a single line.

For instance the keydown/keyup handling can be a one liner. See how I did in Castle Wolfenstein. You also be lazy as I've been about the new level "screen" and use an alert( 'Yay for level #'+ level ) which allow you to use a single setInterval( updateGame, delay ); instead of juggling with a setTimeout and a setInterval as you do now.


I could provide the skeleton of a game if you want.

HTH

esskay
Nervous Wreck (II) Inmate

From:
Insane since: Jan 2005

posted posted 07-21-2008 02:46

I can't believe you got that raycaster in 20 lines - incredible work!

Suho1004
Maniac (V) Mad Librarian

From: Seoul, Korea
Insane since: Apr 2002

posted posted 07-21-2008 03:13

Nice beginnings for BurgerTime, esskay! I have no prowess in JS at all, but I do like to drop in here and enjoy the sights from time to time.




___________________________
Suho: www.liminality.org | Cell 270 | Sig Rotator | the Fellowship of Sup

poi
Paranoid (IV) Inmate

From: Norway
Insane since: Jun 2002

posted posted 07-27-2008 18:01

*bump*

I'm going to the Assembly from July 31st to August 3rd, and don't know if or how reliably I'll have access to the net so you guys might very well have 3 extra days to submit and polish your entries

Keep on coding.

jseidelin
Obsessive-Compulsive (I) Inmate

From: blog.nihilogic.dk
Insane since: Jul 2008

posted posted 07-27-2008 20:46

Have fun. I'm counting on getting mine done before then but extra time is always nice.

Also, hi guys.

poi
Paranoid (IV) Inmate

From: Norway
Insane since: Jun 2002

posted posted 07-28-2008 00:27

Yay! Cool to have you on board.

For those who missed an episode. Jacob Seidelin got quite a few headlines in the past months, including here, for his Super Mario in 14 Kb then 8 Kb ( thanks to some innovative JavaScript compression based on PNG + ImageData ), Super Mario Kart engine, Wolfenstein 3D, RadioHead's point cloud renderer, ...


Side note: Storing a level and its collision map using big images or tables can save quite a few lines and unify the code for the collision detection ( against the level and the entities ).



(Edited by poi on 07-28-2008 01:49)

jseidelin
Obsessive-Compulsive (I) Inmate

From: blog.nihilogic.dk
Insane since: Jul 2008

posted posted 07-28-2008 20:31

Here's what I've got so far. Surprise, it's another go at Super Mario!
It's not quite a remake, though. The game mechanics are a bit different but they should be easy to get.

I've still got a bit of polishing and simplifying to do. Also, as it is now, it only runs smoothly in IE and FF3, at least on my (rather old) box. Haven't tested on Safari yet. FF2 is dead slow, Opera is pretty slow as well.

http://www.nihilogic.dk/labs/20_lines_javascript/july08_super_mario/

kwei
Obsessive-Compulsive (I) Inmate

From: Germany
Insane since: Jul 2008

posted posted 07-28-2008 21:39

Crap, wanted to submit my mario version first to prove that I didn't copy... as soon as I read about jseidelin's plans on twitter, I though oh-oh

http://weibell.de/javascript/20lines/smb/
(not finished yet, currently 11 lines)

but great 20liners so far, keep up the good work!

kwei (formerly Ox0D06, but forgot password and didn't like that nick anyway)

_______________
http://weibell.de/

(Edited by kwei on 07-28-2008 21:42)

poi
Paranoid (IV) Inmate

From: Norway
Insane since: Jun 2002

posted posted 07-28-2008 21:52

MOAR!

poi
Paranoid (IV) Inmate

From: Norway
Insane since: Jun 2002

posted posted 07-28-2008 22:15

smoff + esskay: any progress guys ? Can I, or anyone else, help in any way ?

jseidelin
Nervous Wreck (II) Inmate

From: blog.nihilogic.dk
Insane since: Jul 2008

posted posted 07-28-2008 22:56

kwei: Ha, don't worry, there's always room for more JS Mario! Very nice.


Also, forgot to mention that the tiles and sprites are of course generated at runtime with good old div elements. If possible, I'll try to fix what's causing the bad performance in some browsers by the deadline.

jseidelin
Nervous Wreck (II) Inmate

From: blog.nihilogic.dk
Insane since: Jul 2008

posted posted 07-29-2008 15:43

Ok, I think I'll let mine rest for now except for maybe some minor tweaking. FF2 is just awfully slow with this many div's, but that's also why I ended up with a dual canvas/div approach for the old 14KB mario. IE wins for once although it looks like FF3, Opera and Safari are all playable too.

esskay
Nervous Wreck (II) Inmate

From:
Insane since: Jan 2005

posted posted 07-30-2008 05:59

Man, I went to the arcade last weekend and actually found a working BurgerTime game... I didn't realize that the character actually turns left & right and has a multi-frame walking animation sequence that pauses when you stop moving. I don't think I have it in me to squeeze any more into it for now. poi, I did take a look at your wolf 3D code and noted the difference in the keypress handler, but I wasn't really sure what you meant by some of your other comments in the code assessment. I know I threw away a lot of code to the introduction/level setup, but I was really hoping for some arcade action that would be true to the experience.

Regards,
- SK

dspeyer
Neurotic (0) Inmate
Newly admitted

From:
Insane since: Jul 2008

posted posted 07-30-2008 07:20

Here's Rodent's Revenge in 20 lines of Javascript: http://dspeyer.homelinux.org/rr/

At least, I think it's 20 lines. All depends how you count, of course.

esskay
Nervous Wreck (II) Inmate

From:
Insane since: Jan 2005

posted posted 07-31-2008 05:06

Rodent's Revenge - Interesting - hard to play!

- SK

Blaise
Paranoid (IV) Inmate

From: London
Insane since: Jun 2003

posted posted 07-31-2008 11:09

I like how when you lose you can still try and run from the skitzo cat!

Suho1004
Maniac (V) Mad Librarian

From: Seoul, Korea
Insane since: Apr 2002

posted posted 07-31-2008 11:27

Rodent's Revenge strikes me as a bit buggy...

In my first game the cat never appeared (but I still lost). In my second game, I turned into a block and the cat disappeared (and I lost again). I am a bit confused.


___________________________
Suho: www.liminality.org | Cell 270 | Sig Rotator | the Fellowship of Sup

smoff
Nervous Wreck (II) Inmate

From: Finland
Insane since: Jul 2008

posted posted 07-31-2008 18:53
quote:

poi said:

smoff + esskay: any progress guys ? Can I, or anyone else, help in any way ?


I was working on my entry but as said I had two other compos on my worklist :/ (one lame gamedev compo and some vector thingy for assembly exec. gfx). I hope I've more time on next month.

EDIT Ok, I'll try to make something very fast (eventhough I won't have enough time)
PS. I made some point-in-triangle math, is it allowed to replace this

code:
function InTri (xp, yp, x1, y1, x2, y2, x3, y3) {

	var divisor = (x3-x2)*(y2-y1)-(x2-x1)*(y3-y2);

	if (divisor==0)   //Divided by 0, for triangles we can just:
		return InTri (xp, yp, x2, y2, x3, y3, x1, y1);

	var s=((yp-y1)*(x3-x2)-(xp-x1)*(y3-y2))/divisor;

	var t=(xp-x1-s*(x2-x1))/(x3-x2);

	return ((0<=t)&&(t<=s)&&(s<=1));

}



with something like this

code:
function InTri (xp, yp, x1, y1, x2, y2, x3, y3) {

	var divisor = (x3-x2)*(y2-y1)-(x2-x1)*(y3-y2);

	if (divisor==0)   //Divided by 0, for triangles we can just:
		return InTri (xp, yp, x2, y2, x3, y3, x1, y1);

	//Dirty 3 lines to one line "optimizing"
	return ((0<=(xp-x1-s*(x2-x1))/(x3-x2))&&(t=(  ... lots of stuff in 1 return ..);

}



(Edited by smoff on 07-31-2008 19:48)

(Edited by smoff on 07-31-2008 21:19)

poi
Paranoid (IV) Inmate

From: Norway
Insane since: Jun 2002

posted posted 08-01-2008 00:45

I'll call it a night. I slept only 2h last night I'm flying back to Oslo on Sunday evening and fly to France at dawn on Monday, so let's say you guys have until Sunday 8pm CET

smoff: Yes it is allowed. At least in my book. Are you at ASM ?
Notice that you could even make this a one liner by using a ternary operator: condition?trueStatement:falseStatment .



(Edited by poi on 08-01-2008 00:54)

smoff
Nervous Wreck (II) Inmate

From: Finland
Insane since: Jul 2008

posted posted 08-01-2008 02:04
quote:

poi said:
smoff: Yes it is allowed. At least in my book. Are you at ASM ?
Notice that you could even make this a one liner by using a ternary operator: condition?trueStatement:falseStatment .

(Edited by poi on 08-01-2008 00:54)


Yes I'm at asm and.. well.. Yes I could've done it in one line.

jseidelin
Nervous Wreck (II) Inmate

From: blog.nihilogic.dk
Insane since: Jul 2008

posted posted 08-01-2008 08:35
quote:

poi said:

I'll call it a night. I slept only 2h last night I'm flying back to Oslo on Sunday evening and fly to France at dawn on Monday, so let's say you guys have until Sunday 8pm CET



Cool. Coincidentally, we're also flying down to Paris Monday morning

poi
Paranoid (IV) Inmate

From: Norway
Insane since: Jun 2002

posted posted 08-01-2008 11:12

smoff: I'm sitting, next to Gasman aka Shingebis, in front of the 315 door sign in the oldschool area. I've got a blue cap with nick in case of sun light or bad hair attack.

jseidelin: I only have a 1h connection at Paris CDG 2D-F :\

smoff
Nervous Wreck (II) Inmate

From: Finland
Insane since: Jul 2008

posted posted 08-01-2008 12:47

poi I'll be there again before the extreme music compo. Drop me mail (check the profile page) and let's have a meeting during asm.

(Edited by smoff on 08-01-2008 12:55)

poi
Paranoid (IV) Inmate

From: Norway
Insane since: Jun 2002

posted posted 08-06-2008 15:16

First of all sorry the delay and thanks to all participants.

I'd like to give a honorable mention to esskay for his Burger Time. Not complete and simple game logic but nicely commented source code.

3rd place to dspeyer for his Rodent's Revenge. featuring several "levels" and a relatively clean and compact code.

2nd place to Kwei with Super Mario Bros. Not complete either but tricky game logic.

1st place go to jseidelin for his Super Mario Tribute featuring the most complete game logic of the gang, several levels and the most polished character display.

Kudos again to every one.

esskay
Bipolar (III) Inmate

From:
Insane since: Jan 2005

posted posted 08-07-2008 22:22

w00t - nice work y'all. Looking forward to the next challenge.

- SK

kaht
Obsessive-Compulsive (I) Inmate

From: Collinsville, IL
Insane since: Feb 2005

posted posted 08-22-2008 16:27

jseidelin, very nice Mario remake.

However, I saw this quote on the page: "You cannot die. In this game, the only winner is YOU!" and decided to make death a reality (not by running into the goombas, though). So, I made the change and made a few new challenging levels. I've personally beat all the stages just to make sure it was possible. Here's the altered script file, the code change was on "line" 14: (by the way, I love how easy it is to add new levels)

code:
/*
 * 20 Lines JavaScript - July : Super Mario Tribute
 * Copyright (c) 2008 Jacob Seidelin, cupboy@gmail.com, http://blog.nihilogic.dk/
 *
 * A Super Mario inspired game in 20 lines of JavaScript.
 * 
 */
      // data and variables used in the game
/* 01 */    var data = {
         pal : [
            // 0  1      2       3         4         5         6         7         8        9         10         11         12      13         14
            "", "000", "FFF", "E75A10", "F7D6B5", "FFA542", "C0FF2B", "00AD00", "F7D6B5", "39BDFF", "FFA044", "F83800", "FF3900", "AD7B00", "F0D0B0"
         ],
         sprites : [
            [[3,1,0,4],"310703b0303010d31b0032c1034d203a1033a60339a0138c03190091f1031f6081ee0019f5011f5010a1012b1014c3017d0118a011b5301b4003b630".split()],
            [[4,1,3,0],s1="200f02010d10ff01f10d1220012d001d2001dd0015413154301a5131881218c11244122534029413287002781127b11"],
            [[5,1,3,0],s1],
            [[0,1,6,7],"1200f230cf3601f3d00f"],
            [[0,1,6,7],"1d00f2903f3008f391103931039510397103991039b1039d1039f10"],
            [[0,1,6,7],"100fe211ec3124b3c23b2132a2d31a12fd0"],
            [[0,1,6,7],"100fe10fd0201ec302ab3b2303b4103b6103b8103ba103bc10"],
            [[3,1,0,14],"300f0103f0107f010bf010ff0171011f101134021b40213c021bc02178021f802"],
            [[1,3,0,8],"111dd0220002d000d2000dd00"],
            [[3,0,1,14],"310d0321b033290343703010d3120b32309334072f00e2e10c2d20a2c30820fe021ec022da023c80"],
            [[0,1,6,7],s2="2c93629c231d8201c9001ba0119c1018d0119f00"],
            [[0,1,6,7],s3="207f8224c3223802515116030151001a100132101230211600107001b2011c4001d3001e4001f5023561034700395003a600"],
            [[0,1,6,7],s4="20a322390020c631080111a0012900138001490215c0016b0017c0216f00"],
            [[0,1,2,9],s2],
            [[0,1,2,9],s3],
            [[0,1,2,9],s4],
            [[0,1,2,9],"2b0412d2211a0001b1001c2011d4303d0003e1003f200"],
            [[0,1,2,9],"200f5116501372023620186702a6301a730105001750030220362303235039340344103a4203110038100390003e200"],
            [[0,1,2,9],"200452511215000161001720115410135101161010500"],
            [[0,1,7,0],s5="10f0011e0012d0013c0014b0015a00169001780018700196001a5001b4001c3001d2001e1001f00021fe022ed023dc024cb025ba026a902798028870297602a6502b5402c4302d3202e2102f100"],
            [[0,1,7,0],s5,true],
            [[7,1,7,0],"194131c1231d005"],
            [[0,1,7,0],"22eb110f1012e2015d501be201ef10"],
            [[0,10,2,11],"1711d1623b15359145752650539505274003840027b0038b00"],
            [[0,1,3,4],s6="26030251502427023390224b0215d1207f221ad034503357113b5033971135a5034b7337f00134101b410155021a5021663013d1114e1116f001cc101ad4119e41"],
            [[0,1,3,4],s6,true],
            [[0,12,13,5],s7="37230343813d400355612450023302242202530025410292012a4002953015040141802475023890229b123e2022f302ae202af3016701198001693015a5214b2219b2232a123ca12"],
            [[0,12,13,5],s8="30a2131c002d3223d02238330354812d3223d5103666125600244022532026400265102a3012b5002a6402a64016140152802d700228a22190014b3418b231bb2226b001894129920178001b8002eb122f90123c0224d0022d0121e01"],
            [[0,12,13,5],s9="38330354813e5003666125600244022532026400265102a3012b5002a630161401528023871259713d9212da003191233a0015b6222e2114c2213d001ac222dc022eb03178121990019a20"],
            [[0,12,13,5],s7,true],
            [[0,12,13,5],s8,true],
            [[0,12,13,5],s9,true],
            [[7,0,0,0],"00000"],
            [[0,1,3,4],"268302399021ad020bf133d9034e7011f401af4032bb013a2016b301aa20"],
            [[0,0,0,0],"0000"]
            ],
         spriteHTML : [],
         lvl : [
            [
                 "0000000000o000000000000000000000"
               + "0000000o002000000000000000000000"
               + "0000o0020000000efg00000000000000"
               + "000020000000000hij00000000000000"
               + "00000000000000000000000000000000"
               + "000888888888800000000a0000000000"
               + "00000000000000000o0000a000000000"
               + "00000000000000000200000a00000000"
               + "0000000000000000000000000effg000"
               + "00000000o0000000000000000hiij000"
               + "00000000200000000000000000000000"
               + "000000000000000000000000000a0000"
               + "00p00000000000000670000000a00000"
               + "0aaaa00000000000045000000a000000"
               + "00000a00a00000008888000000000000"
               + "a0000azza000000000000a0000000000"
               + "a000006700000000000000a00000n000"
               + "a00n0045000000000000000a000kxl00"
               + "a0kml04500bcd00p000bcccd00kxxml0"
               + "11111111111111111111111111111111",
               5, 2, 17.5, 11
            ],
            [
                 "000000000o000000000000000000o000"
               + "00000000020000000000000000002000"
               + "000006700000000000efg00000000000"
               + "000004500000000000hij0000000p000"
               + "88888888800000000000000000088880"
               + "00000000000000000000000000000000"
               + "000efg00000000o00000000000a00000"
               + "000hij0000000020000000000000000a"
               + "00000000000000000000000000000000"
               + "00000000o00000000000000000a00000"
               + "00000000200000a0000000000000000a"
               + "00000000000000000zz0000000000000"
               + "00o00000000000000670000000a00000"
               + "00200000a0000000045000000000000a"
               + "00000000000000000450000000000000"
               + "00000000000000000450000000a00000"
               + "00a00000000000000450000000000000"
               + "00000000000000000450000000000000"
               + "00bcd00p000bccd0045000000p000000"
               + "11111111111111111111111111111111",
               5, 3, 5.5, 1
            ],
            [
                 "00000000000000000000000000000000"
               + "0ooooo00000000000000000000000000"
               + "0222220efg00a000000000000000a00a"
               + "0000000hij00a000000000000000azza"
               + "00p000000000a000aa0000aa00000670"
               + "088888000000a000000oo00000000450"
               + "0o0000000000a000000220000efg0450"
               + "020000000a00a000000000000hij0450"
               + "000p00000000a000000p000000000450"
               + "08888800000000000088880000000450"
               + "0o00000000effg000000000000000450"
               + "020000000ahiij000000000000000450"
               + "00p00000000000000000000000000450"
               + "88888800000000000000000000000450"
               + "00000a00a00000000000000000000450"
               + "00000azza00000000000000000000450"
               + "000000670a000000000n000000000450"
               + "000n004500a0000000kxl0000n000450"
               + "00kml045000abcd00kxmxl00kml00450"
               + "11111111111111111111111111111111",
               9, 4, 6.5, 15
            ],
            [
                 "00000000000000000000000000000000"
               + "0000efg0000000000000000000000000"
               + "0000hij0000000000000000000000000"
               + "000000000000000effg0000000000000"
               + "000000000000000hiij0000000000000"
               + "00000000000000000000000000000000"
               + "00000000000000000000000000000000"
               + "00000000000000000000000000000000"
               + "0zz00000000000000000000000000000"
               + "06700000000000000000000000000670"
               + "04500000000000000000000000000450"
               + "88888888888888800888888888888888"
               + "00000000000000000000000000000000"
               + "000000000000000oo000000000000000"
               + "oo00000o0000088228800000o0o0o000"
               + "220000a2800000000000000828282800"
               + "00000aa0000000000000000000n00000"
               + "0000aaa000000000000000000kxl0000"
               + "000aaaa000bccdp00bccdp00kmxxl000"
               + "11111111111111111111111111111111",
               8, 2, 29.5, 8
            ],
            [
                 "00000000000000000000000000000000"
               + "00000000000000000000000000000000"
               + "00000000000000000000000000000000"
               + "00000000000000000000000000000000"
               + "000efg00000000000000000000000000"
               + "000hij00000000000000000000000000"
               + "00000000000000000000000000000000"
               + "00000000000000000000000000000000"
               + "0zz0000000000000efg0000000000000"
               + "0670000000000000hij000000efffg00"
               + "0450000000000000000o00000hiiij00"
               + "88880000000000000002000000000000"
               + "00000000000000000000000000000000"
               + "00000000000000000000000000000000"
               + "000000000000000000o0o00000000000"
               + "00000000000000000828280000000000"
               + "00000000000000000000000000zz0000"
               + "000000000000000n0000000000670000"
               + "0000000000bccdkml0p00bcd00450000"
               + "11111111111111111111111111111111",
               3, 1, 1.5, 8
            ],
            [
                 "00000000000000000000000000000000"
               + "000o0000000000000000000000000000"
               + "00020000000effg00000000000000000"
               + "00000000000hiij00000000000000000"
               + "00000000000000000000000000000670"
               + "000a00000p00000000p0000000000450"
               + "00000000aaaaa0000aaaaa00efgaaaaa"
               + "00000000a0o0a0000a0o0a00hija0000"
               + "00000000a020a0000a020a00000a0zz0"
               + "a0000000a000a0efga000a00000a0670"
               + "00000000000000hij0000000000a0450"
               + "0000000000a00000000a0000000aaaa0"
               + "00000000000000000000000000000000"
               + "08888880000000p000000000000a000a"
               + "000000a00000o8888o00000000000000"
               + "a00oo0a000082aaaa280000000000a00"
               + "000220a0000000000000000000000000"
               + "000n00a0000000000000000000000000"
               + "00kml0a000000000bccd0000bcd00000"
               + "11111111111111111111111111111111",
               7, 3, 29.5, 3
            ],
            [
                 "0000000000aaaaaaaaaaaaaaaaaaaaaa"
               + "00aaaaaaa0000000000000000a000000"
               + "00a00000a0aaa0000effg0000a0a0000"
               + "00000000a000a0000hiij0000a0a0000"
               + "00800000a000a000000000000000a000"
               + "000000800080a000000000000080a000"
               + "000000000000a080000000000000a0p0"
               + "000000000000a000000000000000aaaa"
               + "0000000efg00a0000000000080000000"
               + "0800000hij00a0000000000000000000"
               + "000000000000a0000000000000000000"
               + "000000000000a00000efg0000000o000"
               + "000000000000a00000hij00000002000"
               + "000000800000a0000000000000000000"
               + "000000000000a0a00000000000000000"
               + "000000000000a0a00000000000000000"
               + "0o0000n00000a0a00000000000000ozz"
               + "67000kxl0000a0aaaaaaaaaaaaaaa267"
               + "4500kxxml000000bcd0000000n000045"
               + "11111111111111111111111111111111",
               2, 1, .5, 16
            ],
            [
                 "0450000ooo0ooo0ooo0ooo0000000000"
               + "06700002220222022202220000efg000"
               + "00000000000000000000000000hij000"
               + "00000000000000000000000000000000"
               + "88888888888888888888888888888800"
               + "00000000000000000000000000000000"
               + "000000effg0000000000000efg000000"
               + "000000hiij0000000000000hij000000"
               + "aaaa000aaaa000aaaa000aaaa000aaaa"
               + "000a000a00a000a00a000a00a000a000"
               + "000a000a00a000a00a000a00a000a000"
               + "000a000a00a000a00a000a00a000a0ef"
               + "000a000a00a000a00a000a00a000a0hi"
               + "000a067a00a067a00a067a00a067a000"
               + "000a045a00a045a00a045a00a045a000"
               + "fg0a0aaa00a0aaa00a0aaa00a0aaa000"
               + "ij0a000a00a000a00a000a00a000a000"
               + "000a000ag0a000a00a0zza00a000a000"
               + "000a067aj0a067a00a067a00a067a000"
               + "000a045a00a045a00a045a00a045a000",
               12, 0, 1.5, 1
            ],
            [
                 "0aaaaa00000000000000000000000000"
               + "00000a000000000000000o0000000000"
               + "000zza0000000000aaa0a2aaaaaa0000"
               + "00067a000effg00000a000a000000000"
               + "00045a000hiij00000aaa0a000000000"
               + "00888800000000000000a0a000000000"
               + "00000000000000000000a0a00efg000a"
               + "0000000000000000000000000hij0000"
               + "0000000000000efg0000000000000000"
               + "aa00000000000hij0000000000000000"
               + "4500000a0000000000000000000a0000"
               + "67000000000000000000000000000000"
               + "00000000000000000000000000000000"
               + "00000000000000000000000000000000"
               + "000000000000000000000000a0000000"
               + "00000000008000000000000088888880"
               + "0000000080000000efg0000000000000"
               + "0000000000000000hij0000000000000"
               + "00000000000000000000000000000000"
               + "11000000000000000000010000010001",
               1, 0, 0.5, 12
            ],
            [
                 "04500000000000000000000000000000"
               + "06700000000000000000000000000000"
               + "00000000000000000effg00000000000"
               + "00000000000000000hiij000000000zz"
               + "00000000000000000000000000000067"
               + "00000000000000000000000000000045"
               + "0aa000000000000000000000000000aa"
               + "0000000000000000000000000p000000"
               + "00000000000000000000000000000000"
               + "000000p0000000000000000p00000000"
               + "00000000000000000000000000000000"
               + "00000000p000000000000p0000000000"
               + "0000efg0000000000000000000000000"
               + "0000hij000p00000000p000000000000"
               + "00000000000000000000000000000000"
               + "000000000000p000o000000000000000"
               + "00n00000000000002000000000000000"
               + "0kxl0000000000000000000000000000"
               + "kxxml0000000000000000000000bcd00"
               + "11111100000000001000000000111111",
               1, 8, 1.5, 3
            ],
            [
                 "000a0000000000000000000000000000"
               + "000a0000000000o00000000000000000"
               + "067a0000000000200aaa00000000000o"
               + "045a0000000800000000000000000002"
               + "0aaa000000000000000000000effg000"
               + "00000000000000a0000000000hiij000"
               + "00000000000000a0000o0000p0000008"
               + "00000000000000a00002000000000000"
               + "000000000p0000a00000000000000000"
               + "00efg000000000a000000000p0000000"
               + "00hij000000000a00008000000000000"
               + "00000o0effg000a00000000000000000"
               + "0000020hiij000a000000000000000bc"
               + "0000000000000000000a000000000aaa"
               + "0000000000000000000a0efg0000a000"
               + "0000080000000000000a0hij00000000"
               + "00000000000000n0000a0000000000zz"
               + "0000000000000kxl000a000000000067"
               + "00p000000000kxxml00a000000000045"
               + "0000000000011111111a0000000p0011",
               4, 5, 1.5, 1
            ]
         ],
         curLvl : -1,
         coins : 0,
         goombas : 0,
         mapHTML : "",
         ground : false,
         keys : [],
         dirX : 1,
         mov : {
            x : 0,
            y : 0
         },
         interval : 0
      }

      // generate sprite prototypes
/* 02 */ for (var i=0;i<data.sprites.length;i++) {
/* 03 */    for (var b=0;b<(pix=(data.sprites[i][1]+"").split("")).length;
            data.spriteHTML[i] = (data.spriteHTML[i] || "<div style='width:16px;height:16px;"
                        + ((data.pal[data.sprites[i][0][0]] != "") 
                           ? ("background-color:#" + data.pal[data.sprites[i][0][0]])
                           : "")
                        + "' >") + 
      
                     ((data.sprites[i][0][parseInt(pix[b],16)] != "") ? 
      
                     ("<div style='"
                     + "left:" + (data.sprites[i][2] ? (16-parseInt(pix[b+1],16)-(parseInt(pix[b+3],16)+1)) : parseInt(pix[b+1],16) ) + "px;"
                     + "top:" + parseInt(pix[b+2],16) + "px;"
                     + "width:" + (parseInt(pix[b+3],16)+1) + "px;"
                     + "height:" + (parseInt(pix[b+4],16)+1) + "px;"
                     + "background-color:#" + data.pal[data.sprites[i][0][parseInt(pix[b],16)]] + ";"
                     + "overflow:hidden;"
                     + "'></div>") 
      
                     : "") 

                     + ( (b+=5) >= pix.length ? "</div>" : "") 
         ) { }
      }

      // keyboard events
      document.onkeydown = document.onkeyup = function(e) {
/* 04 */    data.keys[(e||window.event).keyCode] = (e||window.event).type == "keydown";
      }

      // is tile at (x,y) blocking?
      function block(x, y) {
/* 05 */    return (
            (data.map[Math.floor(y/16) * 32 + Math.floor(x/16)] != "0" 
               && parseInt(data.map[Math.floor(y/16) * 32 + Math.floor(x/16)],16) < 11)
         );
      }

      // start the game and/or continue to next level
      window.onload = nextLevel = function() {

         // reset game vars
/* 06 */       data = {
            pal : data.pal,
            sprites : data.sprites,
            spriteHTML : data.spriteHTML,
            mapHTML : "",
            curLvl : data.curLvl+1,
            lvl : data.lvl,
            map : data.lvl[(thisLvl=(data.curLvl+1)%data.lvl.length)][0].split(""),
            coins : data.lvl[thisLvl][1],
            goombas : data.lvl[thisLvl][2],
            startx : data.lvl[thisLvl][3],
            starty : data.lvl[thisLvl][4],
            mov : {
               x : data.mov.x,
               y : -6
            },
            dirX : data.dirX,
            ground : false,
            keys : [],
            interval : data.interval
         }

         // generate map
/* 07 */    for (var i=0;i<data.map.length;
            data.mapHTML += (data.map[++i] != "0") ? 
               (
               "<div id='map_sprite_" + i + "' class='mapsprite' style='"
                  + "left:" + ((i%32)*16) + "px;top:" + (Math.floor(i/32)*16) + "px;"
                  + (data.map[i] == "o" ? "display:none;" : "")
                  + "'><div style='height:16px;width:48px;'>"
                  + data.spriteHTML[parseInt(data.map[i],36)-1]
                  // are we a question box?
                  + (
                     data.map[i] == "2" ? 
                        ("<div style='left:16px;'>" + data.spriteHTML[2] + "</div>"
                        + "<div style='left:32px;'>" + data.spriteHTML[8] + "</div>")
                        : ""
                  )
                  // or maybe a little Goomba?
                  + (
                     data.map[i] == "p" ? 
                        ("<div style='left:16px;'>" + data.spriteHTML[25] + "</div>"
                        + "<div style='left:32px;'>" + data.spriteHTML[33] + "</div>")
                        : ""
                  )
                  + "</div></div>"
               ) : ""
         ) {}


         // add the map sprites + Mario sprite to container div
/* 08 */    document.getElementById("mario").innerHTML = 
            data.mapHTML
            + "<div id='mario_sprite' style='left:" + (data.startx*16) + "px;top:" + (data.starty*16) + "px;'>" 
               + "<div style='left:0px;'>" + data.spriteHTML[26] + "</div>"
               + "<div style='left:" + (1*16) + "px;'>" + data.spriteHTML[27] + "</div>"
               + "<div style='left:" + (2*16) + "px;'>" + data.spriteHTML[28] + "</div>"
               + "<div style='left:" + (3*16) + "px;'>" + data.spriteHTML[29] + "</div>"
               + "<div style='left:" + (4*16) + "px;'>" + data.spriteHTML[30] + "</div>"
               + "<div style='left:" + (5*16) + "px;'>" + data.spriteHTML[31] + "</div>"
               + "<div style='left:" + (6*16) + "px;'>" + data.spriteHTML[32] + "</div>"
            + "</div>";

         // start the game cycle if not already started
/* 09 */    data.interval = data.interval || setInterval( function() {
   
            // where does wittle Mario want to go?
/* 10 */       var newPos = {
               x : Math.min(32*16-16,
                  Math.max(0,
                     (oldX = parseInt((mspr=document.getElementById("mario_sprite")).style.left||0)) 
                     + (data.mov.x = 
                        (data.keys[37] ? 
                           Math.max(-6, --data.mov.x) : 
                           (
                              data.keys[39] ? 
                                 Math.min(6, ++data.mov.x)
                              : (Math.abs(data.mov.x) > 0.7 ? (data.mov.x < 0 ? (data.mov.x+0.7) : (data.mov.x-0.7)) : 0)
                           )
                        )
                     )
                  )
               ),
               y : ((data.mov.y = (data.ground && (data.keys[38]||data.keys[65])) ? -8 : (data.mov.y + (data.mov.y < 8 ? (data.mov.y < -4 ? 0.7 : 1) : 0))) < 0) ? 
                  Math.floor(((oldY = parseInt(mspr.style.top||0)) + data.mov.y) / 4)*4 
                  : Math.ceil(((oldY = parseInt(mspr.style.top||0)) + data.mov.y) / 4) * 4
            };
            
            // bonk any question box above
/* 11 */       (document.getElementById("map_sprite_" + (idxLastBonkCheck=Math.floor(newPos.y/16)*32+Math.floor((newPos.x+8)/16)) )||{}).bonked = 
               (data.map[idxLastBonkCheck] == "2") 
                  ? (document.getElementById( "map_sprite_"+(idxLastBonkCheck-32) ) ).style.display = "block"
                  : 0xDECAFBAD;
   
   
            // collect coin
/* 12 */       if (
               (data.map[ idxCoin = Math.floor((newPos.y)/16)*32+Math.floor((newPos.x+8)/16) ] == "o"
                  || data.map[ idxCoin = Math.floor((newPos.y+8)/16)*32+Math.floor((newPos.x+8)/16) ] == "o")
               && document.getElementById("map_sprite_"+(idxCoin+32)).bonked
               && !(coinSprite=document.getElementById("map_sprite_" + idxCoin ) ).collected
               && (coinSprite.collected = true) && data.coins-- && (coinSprite.innerHTML = "")) 
            {}
   
            // do collision detection against map tiles and move Mario to new pos
/* 13 */       mspr.style.left = 
               (newPos.x = Math.round(data.mov.x ? 
                  (
                     data.mov.x < 0 ?
                        (
                           (block(newPos.x, oldY) || block(newPos.x, oldY + 15)) ? 
                              (Math.floor(oldX/16)*16) : newPos.x
                        )
                        : (
                           (block(newPos.x + 16, oldY) || block(newPos.x + 16, oldY + 15)) ?
                              (Math.ceil(oldX/16)*16) : newPos.x
                        )
                  )
                  : oldX
               )) + "px";
   
/* 14 */       mspr.style.top = 
               (newPos.y = Math.round(data.mov.y ? 
                  (
                     data.mov.y < 0 ?
                        (
                           (!(data.ground = false) && (block(newPos.x, newPos.y) || block(newPos.x + 15, newPos.y))) ?
                              ((Math.floor(oldY/16)*16)+(data.mov.y=0)) : newPos.y
                        )
                        : (
                           (block(newPos.x, newPos.y + 16) || block(newPos.x + 15, newPos.y + 16)) ? 
                              (Math.ceil(oldY/16)*16)+(!(data.ground=true)) : 
                                 (newPos.y / 16 > 21) ? 
                                    nextLevel(data.curLvl--) : newPos.y+(data.ground=false)
                        )
                  )
                  : oldY
               )) + "px";
   
            // change Mario sprite
/* 15 */       mspr.scrollLeft = 
               (data.ground ? (
                  data.mov.x ? (
                     ((data.dirX = data.mov.x ? (data.mov.x < 0 ? -1 : 1) : data.dirX) < 0) ? (
                        (new Date().getTime() % 300 > 150) ? 48 : 80 ) : ( (new Date().getTime() % 300 > 150) ? 0 : 32)
                  ) : (
                     ((data.dirX = data.mov.x ? (data.mov.x < 0 ? -1 : 1) : data.dirX) < 0) ? 48 : 0
                  )
               ) : (
                  ((data.dirX = data.mov.x ? (data.mov.x < 0 ? -1 : 1) : data.dirX) < 0) ? 64 : 16
               )
               );
   
            // animate coin boxes and goombas, stomp goombas below
/* 16 */       for (var i=0,stompThis=[0];i<data.map.length;i++) {
   
               // stomp any goomba below Mario, let him jump a little after stomping
/* 17*/           data.mov.y =  
                  ( data.map[i] == "p" && 
                  (
                     (goomba=document.getElementById("map_sprite_"+i)).stomped = goomba.stomped || 
                        (stompThis[i] = (data.mov.y > 0 
                        && (my=parseInt(mspr.style.top,10)) < (gy=parseInt(goomba.style.top,10)) 
                        && my > gy-16
                        && (mx=parseInt(mspr.style.left,10))+16 > (gx=parseInt(goomba.style.left,10))
                        && mx < gx+16))
                  ) && stompThis[i] && data.goombas--) ? -4*(data.ground=1) : data.mov.y;


               // move goombas
/* 18 */          if (data.map[i] == "p" 
                  && (g = document.getElementById("map_sprite_"+i))
                  && (g.style.left = 
                     (g.stomped ? g.style.left 
                     : (g.orgLeft||(g.orgLeft=parseInt(g.style.left,10)))
                        + (g.walkStep = (g.walkStep||0) + 
                           (g.walkDir = ((g.walkStep||0) < -7 ? 1 : ( (g.walkStep||0) > 15 ? -1 : (g.walkDir||1) )) )) * 2
                     ))
                  ) 
               {}
   
               // change sprites for qboxes and goombas
/* 19 */          if (
                  (data.map[i] == "2" || data.map[i] == "p") 
                  && (spr=document.getElementById("map_sprite_"+i)).curScroll != 
                     (bonkScroll = ((
                        (data.map[i]=="2"&&spr.bonked) || (data.map[i]=="p"&&spr.stomped)) ? 32 : ((new Date().getTime() % 1200 > 600) ? 16 : 0)) ) && (spr.firstChild.style.left = -(spr.curScroll = bonkScroll)+"px")) 
               {}
            }
   
            // try to exit the level
/* 20 */       if (
               data.keys[40] 
               && data.map[ Math.floor((newPos.y)/16)*32+Math.floor((newPos.x+8)/16) ] == "z"
               && !data.coins && !data.goombas
               && nextLevel(alert("Thank you, Mario! But our princess is in another pipe!\r\nProceeding to level 1-" + (data.curLvl+2)))
               ) 
            {}
   
         }, 40);

      }



-kaht

(Edited by kaht on 08-22-2008 16:29)

(Edited by kaht on 08-22-2008 16:37)

jseidelin
Nervous Wreck (II) Inmate

From: blog.nihilogic.dk
Insane since: Jul 2008

posted posted 08-24-2008 11:41

kaht: Nice! Some of your levels are absolutely evil, though!



Post Reply
 
Your User Name:
Your Password:
Login Options:
 
Your Text:
Loading...
Options:


« BackwardsOnwards »

Show Forum Drop Down Menu