Jump to bottom

Closed Thread Icon

Preserved Topic: Augut 20lines Javascript Contest - Save the Princess - comments (Page 1 of 2) Pages that link to <a href="https://ozoneasylum.com/backlink?for=22762" title="Pages that link to Preserved Topic: Augut 20lines Javascript Contest - Save the Princess - comments (Page 1 of 2)" rel="nofollow" >Preserved Topic: Augut 20lines Javascript Contest - Save the Princess - comments <span class="small">(Page 1 of 2)</span>\

 
poi
Paranoid (IV) Inmate

From: France
Insane since: Jun 2002

posted posted 08-01-2004 23:15

This month, the goal is to make a game in which we'll have to "Save the Princess".
You can make any kind of game : action, reflexion, rpg, rts, ...
The comments must be posted in this thread, and the entries in Augut 20lines Javascript Contest - Save the Princess - entries

quote:
a code monkey said once:
As usual, the main rule is to make your script in 20 lines of (effective) code.
Comas shouldn't be used to execute several instructions on the same line
See the code sample below to illustrate the basic rules :

code:
<script type="text/javascript">

/* */ document.body.onclick = function()
/* */ {
/* 01 */ val = prompt( 'enter a number' );
/* 02 */ for( i=0; i<10; i++ )
/* */ {
/* 03 */ alert( stupidFunction( val, i ) )
/* */ }
/* */ }

/* */ function stupidFunction( a, b )
/* */ {
/* 04 */ return a>b?a:b; // I said it was a stupid function
/* */ }

</script>



The document.body.onclick = function() does not count as a line as it's not some effective code and the function call could be put in the BODY tag ( or anyother HTML tag ).
The declaration of the stupidFunction() does not count either for the same reasons.
The coma in the line /* 03 */ is ok, since it simply separates the parameters of a function.


Hope we'll all have fun with this topic.



(Edited by poi on 08-01-2004 23:16)

BillyRayPreachersSon
Nervous Wreck (II) Inmate

From: London
Insane since: Jul 2004

posted posted 08-03-2004 14:54

Can we use duct tape, too?

http://www.people.virginia.edu/~bwk7j/Princess.htm



Dan

BillyRayPreachersSon
Nervous Wreck (II) Inmate

From: London
Insane since: Jul 2004

posted posted 08-03-2004 18:12

I have a question regarding the 20 lines competition...

Can I assume that this acceptable as one line of code:

code:
if (expression) execFunction();



rather than having to split it up into two lines?

Thanks!
Dan

poi
Paranoid (IV) Inmate

From: France
Insane since: Jun 2002

posted posted 08-03-2004 18:56

BillyRayPreachersSon: Personnaly I tend to think it must be written on 2 lines. But we've never been really strict and the rules are a bit fuzzy ( thus your question ). On the other hand you could write your code using a ternary operator like:

code:
(expression)?execFunction():void(0);



BillyRayPreachersSon
Nervous Wreck (II) Inmate

From: London
Insane since: Jul 2004

posted posted 08-04-2004 16:48

Just one more question... Although I think I already know what the answer will be, but just thought I'd check anyway

When accessing object properties, I can do this:

code:
obj.property1 = foo;
obj.property2 = bar;



and I can also do this:

code:
obj = {property1:foo, property2:bar }



Is the second method valid as one line of code? It's no biggie if not, it would just mean my code going from 20 to 19 lines

Thanks!
Dan

Iron Wallaby
Paranoid (IV) Inmate

From: USA
Insane since: May 2004

posted posted 08-04-2004 16:51

I would say so; it's an assignment, and a single assignment is a single line.

Of course, I'm a newcomer to the 20lines stuff too.

"Any sufficiently advanced technology is indistinguishable from magic." -- Arthur C. Clarke
"Any sufficiently arcane magic is indistinguishable from technology." -- P. David Lebling

wrayal
Bipolar (III) Inmate

From: Cranleigh, Surrey, England
Insane since: May 2003

posted posted 08-04-2004 18:20

Unfortunately, according to most interpretations of the rules, the "," is not allowed to be used to allow more than one assignment on one line.
Fortunately, its only a bit of fun, so it really doesnt matter .

