|
An Allegro Game in 20 lines of code - Possible? |
nonnus29
Member #2,606
August 2002
|
After reading this, I thought, hmmm, that sounds a like a neat idea! There's a screen shot there of a raycaster. So how many lines of code (semicolon delimited for all you cheaters) would it take to make a game in allegro? #include<allegro.h> void main(void) { BITMAP *backbuffer=NULL; int playing=1; allegro_init(); install_keyboard(); install_timer(); set_gfx_mode(GFX_AUTODETECT,640,480,0,0); create_bitmap(SCREEN_W,SCREEN_H); while(playing) { main loop in here} return; } END_OF_MAIN();
So whats that? 11 or 12? That leaves 8 entire lines to play with! Comeon who's up to the challenge? |
23yrold3yrold
Member #1,134
March 2001
|
Semicolon delimiter? Eek. Lose the call to install_timer, and combine the buffer declaration with create_bitmap (what; you can't do that in C? Heh heh ). And check for key[KEY_ESC] instead of playing. And lose the newline right before END_OF_MAIN(), and the blank line after the #include. Brings it down to 9 lines, with 11 to play with. create_bitmap() should return a variable to something, I presume ... -- |
Bruce Perry
Member #270
April 2000
|
main() should return int. Here's my offering:
-- |
Thomas Fjellstrom
Member #476
June 2000
|
heh. cool... Its got problems though when the ball that is fired reaches the line of balls, all the balls reset (or so it seems). -- |
Bruce Perry
Member #270
April 2000
|
Right - I was still working on it. You happened to get the first, severely broken version. Trust me to be overzealous Finalised now -- |
Karadoc ~~
Member #2,749
September 2002
|
Bruce Perry; that's some damn nice work! ----------- |
Thomas Fjellstrom
Member #476
June 2000
|
heh teh collision detection is a bit loose. but I like it -- |
Evert
Member #794
November 2000
|
And it's actually sortof fun too! |
miran
Member #2,407
June 2002
|
Do you want to see my "game" that does more or less the exact same thing? No less than 539 lines! -- |
spellcaster
Member #1,493
September 2001
|
Here's another 20 line game:
Collect all the green balls. Don't hit the red balls. You can hit up to 4 red balls before it's game over... unlimited number of dynamic generated levels. Oh, and if I only count the semicolons, I could get it down to 14 lines. -- |
Bruce Perry
Member #270
April 2000
|
My own post said: main() should return int. Nice game though. Much less subtle abuse of Teh Almighty Comma miran: don't worry - supposing I wanted to extend my game, there's only so far I could go without a complete rewrite. Small hacks are like that. Your game is bound to be more extensible, and the code more readable -- |
spellcaster
Member #1,493
September 2001
|
Quote: Nice game though. Much less subtle abuse of Teh Almighty Comma
Hm.
And please, don't force me to change that code again Quote: and combine the buffer declaration with create_bitmap (what; you can't do that in C? Heh heh ). You can combine the buffer decl with create_bitmap Yeah. BITMAP *buffer = allegro_init() ? NULL : install_keyboard() ? NULL : install_timer() ? NULL : set_gfx_mode(GFX_AUTODETECT_WINDOWED, 640, 480, 0, 0) >= 0 ? create_bitmap(SCREEN_W, SCREEN_H) : NULL; -- |
Evert
Member #794
November 2000
|
I'd call that ?: abuse, but hey, it works, right How about it? A competition in who makes the best game with 20 lines of code? |
spellcaster
Member #1,493
September 2001
|
My "de-commat" version also has a bug during level increase, so I suggest you guys use my first version. Quote: I'd call that ?: abuse, but hey, it works, right
You have to scramble some eggs -- |
Rash
Member #2,374
May 2002
|
return 0; can be omitted in both C++ as well as C99. |
kazzmir
Member #1,786
December 2001
|
I think that would be a neat contest, maybe if the rules were a little less strict like 100 lines maybe. This would force people to be creative and learn to write effecient code! |
Zaphos
Member #1,468
August 2001
|
Efficient? I think you mean "condensed"! It's still a fun exercise ... Interestingly enough, all the 20 liners written so far have actually been 19 lines; since they're semicolon delimeted the "int main(){" doesn't count as a line. Well, neither does #include <allegro> but the need for a return after it implies that it should be counted as a line anyway, I guess ...
|
Johan Henriksson
Member #11
April 2000
|
20 lines... just enough to fit in my comment describing the purpose of the main function ^_^ Be happy we aren't competing in fattest documentation >:) |
Zaphos
Member #1,468
August 2001
|
Just realized that by a literal interpretation of "semicolon delimited" a for (;;) statement requires 3 lines ... heh, but you can fit "squeeze" a program by fitting statements like "x = 2" into "if (x=2) the_next_line; ... so we can rewrite bruce's program like this:
Edit: My snippet is messed up, but hopefully you get the point.
|
Johan Henriksson
Member #11
April 2000
|
I think we rather change the contest to "what game can you squeeze in into 20 lines and 20 columns? |
Zaphos
Member #1,468
August 2001
|
Oh yeah; that's definitely the coolest idea. You just get a grid of 20 by 20 characters to fill up, and try to make a game ... and there is no such thing as cheating. Perhaps it would be more interesting to go 100x15 or something, though. Do we want to do a compo around this? It could be fun!
|
spellcaster
Member #1,493
September 2001
|
Heh. That idea is great -- |
kazzmir
Member #1,786
December 2001
|
It is a good idea,. but why limit it to certain dimensions if all that means is a certain number of characters? 100x15 means a total of 1500 characters. 80x25 means a total of 2000 characters. So why not make the contest a total character contest instead of a dimensional contest? |
Zaphos
Member #1,468
August 2001
|
I dunno ... I thought the dimensional thing added a neat little cuteness / originality; it's essentially the same as a char-count but more restricting and encourages a bit more interesting results by forcing the coder to focus on the graphical appearance of the code itself ...
|
kazzmir
Member #1,786
December 2001
|
thats true, but to maximize your winning chances, you would have to write as much code on one line as possible. in the end, you will have 25 lines of completely filled code. it wouldnt be hard for me to write some code, take out all the tabs, make sure every line ends at exactly 80 characters, and only have 1 space between every token. the dimensions dont force me to do anythign except have a certain number of characters. |
|
|