Topic: 20 Liners - July 08 - Your favorite video game (Page 1 of 1) |
|
---|---|
Paranoid (IV) Inmate From: Norway |
![]() This month, the theme is : Your favorite video game. |
Bipolar (III) Inmate From: Germany |
![]() 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)})()
|
Paranoid (IV) Inmate From: Norway |
![]() 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 |
Bipolar (III) Inmate From: Germany |
![]() quote:
|
Paranoid (IV) Inmate From: Norway |
![]() 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. |
Obsessive-Compulsive (I) Inmate From: Finland |
![]() (Hi everyone) |
Paranoid (IV) Inmate From: Norway |
![]() |
Nervous Wreck (II) Inmate From: |
![]() 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. |
Paranoid (IV) Inmate From: Norway |
![]() 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. |
Nervous Wreck (II) Inmate From: |
![]() 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"? |
Paranoid (IV) Inmate From: Norway |
![]() Don't worry no one will bite your head off if you make a 25 liner. Except maybe zombies. 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. |
Nervous Wreck (II) Inmate From: |
![]() 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. |
Paranoid (IV) Inmate From: Norway |
![]() Sweet! 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. |
Nervous Wreck (II) Inmate From: |
![]() I can't believe you got that raycaster in 20 lines - incredible work! |
Maniac (V) Mad Librarian From: Seoul, Korea |
![]() 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. |
Paranoid (IV) Inmate From: Norway |
![]() *bump* |
Obsessive-Compulsive (I) Inmate From: blog.nihilogic.dk |
![]() Have fun. I'm counting on getting mine done before then but extra time is always nice. |
Paranoid (IV) Inmate From: Norway |
![]() Yay! Cool to have you on board. |
Obsessive-Compulsive (I) Inmate From: blog.nihilogic.dk |
![]() Here's what I've got so far. Surprise, it's another go at Super Mario! |
Obsessive-Compulsive (I) Inmate From: Germany |
![]() 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 |
Paranoid (IV) Inmate From: Norway |
![]() MOAR! |
Paranoid (IV) Inmate From: Norway |
![]() |
Nervous Wreck (II) Inmate From: blog.nihilogic.dk |
![]() kwei: Ha, don't worry, there's always room for more JS Mario! Very nice. |
Nervous Wreck (II) Inmate From: blog.nihilogic.dk |
![]() 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. |
Nervous Wreck (II) Inmate From: |
![]() 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. |
Neurotic (0) Inmate Newly admitted From: |
![]() Here's Rodent's Revenge in 20 lines of Javascript: http://dspeyer.homelinux.org/rr/ |
Nervous Wreck (II) Inmate From: |
![]() Rodent's Revenge - Interesting - hard to play! |
Paranoid (IV) Inmate From: London |
![]() I like how when you lose you can still try and run from the skitzo cat! |
Maniac (V) Mad Librarian From: Seoul, Korea |
![]() Rodent's Revenge strikes me as a bit buggy... |
Nervous Wreck (II) Inmate From: Finland |
![]() quote:
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)); }
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 ..); }
|
Paranoid (IV) Inmate From: Norway |
![]() I'll call it a night. I slept only 2h last night |
Nervous Wreck (II) Inmate From: Finland |
![]() quote:
|
Nervous Wreck (II) Inmate From: blog.nihilogic.dk |
![]() quote:
|
Paranoid (IV) Inmate From: Norway |
![]() |
Nervous Wreck (II) Inmate From: Finland |
![]() 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. |
Paranoid (IV) Inmate From: Norway |
![]() First of all sorry the delay and thanks to all participants. |
Bipolar (III) Inmate From: |
![]() w00t - nice work y'all. Looking forward to the next challenge. |
Obsessive-Compulsive (I) Inmate From: Collinsville, IL |
![]() jseidelin, very nice Mario remake. 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); }
|
Nervous Wreck (II) Inmate From: blog.nihilogic.dk |
![]() kaht: Nice! Some of your levels are absolutely evil, though! |