Great entry though BRP! It's really fun. I can just complete level 11, but beyond there....I suck . Oh well, Im still trying to think of what to do. I was considering doing a mario type thing unsurprisingly. THen it occured to me that borders on the impossible in 20 lines. Now site back and watch poi make one

Good luck everyone!

Wrayal

Go to kimber-ja.demon.co.uk and click on the link to the raytracer!

BillyRayPreachersSon
Nervous Wreck (II) Inmate

From: London
Insane since: Jul 2004

posted posted 08-04-2004 19:36

Originally I had the Princess in the top-left corner, but it was far too easy

After about level 13, the enemy sticks pretty close to you, but there is a lazy knack to it that should get you to at least level 25 (I got bored then

I'm looking forward to seeing the other entries too - if nothing else, I can play games at work under the guise of "learning some advanced javascript techniques"

Dan

poi
Paranoid (IV) Inmate

From: France
Insane since: Jun 2002

posted posted 08-08-2004 23:00

If we stay stricly in the rules, which don't really do whatever, the syntax below seems OK :

code:
obj = { property1:foo, property2:bar }

Objects without methods are equivalent to Arrays, thus the use of Objects simply provides an aesthetic touch to the scripts

poi
Paranoid (IV) Inmate

From: France
Insane since: Jun 2002

posted posted 08-11-2004 02:24

*bump*

Please, for the sack of clarity, can we all try to keep the Augut 20lines Javascript Contest - Save the Princess - entries clean with just the entries, and discuss here. Thanks in advance.

shingebis
Obsessive-Compulsive (I) Inmate

From: UK
Insane since: Aug 2004

posted posted 08-14-2004 17:55

Sorry to throw a spanner in the works so soon after arriving, but I've made a start on my entry and realised that allowing the object notation above (or even just literal arrays, for that matter) opens up the way to some quite blatant cheating:

code:
var dummy = {foo1: myDiv = document.createElement('div'), foo2: myOtherDiv.appendChild(myDiv), foo3: ...}



Unfortunately I can't see how we can make a rule against this without making the whole thing hopelessly restrictive - even completely outlawing commas won't help, as there are similar tricks that could be done with && / || and the ternary ?: operator.

Anyway, I'll crack on with my entry, but now it feels not so much like "let's see how much I can fit into 20 lines", as "let's see how little cheating I need to do what I want in 20 lines"

Iron Wallaby
Paranoid (IV) Inmate

From: USA
Insane since: May 2004

posted posted 08-14-2004 19:01

Simple solution: don't cheat.

Glad to see you're trying it, I'd love to see what you come up with.

"Any sufficiently advanced technology is indistinguishable from magic." -- Arthur C. Clarke
"Any sufficiently arcane magic is indistinguishable from technology." -- P. David Lebling

shingebis
Obsessive-Compulsive (I) Inmate

From: UK
Insane since: Aug 2004

posted posted 08-15-2004 01:52
quote:
Iron Wallaby said:

Simple solution: don't cheat.



Fair enough, as long as it can stay as simple as that - but there's a fine line between creative problem-solving and outright cheating, and it's a matter of opinion where that line is...

Anyway, my entry came in at 18 reasonably sensible lines, and I reckon I could reduce it to about 12 without doing anything that I'd consider a real cheat (combining all global variables into a single object, embedding the assignments in lines 9 and 12 into the lines that follow them), but I achieved what I set out to do, so I'll leave it alone for now at least.

BillyRayPreachersSon
Nervous Wreck (II) Inmate

From: London
Insane since: Jul 2004

posted posted 08-15-2004 13:30

Nice - I've not seen that 3D perspective used since my 8-bit Atari days... So a quick nostalgia trip for me

I'm interested to know about your choice of image file formats - did you choose PNG specifically because of the GIF / UniSys royalties "issue", or was there another reason?

Dan

shingebis
Obsessive-Compulsive (I) Inmate

From: UK
Insane since: Aug 2004

posted posted 08-15-2004 16:55

It's mainly just that I like to do things according to W3C standards, of which PNG is one, even if it means waiting for A Certain Popular Browser to catch up in its support. To me, continuing to use GIF to accommodate IE is a bit like insisting that all your DHTML stuff must work in Netscape 4.

But then again, it's partly because I do graphics in Gimp, which doesn't save to GIF (in the version I've got, anyway) due to the Unisys patent restrictions - so in the end that does play an indirect part.

Jeffy
Neurotic (0) Inmate
Newly admitted

From:
Insane since: Aug 2004

posted posted 08-16-2004 13:40

I like solutions that work in whatever browser (for whatever logical reason) I am forced to use. I hear your comments about PNG use - but to then go ahead and submit an entry which doesn't work in "the most used browser in the world" just because your version of GIMP doesn't support it... well... I call that laughably short-sighted and petty.

Let me know if this kind of "self justified" elitism is something the rest of the board endorses. If it is... I'm out.

Jeff

poi
Paranoid (IV) Inmate

From: France
Insane since: Jun 2002

posted posted 08-16-2004 14:17

Jeffy: I really doubt that's any kind of elitism. Actually many people here feel concerned about web standards and accessibility, but for these little contests we generally focus on the features and consider the standards compliancy as the cherry on the cake. And after all we all have at the very least one version of each major browser available on our OS. It's not a huge pain to paste an URL in another browser or simply right-click and click on "OPEN IN XYZ BROWSER".

Whatever, I'll be glad to see more standard compliant entries in the 20 lines monthly contests. Feel free to submit some.

Jeffy
Neurotic (0) Inmate
Newly admitted

From:
Insane since: Aug 2004

posted posted 08-16-2004 16:19

Poi...

I'm one of those people that push accessability and standards as much as the next person - it's what I do for a living. But I certainly do consider this to be elitism:

quote:
To me, continuing to use GIF to accommodate IE is a bit like insisting that all your DHTML stuff must work in Netscape 4.



I also hope to see more cross-browser working entries in the 20 line contest... since they not only reflect a creative talent, but show a depth of knowledge in a technology that most people assume is only for rollovers.

poi
Paranoid (IV) Inmate

From: France
Insane since: Jun 2002

posted posted 08-16-2004 16:59

Actually many entries in the 20 lines contests are cross browser. But the intenssive CPU usage implied by the previous themes put IE ( and its not easily crawling rendering engine ) in a predominant position. But I'm a FireFox freaks too and always try my best to make my stuffs work in both IE and FireFox.

shingebis
Obsessive-Compulsive (I) Inmate

From: UK
Insane since: Aug 2004

posted posted 08-16-2004 21:23

Since this PNG vs GIF thing isn't something I'm sufficiently bothered about to get into an argument over:

http://www.west.co.tt/matt/js/ant_invasion/index_gif.html

Except that for some reason, this version seems to be completely unusable here in Mozilla - it's about half the speed, and the ants are invisible. Go figure (It's fine in Safari, and I'm assuming it'll be OK in IE too...)

wrayal
Bipolar (III) Inmate

From: Cranleigh, Surrey, England
Insane since: May 2003

posted posted 08-19-2004 03:02

Im really sorry to say this, but Im probably not going to be able to enter anything again. Unfortunately, Im being taken on a boat tomorrow. Im going to spend my birthday and the day I get my GCSE results away from my family, and without any form of computer or TV, so I wont really get a chance to program?

Also, this basically marks the end of my participation in this forum.

My programming has become stagnant, and Im sick of some of the characters on this forum. check the service pack 2 thread on the "ozone" forum of all places if u want to know more.

Thanks for all you guys have given me, its been a real pleasure to share code with you all. I might drop back in from time to time, but thats about it.

Later all,

Wrayal

Go to kimber-ja.demon.co.uk and click on the link to the raytracer!

BillyRayPreachersSon
Nervous Wreck (II) Inmate

From: London
Insane since: Jul 2004

posted posted 08-24-2004 17:05

kastner,

Nice game - is it actually possible to get past level 2?

Dan

kastner
Obsessive-Compulsive (I) Inmate

From:
Insane since: Aug 2004

posted posted 08-24-2004 19:06

Sure thing ... to do level 2, you have to use your ghost (hit space bar).

there are 7 levels right now, as soon as I can beat level 7 on the page I was "inspired" from, I will be adding level 8.

I really wish I could figure out the smooth scrolling... document.getElementById("c_4") (my Hero) returns "HTML Image Element" or some such, but getElementById("c_4").style.top is empty (and setting it does nothing).

the other way I thought to do smooth (but not AS smooth) would be to call draw() every time the movement loop happens, but that seems to do nothing.

kastner
Obsessive-Compulsive (I) Inmate

From:
Insane since: Aug 2004

posted posted 08-24-2004 19:35

Ok, just finished http://oos.moxiecode.com/examples/d_star/index.html, and I finished copying the boards, so unless I missed a unit (up to 7 are 100% known good), then ALL the levels are beatable. Its wierd, I think the origional game had like 4 levels, and they are MUCH harder then the rest of them. I think the OOS guy added them. They're still fun tho!

Tyberius Prime
Paranoid (IV) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 08-25-2004 00:48

kastner: love that game!

and have a look at It's getting crowded in here. (Inmate 5000!) - they're talking about you.
(great way to start at the asylum, btw)

so long,

->Tyberius Prime

poi
Paranoid (IV) Inmate

From: France
Insane since: Jun 2002

posted posted 08-25-2004 01:30

kastner: Your game is really cool. If you could change a bit the sprites to match the topic, it'd rock.

To answer your question about the if statements : YES, they count as they really do something ( compared to a function declaration or trapping an event ). But don't worry, we won't bite if you exceed 20 lines.

You also asked some tips about optimization. A simple trick in the declaration of your variables can shrink 3 lines. Turn the following code:

code:
/* 01 */	var level = 1;
/* 02 */ var width = 12;
/* 03 */ var height = 9;
/* 04 */ var board = [
0, // ...

into this

code:
/* 01 */	var board = [
0+0*(level=1)+0*(width=12)+0*(height=9), // ...

There's also a trick with Strings variables. To nest the declaration in another statement we need is to "nullify" the value of a string. Since there's all the chances that the string do not represent a numerical value we can't use a parseFloat() to convert the string before multiplying it by zero. But we can use the isNaN() function and then multiply the result by zero

Hope that helps

kastner
Obsessive-Compulsive (I) Inmate

From:
Insane since: Aug 2004

posted posted 08-25-2004 01:45

Woah... thanks for the tips, I did the first on you mentioned, and that gives me 3 lines to try and get some of the other features in (reset will be in there soon)

I'm far from an artist, so I just copied the graphics I saw as best I could, I will see what I can find for a princess

that string tip will probably make a little more sense to me when I get some sleep!

Thanks for the great welcoming to the site, I'm glad people are liking the game!

p01 - I've seen your work on the other contests and I'm *very* impressed - your fire and plasma effects are amazing!

I feel like my keyboard handling could be a little tighter, I basicaly used shingebis's for the basis, and adapted it (poorly).

kastner
Obsessive-Compulsive (I) Inmate

From:
Insane since: Aug 2004

posted posted 08-25-2004 02:13

Who would have thought graphics would make it more fun!, I shamelessly ripped of some mario sprites, let me know what you think. I think the only usability aspect missing is the smooth motion animation!

BillyRayPreachersSon
Nervous Wreck (II) Inmate

From: London
Insane since: Jul 2004

posted posted 08-25-2004 11:39

Kastner - I just get loads of JS errors in IE now.

Dan

kastner
Obsessive-Compulsive (I) Inmate

From:
Insane since: Aug 2004

posted posted 08-25-2004 17:49

Yea, I see that....
p01, it looks like the loading trick you showed me (in the array), isn't working in i.e. here is the assignment:
/* 01 */ var board = [
(0+0*(level=1)+0*(width=12)+0*(height=9)+0*(reset = [])),

the ie error is "width is undefined", the first time I access it....
what am I doing wrong?

poi
Paranoid (IV) Inmate

From: France
Insane since: Jun 2002

posted posted 08-25-2004 18:07

kastner:Yep, we may say what we want, but the graphism have a real impact of the fun factor and thus on the gameplay. As for the problem in IE, have you tried to "nullify" the declaration of the array instead of that of the other variables ? ATM I don't really know, I tried :

code:
var board = [ (4+0*(level=1)+0*(width=2)+0*(height=3)), 5, 6, 7 ]
alert( board +"\n"+ level +"\n"+ width +"\n"+ height )

in FireFox 0.8 and IE 6.0.2800, and in both the ouput was:
4,5,6,7
1
2
3

So it should be ok in your game. Sorry to be of little help, I'm still at work ( the one that pay the bills )

kastner
Obsessive-Compulsive (I) Inmate

From:
Insane since: Aug 2004

posted posted 08-25-2004 18:14

Ok, I figured it out, I shouldn't have asked until after I played around - turns out that the line
//p01's trick - thanks
was causing the problem I changed it to:
// p01s trick - thanks
and all is good in the world again.

Dan, it should be fine in IE now...

p01: yea, the graphics make a huge imact, my world is shaken!

I think the game is done unless I get an inspired idea to fix the animation, I added the board reset, so I don't know what else there is todo (aside from move counting) EDIT: move counting is done, but I introduced a bug whereby if you move into a wall, it increments the move counter ...

(Edited by kastner on 08-25-2004 18:23)

poi
Paranoid (IV) Inmate

From: France
Insane since: Jun 2002

posted posted 08-25-2004 18:43

I've seen a page listing many syntaxes for comments that were all valid SGML, but failled in IE. Unfortunatelly I can't find it out.
BTW, I saved the princess in 456 moves.

kastner
Obsessive-Compulsive (I) Inmate

From:
Insane since: Aug 2004

posted posted 08-25-2004 19:32

Woah, 456??? I didn't finish my own verison yet, but the flash one took me 980 or so!
wow...

yea, IE is a strange beast... I was thinking about starting another 20 liner, I had so much fun with that one!

any hint on what sept's theme will be - it will probably be the last one I can particiapte in until jan (holidays at work are killer)

kastner
Obsessive-Compulsive (I) Inmate

From:
Insane since: Aug 2004

posted posted 08-25-2004 23:38

I started another game, not sure if I want to finish it as its already like 10 lines without any board data / game logic...
I kinda did it as a "lets see if I can get this to work"
it works in I.E. but they arrows don't work - so d = -> and a = <- for some reason onkeypress doesn't seem to capture the arrows for me.

here's the url, please please let me know what you think!
http://mine.metaatem.net/20_lines/princess2/

Oh, and the left directioin works, you just have to wait for the image load after you hit it (I need to preload, but not sure how to do it in one line for multiple images)

kastner
Obsessive-Compulsive (I) Inmate

From:
Insane since: Aug 2004

posted posted 08-26-2004 01:39

and a much "heavier" version (about 26 lines by now), space or "up" is the other control
and arrows should be fixed in ie now, but not sure...

http://mine.metaatem.net/princess2/index2.html
* this is the current dev version, so if its really wacky, just wait a minute and reload, I'm probably working on it.

and please, if you look at it, tell me what you think!

Hugh
Paranoid (IV) Inmate

From: Dublin, Ireland
Insane since: Jul 2000

posted posted 08-26-2004 02:05

current level: 10 - 871 moves
princess saved.
Great game.

kastner
Obsessive-Compulsive (I) Inmate

From:
Insane since: Aug 2004

posted posted 08-26-2004 03:21

Good Job, Hugh
did you like the game?

kastner
Obsessive-Compulsive (I) Inmate

From:
Insane since: Aug 2004

posted posted 08-26-2004 06:38

I think I'm gonna move this discussion, b/c this is nowhere NEAR 20 lines

but I'm stuck.. or more accuratly, NOT stuck
I really don't know how to implement the hit testing - the hero sprite is 1.5 blocks high...
and I'm doing my movement in a "draw" function that is broken up by jumping/falling and left/right.... ug... if someone could give me a hint, I'd apprecate it...

Oh, I'm talking about
http://mine.metaatem.net/20_lines/princess2/index2.html

thanks

(Edited by kastner on 08-26-2004 06:39)

BillyRayPreachersSon
Nervous Wreck (II) Inmate

From: London
Insane since: Jul 2004

posted posted 08-29-2004 20:27

kastner,

Have you been modifying your original 20 liner entry? I just tested it under IE6 on a Win XP (Home) SP2 system, and the screen (painfully) redraws after every move, making the game totally unplayable

Dan

[1] 2Next Page »

« BackwardsOnwards »

Show Forum Drop Down Menu