Allegro.cc - Online Community

Allegro.cc Forums » Off-Topic Ordeals » The 2004 Allegro ScreenHack

This thread is locked; no one can reply to it. rss feed Print
The 2004 Allegro ScreenHack
Goodbytes
Member #448
June 2000
avatar

A few months/years ago we had a '20 line' programming contest, during which spellcaster suggested we have a 80x25 programming contest. I can't actually find the thread, since the forum search function is lame, but trust me. It happened. :)

Anyway, I have decided to steal spellcaster's idea. (Hope you don't mind, sc? :)) Let's do this thing.

The 2004 Allegro ScreenHack Rules
Post some C or C++ source code that will completely fit into an 80-character by 25-character screen (the standard DOS prompt size) and that will compile on its own (along with a full complement of Allegro/system headers, that is). The best entry (I'm talking games here) will be chosen by vote sometime in the near future. You are allowed to submit as many entries as you like.

Who's up for the challenge? Prove your mettle! Post me some code! ;D


--
~Goodbytes

Eric Love
Member #846
December 2000

I'll never forget a discussion on GameDev a few years ago. Someone complained that the way they implemented Tetris (OO with two files for each class I guess) made for 117 files (or some number like that). Someone said "117 files? Tetris should be like 117 lines!" and then the race was on to implement Tetris in a miminum of space. It was done in around 13 lines. I don't still have it, but many were surprised that it complied and ran.

So you can do a lot in 80x25, but it makes the code very difficult to read. I'm keen to see what people come up with. I also remember a comp with 256 byte .com files, one of which was a space shooter.

Evert
Member #794
November 2000
avatar

Matthew did a tetris for the 20 line thing.
As for 25x80 - I guess it's neat, but I'd rather see a 2000 byte limit on filesize.

Anyway, I'll see if I can think of anything (and actually implement it) this weekend. I've been meaning to get my chess programs ready for beta release for a few weeks now, and I hope to get round to that too.

Fladimir da Gorf
Member #1,565
October 2001
avatar

What about a contest in which the code should look like a logo or a screenshot of the game? The better the code represents the game it compiles to, the better. :)

OpenLayer has reached a random SVN version number ;) | Online manual | Installation video!| MSVC projects now possible with cmake | Now alvailable as a Dev-C++ Devpack! (Thanks to Kotori)

Evert
Member #794
November 2000
avatar

Hmm... I've seen ASCII art Mandelbrot fractals, but I woudn't want to write code to generate one that at the same time looks like one ;)

It's a neat idea though.

Fladimir da Gorf
Member #1,565
October 2001
avatar

The secret is to modify the code to look almost something sensible. Even by adding or deleting spaces here and there can make it look like something.

Oh, and then there's the famous #defines to play with...

OpenLayer has reached a random SVN version number ;) | Online manual | Installation video!| MSVC projects now possible with cmake | Now alvailable as a Dev-C++ Devpack! (Thanks to Kotori)

Trezker
Member #1,739
December 2001
avatar

If you do these kind of things you have too much brainpower and should give some to me!

tareco
Member #2,259
April 2002
avatar

I was bored so I made a lame tic tac toe :P

1#include <allegro.h>
2#define I(x, y)if(x){y}
3#define E(z)else{z}
4#define C(y,z)case y: z break;
5#define W(x,y){a, x, y, 60, 60, 255, 0, 0, 0, 0, 0},
6int s=0,j[2];int a(int msg,DIALOG *d,int c){switch(msg){C(MSG_DRAW,rect(screen,d
7->x,d->y,d->x+d->w,d->y+d->h,d->fg);I(d->d1,I(d->d2,rectfill(screen,d->x+2,d->y+
82,d->x+d->w-2,d->y+d->h-2,d->fg);)E(line(screen,d->x,d->y,d->x+d->w,d->y+d->h,d
9->fg);line(screen,d->x,d->y+d->h,d->x+d->w,d->y,d->fg);)))C(MSG_LPRESS,I(!d->d1,
10d->d2=s;d->d1=1;I(s,s=0;)E(s=1;);return D_REDRAW;))}return D_O_K;}int z(int msg,
11DIALOG *d, int c){int x,y,p,l;DIALOG *b=d->dp;switch(msg){C(MSG_IDLE,for(p=0;p<3
12;p++){for(x=0;x<3;x++){l=0;for(y=0;y<3;y++){I(b[1+y*3+x].d1&&b[1+y*3+x].d2==p,l
13++;)}I(l==3,j[p]++;return D_CLOSE;)}for(y=0;y<3;y++){l=0;for(x=0;x<3;x++){I(b[1+
14y*3+x].d1&&b[1+y*3+x].d2==p,l++;)}I(l==3,j[p]++;return D_CLOSE;)}y=0;l=0;for(x=0
15;x<3;x++){I(b[1+y*3+x].d1&&b[1+y*3+x].d2==p,l++;)y++;}I(l==3,j[p]++;return
16D_CLOSE;)y=0;l=0;for(x=2;x>-1;x--){I(b[1+y*3+x].d1&&b[1+y*3+x].d2==p,l++;)y++;}I
17(l==3,j[p]++;return D_CLOSE;)l=0;for(x=0;x<3;x++){for(y=0;y<3;y++){I(b[1+y*3+x].
18d1,l++;)I(l==9,return D_CLOSE;)}}})}return D_O_K;}int game(){DIALOG w[]={{
19d_clear_proc,0,0,0,0,16,16},W(0,0)W(0,60)W(0,120)W(60,0)W(60,60)W(60,120)W(120,0
20)W(120,60)W(120,120){d_ctext_proc,250,20,0,0,40},{d_ctext_proc,250,30,0,0,1},{
21d_ctext_proc,250,0,0,0,255,0,0,0,0,0,"TicTacToe"},{z,0,0,0,0,0,0,0,0,0,0,w},{0}}
22;char v[2][20];sprintf(v[0],"%d",j[0]);sprintf(v[1],"%d",j[1]);w[10].dp=v[0];w
23[11].dp=v[1];I(do_dialog(w,-1)==-1,return 0;)return game();}void main(){
24allegro_init();install_keyboard();install_mouse();install_timer();set_gfx_mode(
25GFX_AUTODETECT_WINDOWED,320,200,0,0);game();}END_OF_MAIN();

EDIT: There, it should be working now.

Tobias Dammers
Member #2,604
August 2002
avatar

Bomberman, only without monsters, and no eye candy of course...

1#include <allegro.h>
2#define L(x) for (x=0; x<60;++x)
3#define I t[y][x]
4typedef int i;typedef void v;i(*k)()=readkey;RGB pl[256]={{0,0,0},{48,0,0},{0,32
5,63},{16,16,16},{32,32,32},{48,48,48},{0,32,0},{63,63,63}};typedef struct{i t;i
6c;}T;BITMAP* b,*s;i h=480,z=60,X=0,Y=0,c=0,d=0,g=0,e=1,m=9000;T t[60][60];v C(i
7x,i y,i cl){circlefill(b,x+4,y+4,3,cl);circle(b,x+4,y+4,3,0);}i R(){return X*8+(
8(d==1)?c:(d==2)?(-c):0);}i S(){return Y*8+((d==3)?c:(d==4)?(-c):0);}i E(i,i);v p
9(){i x,y;L(y)L(x){rectfill(b,x*8,y*8,x*8+8,y*8+8,(I.t<4)?6:I.t);if(I.t&&(I.t<4))
10C(x*8,y*8,I.t);}C(R(),S(),7);vsync();blit(b,s,0,0,80,0,h,h);textprintf(s,font,0,
110,7,"%3is",m/60);textprintf(s,font,0,10,2,"%i",e);}v pe(i xx,i yy){i x=xx,y=yy;I
12.t=1;I.c=z;for(x=xx+1;(x<=MIN(xx+e,59))&& E(x,y);++x);for(x=xx-1;(x>=MAX(xx-e,0)
13)&& E(x,y);--x);x=xx;for(y=yy+1;(y<=MIN(yy+e,59))&& E(x,y);++y);for(y=yy-1;(y>=
14MAX(yy-e,0))&& E(x,y);--y);}i E(i x,i y){i f=I.t;if(f==3)pe(x,y);if(f==4)return
150;I.t=1;I.c=z;return !f;}v u(i x,i y){if(I.c)--I.c;if(!I.c){if(I.t==1)I.t=0;if(I
16.t==3)pe(x,y);}}i main(){i x,y;allegro_init();install_keyboard();set_gfx_mode(0,
17640,h,0,0);srand(time(0));s=screen;b=create_bitmap(h,h);set_palette(pl);L(y)L(x)
18I.t=(x&y&1)?4:((((x&1)||(y&1))&&(x+y>3)&&!(rand()&1))?5:0);L(x)t[(rand()%z)&~1][
19(rand()%z)&~1].t=2;t[59][59].t=0;do{p();--m;L(y)L(x)u(x,y);if(d)++c;if(!(c&7)){X
20=R()/8;Y=S()/8;if(t[Y][X].t==1)m=0;if(t[Y][X].t==2){++e;m+=120;t[Y][X].t=0;}if((
21X==59)&&(Y==59))g=1;d=0;if(key[82])d=2;if(key[83])d=1;if(key[84])d=4;if(key[85])
22d=3;c=8;if((R()>=h)||(R()<0)||(S()>=h)||(S()<0)||(t[S()/8][R()/8].t>2))d=0;c=0;
23if(keypressed()){i j=k()>>8;if(j==75){t[Y][X].t=3;t[Y][X].c=180;}if(j==59)m=0;}}
24}while(m && !g);rest(1000);while(keypressed())k();clear(s);textprintf(s,font,260
25,240,g?7:1,"You %s! Score:%i",g?"win":"lose",m/z);k();}END_OF_MAIN()

---
Me make music: Triofobie
---
"We need Tobias and his awesome trombone, too." - Johan Halmén

CGamesPlay
Member #2,559
July 2002
avatar

Just to show you all how incredibly freaking awesome I am, I wrote a program to allow you do unobfuscate the program I submit to the competition. I have this contest in the bag. ;D

1#include <allegro.h> /* Obfuscated Code Jigsaw - Ryan Patterson */
2#include <stdio.h> /* This program is my entry into the 2004 Allegro */
3#include <string.h> /* ScreenHack competition. The game is a classic jigsaw */
4/* puzzle. Simply move pieces around to piece back together my horribly */
5/* obfuscated code. Compiles with gcc 3.3.1 and MSVC 7. Note that the file */
6/* needs to be run from the same directory as its source file -- it reads in */
7/* its source as the background for the puzzle. Even has animation. Enjoy! */
8int i,x,y,p=4,m=0;BITMAP*b[25],*d[25],*s,*w;char l[81],*c;k(){if((i==p-1&&p%5!=
90)||(i==p+1&&p%5!=4)||(i==p+5&&p<20)||(i==p-5&&p>4)){w=b[p];b[p]=b<i>;b<i>=w;p=
10i;if(!*l)++m;}}main(){FILE*f=fopen(__FILE__,"r");srand(time(NULL));allegro_init
11();install_keyboard();install_mouse();set_color_depth(32);set_gfx_mode(GFX_AUT\
12ODETECT_WINDOWED,640,200,0,0);s=create_bitmap(640,200);clear(s);for(i=0;i<25&&!
13feof(f)&&*fgets(l,81,f);++i,*l=0){if(strlen(l)<2){--i;continue;}c=strchr(l,13);
14if(!c)c=strchr(l,10);if(c)*c=0;textout(s,font,l,0,i*8,-1);}fclose(f);for(x=0;x<
155;++x)for(y=0;y<5;++y)b[y*5+x]=d[y*5+x]=create_sub_bitmap(s,x*128,y*40,128,40);
16clear(b[p]);*l=1;while(!key[KEY_ESC]){if(!*l){if(!(mouse_b&1))continue;i=(mous\
17e_y/40)*5+(mouse_x/128);k();i=0;for(x=0;x<5;++x)for(y=0;y<5;++y)if(b[y*5+x]!=d[
18y*5+x])i=1;if(!i){textprintf(screen,font,392,168,0xff00,"You won in %d moves!",
19m);rest(2000);readkey();break;}}else{textprintf(screen,font,392,168,0xff0000,"\
20Randomizing... %d%%",(unsigned char)*l*100/255);rest(100);switch(rand()%4){case
210:i=p-1;break;case 1:i=p+1;break;case 2:i=p-5;break;case 3:i=p+5;break;}k();++*
22l;}show_mouse(NULL);for(x=0;x<5;++x)for(y=0;y<5;++y)blit(b[y*5+x],screen,0,0,x*
23128,y*40,128,40);for(x=1;x<5;++x)vline(screen,x*128,0,200,-1);for(y=1;y<5;++y)\
24hline(screen,0,y*40,640,-1);show_mouse(screen);}for(i=0;i<25;++i)destroy_bitmap
25(b<i>);destroy_bitmap(s);}END_OF_MAIN()/*Thanks for playing! Hope you enjoyed*/

[edit]
I tried the other two... Tareco's crashed (after I set the gfx mode to GFX_AUTODETECT_WINDOWED), and I couldn't get Tobias' to do anything...

[edit]
Well, I tried again and got Tobias' to do something... But how do you win or lose?

--
Tomasu: Every time you read this: hugging!

Ryan Patterson - <http://cgamesplay.com/>

Tobias Dammers
Member #2,604
August 2002
avatar

OK, didn't include much info...
Goal is to reach bottom-right corner before time elapses. Picking up blue blobs increases explosion radius and gives 1 extra second.
Keys: Cursor keys move, space drops bomb, esc aborts.
Here's the new version; I also included a fade-out at the end, a clock counter and an explosion range display (blue number).

1#include <allegro.h>
2#define L(x) for (x=0; x<60;++x)
3#define I t[y][x]
4typedef int i;typedef void v;i(*k)()=readkey;RGB l[256]={{0,0,0},{48,0,0},{0,32,
563},{16,16,16},{32,32,32},{48,48,48},{0,32,0},{63,63,63}};i h=480,z=60,X=0,Y=0,c
6=0,d=0,g=0,e=1,m=9000;typedef struct{i t;i c;}T;BITMAP* b,*s;T t[60][60];v C(i x
7,i y,i a){circlefill(b,x+4,y+4,a?3:4,a);}i R(){return X*8+((d==1)?c:(d==2)?(-c):
80);}i S(){return Y*8+((d==3)?c:(d==4)?(-c):0);}v p(){i x,y;L(y)L(x){rectfill(b,x
9*8,y*8,x*8+8,y*8+8,(I.t<4)?6:I.t);if(I.t&&(I.t<4)){C(x*8,y*8,0);C(x*8,y*8,I.t);}
10}C(R(),S(),0);C(R(),S(),7);vsync();blit(b,s,0,0,80,0,h,h);textprintf(s,font,0,0,
117,"%3is",m/60);textprintf(s,font,0,10,2,"%i",e);}i E(i,i);v n(i P,i Q){i x=P,y=Q
12;I.t=1;I.c=z;for(x=P+1;(x<=MIN(P+e,59))&& E(x,y);++x);for(x=P-1;(x>=MAX(P-e,0))
13&& E(x,y);--x);x=P;for(y=Q+1;(y<=MIN(Q+e,59))&& E(x,y);++y);for(y=Q-1;(y>=MAX(Q-
14e,0))&& E(x,y);--y);}i E(i x,i y){i f=I.t;if(f==3)n(x,y);if(f==4)return 0;I.t=1;
15I.c=z;return !f;}v u(i x,i y){if(I.c)--I.c;if(!I.c){if(I.t==1)I.t=0;if(I.t==3)n(
16x,y);}}i main(){allegro_init();install_keyboard();srand(time(0));set_gfx_mode(0,
17640,h,0,0);i x,y;s=screen;b=create_bitmap(h,h);set_palette(l);L(y)L(x)I.t=(x&y&1
18)?4:((((x&1)||(y&1))&&(x+y>3)&&!(rand()&1))?5:0);L(x)t[(rand()%z)&~1][(rand()%z)
19&~1].t=2;t[59][59].t=0;do{p();--m;L(y)L(x)u(x,y);if(d)++c;if(!(c&7)){X=R()/8;Y=S
20()/8;if(t[Y][X].t==1)m=0;if(t[Y][X].t==2){++e;m+=120;t[Y][X].t=0;}if((X==59)&&(Y
21==59))g=1;d=0;if(keypressed()){i j=k()>>8;if(j==75){t[Y][X].t=3;t[Y][X].c=180;}
22if(j==59)m=0;}if(key[82])d=2;if(key[83])d=1;if(key[84])d=4;if(key[85])d=3;c=8;if
23((R()>=h)||(R()<0)||(S()>=h)||(S()<0)||(t[S()/8][R()/8].t>2))d=0;c=0;}}while(m
24&& !g);fade_out(1);clear(s);textprintf(s,font,260,240,g?7:1,"You %s! Score:%i",g
25?"win":"lose",m/z);set_palette(l);while(keypressed())k();k();}END_OF_MAIN()

---
Me make music: Triofobie
---
"We need Tobias and his awesome trombone, too." - Johan Halmén

Elias
Member #358
May 2000

Also had to try myself in this (disable warnings when compiling :P):

1#include <allegro.h> /*CURSOR LEFT/RIGHT: MOVE, CURSOR DOWN: POOR WATER*/
2#define T(y,c,s,p) (y?textprintf_centre(buf,font,160,y,c,s,p),0:key[KEY_ESC])
3#define R(s,x,y,w,h,c)(s?rectfill(buf,x,y-h,x+w,y,c),0:getpixel(buf,x,240+(y)))
4volatile int t=0;int x[99],y[99],w[99],h[99],X,Y,i,j,ot,d,f,u=0,o=0,s=1,l=1,r,z
5=0;void tick(void){t++;};int main(void){srand(time(NULL));if(allegro_init()||
6set_gfx_mode(GFX_AUTODETECT,320,240,0,0)||install_keyboard ())return-1;BITMAP*
7buf;install_int_ex (tick,BPS_TO_TIMER (60));buf=create_bitmap (320,480);A:clear
8(buf);memset(y,0,sizeof y);x[0]=y[0]=120;w[0]=h[0]=20;hline(buf,0,479,319,42);
9while(T(0,0,0,0));t=0;while(!T(0,0,0,0)){if(o|s)goto R;if(!(t % (30 - l * 2))){
10i=2 * (rand () % 160);d=1+rand()%20;for(j=1;j<50;j++)if(!y[j]){x[j]=i;i=(i+2)%
11320;y[j]=w[j]=1;h[j]=d;}}blit(buf,buf,0,240,0,0,320,240);for(j=0;j<99;j++){X=x[
12j];Y=y[j];if(j<50){if(Y){R(1,X,Y,w[j],h[j],j?76+(Y&15):4);if(j&&X<=x[0]+w[0]&&x
13[0]<=X+w[j]&&Y>=y[0]-h[0]&&y[0]>=Y-h[j])o=1;f=1;d=0;if(!j){if(u)f=-1;if(key[
14KEY_LEFT])d=-1;if(key[KEY_RIGHT])d=1;if(key[KEY_DOWN])for(i=50;i<99;i++)if(!y[i
15]){x<i>=2*(x[j]/2)+10;y<i>=y[j];h<i>=60;break;}u=0;}for(i=0;i<=w[j];i++)if(R(0,
16X+i+d,Y+((i&1)?f:0),0,0,0)>0){if(f>0){if(j){R(1,X,240+Y,w[j],h[j],15);y[j]=0;}
17else u=1;f=0;}if(!(i&1))d=0;}x[j]+=d;y[j]+=f;}}else{if(y[j]){R(1,X,Y,1,0,9);if(
18R(0,X,Y+1,0,0,0)){r=(rand()&1)?2:-2;if(R(0,X+r,Y,0,0,0)){if(R(0,X-r,Y,0,0,0)){h
19[j]=1;}else x[j]-=r;}else x[j]+=r;}else{y[j]++;h[j]++;}if(!--h[j])y[j]=R(1,X,Y+
20240,1,0,11);}}}for(i=0;i<320;i+=2)if(!R(0,i,238,0,0,0))break;if(i==320)blit(buf
21,buf,0,240,0,241,320,238);if(y[0]>240)o=1;T(10,7,"%i SEC",120-t/60);if(t==7200)
22{l++;if(l==11){z=o=1;}else goto A;}R:if(z)T(40,13,"YOU WIN",0);else T(1,15,
23"WAVE %i/10",l);if(o)T(110,12,"GAME OVER",0);if(s){T(80,11,"ICE JUNK",0);}if(s|
24o)T(160,10,"PRESS ESC KEY",0);blit(buf,screen,0,0,0,0,320,240);ot=t;while(t==ot
25)yield_timeslice();}if(s|o){s=o;o=0;goto A;}return 0;}END_OF_MAIN()/*ICE JUNK*/

And here's my breakout clone from the 20 line thread, which also qualifies here, and compiles without warnings and also gcc < 3.x:

#include <allegro.h>
volatile int i,t=0,b=320,f=0,p[]={0,160,320},d[]={0,-1,1,0,0,0};void timer(void)
{t++;}int main(void){if(!(allegro_init()||set_gfx_mode(GFX_AUTODETECT,640,480,0,
0)||install_timer()||install_int_ex(timer,BPS_TO_TIMER(100))||!install_mouse()))
{clear(screen);for(i=0;i<480;i++)rectfill(screen,(i%40)*16,(i/40)*16,(i%40)*16+
14,(i/40)*16+14,makecol(200,200,0));rest(4000);t=0;while(p[1]<400)if(f<t){for(i=
0;i<6;i+=2){if(i!=2)circlefill(screen,p[2],p[1],4,i?makecol(100,100,255):0);if(i
<4)p[i+!i]+=d[i+!i];if(i<4&&getpixel(screen,p[2]+d<i>*5,p[1]+d[i+1]*5)){rectfill
(screen,(p[2]+d<i>*5)&~15,(p[1]+d[i+1]*5)&~15,(p[2]+d<i>*5)|15,(p[1]+d[i+1]*5)|
15,0);d[i+!i]=-d[i+!i];p[i+!i]+=d[i+!i];}if(i)rectfill(screen,b-12,320,b+12,327
,i==2?0:makecol(255,0,b/3));if(i==2)b=mouse_x;}f++;}}return 0;}END_OF_MAIN();

--
"Either help out or stop whining" - Evert

tareco
Member #2,259
April 2002
avatar

1#include <allegro.h>
2volatile int sc=0;int gl=0,dx,dy,dd,rl,points=0,lives=2;fixed x,y,ang;void
3sc_add(){sc++;}int re(int m,int a){return rand()%(a+1-m)+m;}void iv(){rl=0;x=
4itofix(re(10,310));y=itofix(re(10,230));dx=re(20,300);dy=re(20,180);dd=re(5,15);
5ang=itofix(re(0,255));}void main(){BITMAP *d;allegro_init();install_keyboard();
6install_timer();set_gfx_mode(GFX_AUTODETECT,320,240,0,0);install_int_ex(sc_add,
7BPS_TO_TIMER(60));d=create_bitmap(320,240);ang=itofix(0);srand(time(0));start:
8text_mode(-1);while(!key[KEY_ENTER]){if(key[KEY_ESC]){fade_out(10);allegro_exit(
9);exit(0);}clear_to_color(d,191);textprintf_centre(d,font,162,122,16,"MiniGolf")
10;textprintf_centre(d,font,160,120,255,"MiniGolf");textprintf_right(d,font,320,
11230,255,"Hiscore: %d",get_config_int("hs","s",20));draw_sprite(screen,d,0,0);}iv
12();gl=0;while(1){while(sc>0){if(key[KEY_ESC]){goto start;}if(!rl){if(key[
13KEY_LEFT]){if(key[KEY_RSHIFT]){ang-=ftofix(0.25);}else{ang-=itofix(1.5);}}if(key
14[KEY_RIGHT]){if(key[KEY_RSHIFT]){ang+=ftofix(0.25);}else{ang+=itofix(1.5);}}if(
15key[KEY_SPACE]){rl=1;}}else{x+=fmul(itofix(2),fcos(ang));y+=fmul(itofix(2),fsin(
16ang));if(fixtoi(x)>=dx-dd/2&&fixtoi(x)<=dx+dd/2&&fixtoi(y)>=dy-dd/2&&fixtoi(y)<=
17dy+dd/2){iv();points+=10;gl++;}if(fixtoi(x)<-5||fixtoi(y)<-5||fixtoi(x)>325||
18fixtoi(y)>245){iv();lives--;if(lives==-1){if(points>get_config_int("hs","s",0)){
19set_config_int("hs","s",points);}lives=2;points=0;goto start;}}}if(gl==10){lives
20++;gl=0;}sc--;}clear_to_color(d,191);circlefill(d,dx,dy,dd,16);if(!rl){line(d,
21fixtoi(x),fixtoi(y),fixtoi(x+30*fcos(ang)),fixtoi(y+30*fsin(ang)),104);}
22circlefill(d,fixtoi(x),fixtoi(y),4,255);textprintf(d,font,0,230,255,
23"Lives: %d Points: %d",lives,points);draw_sprite(screen,d,0,0);}}END_OF_MAIN();

MiniGolf! Well, sorta :)

Niunio
Member #1,975
March 2002
avatar

Can I use external files (samples, MIDIs, DAT...)?

I'm writing one, may be I finish it this night.

-----------------
Current projects: Allegro.pas | MinGRo

james_lohr
Member #1,947
February 2002

You're all crazy...

Rash
Member #2,374
May 2002
avatar

SonShadowCat
Member #1,548
September 2001
avatar

Billybob
Member #3,136
January 2003

I worked for a whole trying to squeeze my code into 80x25. Thanks to X-Viila, Marcello, and many others on #allegro I got it sized right.

I worked in MSVC, so I'm not sure if this compiles under GCC, although it should with minimal change.
The MSVC project was a Win32 Console App, using the required AGL libraries in the linking and USE_CONSOLE defined in preproccessors.

This is a simple game. Arrow keys move you around in the random map. You have to collect the yellow thingies. The Blue Block Ghosts will try to eat you, so you have to avoid those. If they do touch you, you lose all your points. Ghosts can go through walls and teleport at edges so becareful. Enjoy! Also, if you can't move at the beginning, restart the program(random maps).

1#include <alleggl.h>
2#include <math.h>
3#define I(a,b) for(b=0;b<a;b++)
4#define R(a,b) V(D<i>.x+a,b,-(D<i>.y+P));
5typedef int N;void A(N a,N b){allegro_gl_set(a,b);}void V(float a,float b,float
6c){glVertex3f(a,b,c);}struct{unsigned x,y;}D[3];N M[10][10],C=1200,S=0,i,v=0,y,r
7;float X=5,Z=-5,Y,n,l,O,P=.5,Q=.75;volatile N T=0;void F(){T++;}void main(){all\
8egro_init();install_allegro_gl();install_keyboard();A(1024,1);A(131072,1);A(-1,
9140320);set_gfx_mode(GFX_OPENGL_WINDOWED,800,600,0,0);glEnable(2929);glMatrixMo\
10de(5889);glFrustum(-.09,.09,-.07,.07,.1,300);glMatrixMode(5888);install_int(F,17
11);srand(time(0));I(100,i)M[i%10][i/10]=1;I(85,i)M[rand()%8+1][rand()%8+1]=0;I(3,
12i)D<i>.x=D<i>.y=rand()%10;while(!key[59]){while(T){v-=!!v;T--;C++;n=X;l=Z;Y-=key
13[83]*3;Y+=key[82]*3;X-=sin(O=Y*.0174)*.05*key[84];Z+=cos(O)*.05*key[84];X+=sin(O
14)*.05*key[85];Z-=cos(O)*.05*key[85];if(M[(N)X][(N)-Z]==1){X=n;Z=l;}if(M[(N)X][(N
15)-Z]==2){S++;M[(N)X][(N)-Z]=0;}if(C>1200){I(100,i){if(M[r=i%10][i/10]>1)M[r][i/
1610]=0;if(!M[r][i/10])M[r][i/10]=rand()&1+1;}C=0;}if(!(C%60))I(3,i){D<i>.x=(D<i>.
17x+(rand()%3-1))%10;D<i>.y=(D<i>.y+(rand()%3-1))%10;}I(3,i){if(D<i>.x==(N)X&&D<i>
18.y==-(N)Z&&!v){allegro_message("GHOST! Score: %i",S);S=T=0;v=120;}}}glLoadIdent\
19ity();glClear(16640);glRotatef(Y,0,1,0);glTranslatef(-X,-P,-Z);glBegin(7);I(10,y
20)I(10,i){if(M<i>[y]==1){glColor3f(P,P,P);y=-y-1;V(i+1,0,y);V(i+1,1,y);V(i,1,y);V
21(i,0,y);y=y+1;V(i+1,0,y);V(i+1,1,y);V(i,1,y);V(i,0,y);y=-y;V(i+1,0,-y-1);V(i+1,1
22,-y-1);V(i+1,1,-y);V(i+1,0,-y);V(i,0,-y-1);V(i,1,-y-1);V(i,1,-y);V(i,0,-y);}if(M
23<i>[y]==2){glColor3f(P,P,0);V(i+P,Q,-y-P);V(i+Q,O=.25,-y-Q);V(i+O,O,-y-O);V(i+Q,
24O,-y-O);}}I(3,i){glColor3f(0,0,1);R(0,0)R(O,2)R(Q,2)R(1,0)}glEnd();allegro_gl_f\
25lip();}}END_OF_MAIN()

http://www.cljy.com/~billy/80_25_chase_pic.PNG
EDIT_FINAL: Updated entire post.
EDIT: Code updated to latest version.

Krzysztof Kluczek
Member #4,191
January 2004
avatar

Well, I have just finished very similar game, but without enemies and running without AGL on my own ray-trace engine. I wanted to add some enemies (red circles) and player ability to shoot them (using smaller green circles for instance), but it won`t fit in 80x25. As a result, circle particle system is incorporated into engine and used for displaying coins.

Your task here is to collect all gold coins left in the dungeon of the castle Bartenstein and avoid pits. Use arrow keys to move and ESC to exit. You are equipped with gold-coin-counter(TM) and a compass. The game is quite hard to beat, so good luck! :)
(there really are 150 coins and all of them are accessible, really :) )

The code was developed under DJGPP and it generates a bunch of double->int conversion warnings, which can make compilation under other compilers harder. If you are forced to make some modifications in the source, make sure to replace the modified source with the original one before running the game, because otherwise some of the coins can be unaccessible (the game uses it`s source code, which is also prepared to act as a map).

btw. this castle really existed in my home city, but I don`t think there were gold coins, pits and fancy-painted floors. :)

1#include <allegro.h>/* Bartenstein 3D! by Krzysztof Kluczek (c) 2004 */
2#include <math.h>/*-- A complete 3D engine on one 80x25 screen */
3typedef int i;i x,y,n,l,Q=0,j[90][90],s;char m[90][90]={},*g=(char*)m,*h=g,*k=g
4,*p=g+1,c;float b,u,v,a,d,z[320],A=0,X=1.5,Y=1.5,q[999][9]={},*t;BITMAP*w;RGB r;
5void cl(){ d=atan((x-160)/200.);u=cos(A+d);v=sin(A+d);b=50/cos(d)+10;for(l=y=1\
600;y>0;){c=y>9?m[i(b/y*u+X)][i(b/y*v+Y)]+2*(y&~3):0;c++&7?c&7?vline(w,x,99+y,99+
7l,c),0:0,putpixel(w,x,100-y,c),0:(z[x]=b/y,vline(w,x,99+l,100-y,c),y=0);y--;l=c&
87?y:l;}}void sq(){u=cos( A);v=sin(A);for(l=0;l<Q;l++)t=q[l],a=t[2]-X,b=t[3]-Y,t[
90]=a*u+b*v,t[1]=b*u-a*v;u=1E9;while(1){v=0;for(x=0;x<Q;x++)a=q[x][0],v<a&&a<u?l=
10x,v=a:0;if(v<.1)break;u=v;t=q[l];d=160+200*t[1]/t[0];a=16/t[0];for(n=-a;x=d+n,n\
11<=a;n++)if(x>=0&&x<320&&z[x]>t[0]+.3)y=sqrt(a*a-n*n),vline(w,x,100-y,100+y,251-8
12*i(t[0]*4));}}i cc(){d=0.4;return m[i(X-d)][i(Y-d)]&&m[i(X-d)][i(Y+d)]&&m[i(X+d)
13][i(Y-d)]&&m[i(X+d)][i(Y+d)];}void mv(){X+=(u=a*cos(A));if(!cc())X-=u;Y+=(v=a*s\
14in(A));if(!cc())Y-=v;}i main(){allegro_init();install_keyboard();set_gfx_mode(G\
15FX_VGA,320,200,0,0);w=create_bitmap(320,200);PACKFILE *f=pack_fopen(__FILE__ ,\
16"r");while(pack_fgets(p+=90,88,f));pack_fclose(f);for(;g<h+8100;g++)(*g&=7)==2?j
17[i(q[Q][2]=(g-k)/90+.5)][i(q[Q][3]=(g-k)%90+.5)]=Q++:0;for(y=0;y<256;y++){x=y/4;
18r.r=y&1?x:0;r.g=y&2?x:0;r.b=y&4?x:0;set_color(y,&r);} s=Q;while(s&&!key[KEY_ESC]
19){g=m[i(X)]+i(Y);if(*g==7){for(y=198;y+1;y--){if(!(y%30))vsync();blit(screen,sc\
20reen,0,y+1,0,y,320,1);}for(;y<50;y++)vsync();break;}if(*g==2){*g=3;s--;q[j[i(X)]
21[i(Y)]][2]=-9;}for(x=0;x<320;x++)cl();sq();a=0.07;if(key[KEY_LEFT])A-=a;if(key[\
22KEY_RIGHT])A+=a;if(key[KEY_UP])mv();if(key[KEY_DOWN]){a=-a;mv();}u=300;v=20;line
23(w,u,v,u+9*cos(A),v+9*sin(A),254);putpixel(w,u,v,255);textprintf(w,font,0,0,255,
24"%d",s);vsync();blit(w,screen,0,0,0,0,320,200);}clear(screen);textout(screen,fo\
25nt,s?"Game Over":"You win!",124,96,255);while(!key[KEY_ESC]);}END_OF_MAIN();/**/

I think somebody better in english than me should write a news on Allegro.cc about this contest - some people may not visit the off-topic forum but may be interested in it.

Thomas Fjellstrom
Member #476
June 2000
avatar

Krzysztof: Unfortunetly it crashed under linux.. maybe youve got a memory bug lurking in there somewhere?

--
Thomas Fjellstrom - [website] - [email] - [Allegro Wiki] - [Allegro TODO]
"If you can't think of a better solution, don't try to make a better solution." -- weapon_S
"The less evidence we have for what we believe is certain, the more violently we defend beliefs against those who don't agree" -- https://twitter.com/neiltyson/status/592870205409353730

Krzysztof Kluczek
Member #4,191
January 2004
avatar

Thanks for the info. :) I`ll check this tomorrow. It`s 5:26 am in my time zone now. :P

btw. Does entries with unclean exit count? Mine have one destroy_bitmap() missed. :P

Marcello
Member #1,860
January 2002
avatar

Here is will's code in 25 lines...

1#include <alleggl.h>
2#include <math.h>
3#define I(a) for(i=0;i<a;i++)
4#define A(a,b) allegro_gl_set((a),(b));
5#define V(a,b,c) glVertex3f((a),(b),(c));
6#define R(a,b) V(D<i>.x+a,b,-(D<i>.y+.5))
7struct{unsigned x,y;}D[3];volatile int T=0;float X=5,Z=-5,Y,w,z,O,P;int M[10][10
8],g=1200,S=0,i,v=0;void F(){T++;}int main(){allegro_init();install_allegro_gl();
9install_keyboard();A(1024,1)A(8192,32)A(131072,1)A(-1,140320)set_gfx_mode(
100x4F474C57,800,600,0,0);glEnable(2929);glMatrixMode(5889);glFrustum(-.09,.09,
11-.07,.07,.1,300);glMatrixMode(5888);install_int(F,17);srand(time(0));I(100)M[i%
1210][i/10]=1;I(85)M[rand()%8+1][rand()%8+1]=0;I(3)D<i>.x=D<i>.y=rand()%10;while(!
13key[59]){while(T){v-=!!v;T--;g++;w=X;z=Z;Y-=key[83]*3;Y+=key[82]*3;X+=sin(O=Y*
14.0174)*(P=-.05*key[84]);Z-=cos(O)*P;X+=sin(O)*.05*key[85];Z-=cos(O)*.05*key[85];
15if(M[(int)X][(int)-Z]==1)X=w,Z=z;if(M[(int)X][(int)-Z]==2)S++,M[(int)X][(int)-Z]
16=0,printf("Score:%i\n",S);if(g>1200){I(100){if(M[i%10][i/10]>1)M[i%10][i/10]=0;
17if(!M[i%10][i/10])M[i%10][i/10]=rand()&1+1;}g=0;}if(!(g%60))I(3){D<i>.x=(D<i>.x+
18(rand()%3-1))%10;D<i>.y=(D<i>.y+(rand()%3-1))%10;}I(3)if(D<i>.x==(int)X&&D<i>.y
19==-(int)Z&&!v)S=0,v=120,printf("\a");}glLoadIdentity();glClear(16640);glRotatef(
20Y,0,1,0);glTranslatef(-X,-.5,-Z);glBegin(7);for(int y=0;y<10;y++)I(10){P=.5;if(M
21<i>[y]==1){glColor3f(P,P,P);y=-y-1;V(i+1,0,y)V(i+1,1,y)V(i,1,y)V(i,0,y)y=y+1;V(i
22+1,0,y)V(i+1,1,y)V(i,1,y)V(i,0,y)y=-y;V(i+1,0,-y-1)V(i+1,1,-y-1)V(i+1,1,-y)V(i+1
23,0,-y)V(i,0,-y-1)V(i,1,-y-1)V(i,1,-y)V(i,0,-y)}if(M<i>[y]==2){glColor3f(P,P,0);V
24(i+P,.75,-y-P)V(i+.75,O=.25,-y-.75)V(i+O,O,-y-O)V(i+.75,O,-y-O)}}I(3){glColor3f(
250,0,1);R(0,0)R(O,2)R(.75,2)R(1,0)}glEnd();allegro_gl_flip();}}END_OF_MAIN()

Marcello

Zaphos
Member #1,468
August 2001

Marcello: I still needed to #include <stdio.h> on that one, so it was 26 lines :(
Krzysztof Kluczek: Runs for me -- quite cool :)
Minigolf is kinda silly ... Elias's new entry is an interesting concept ...

Niunio
Member #1,975
March 2002
avatar

Here you have my entry. It's the first time I've finished an entry for an Allegro anythingHack and I'm very happy!:)

I've hacked some ideas from Tobias' entry (Hey, this is a Hack competition, isn't it?;))

It is the classic cannon game, where the two players are at opposite sides of a mountain/wall and shoots one against the other. Both players uses the same controls:
[list][*]Up/down cursors: change the shoot angle.
[*]Left/right cursors: change the shoot distance.
[*]Space: shoot.
[*]Esc: get out.
[/list]
Here you have the source (it do not need more headers since the rand, srand & time functions use and return integers, so they don't need prototipes, just as K&R said:P[edit]Or Allegro includes it for me????[/edit]):
[edit2]I've attached a Win32 binary if you can't compile it[/edit2]

#SelectExpand
1#include<allegro.h> /* CAÑÓN: Ñuño's ScreenHack 2004 entry (c)2004. Is GPL. */ 2typedef int i;typedef float f;typedef void v;i x1,y1,a1,f1,x2,y2,a2,f2,k;BITMAP* 3s;v bp(c){clear_to_color(s,c);}gk(v){return readkey()>>8;}v kb(v){clear_keybuf() 4;}rn(x){return rand()%x;}f cx(a,l){return(fixcos(a<<16)*l)>>16;}f cy(a,l){return 5(fixsin(a<<16)*l)>>16;}v ct(char*S,i y,i c){textout_centre(s,font,S,160,y,c);}ui 6(i*x,i*y,i*a,i*F,i p){i r,h;f bx,by,vx,vy;circle(s,*x,210,10,15);line(s,*x,210,* 7x+cx(*a,8),210+cy(*a,8),7);rectfill(s,*x-25,230,*x+25,235,15);rectfill(s,*x-25, 8230,*x-25+(*F/2),235,7);kb();while((k=gk())!=59&&k!=75){*F+=((k==83)-(k==82));if 9(*F<0)*F=0;if(*F>100)*F=100;rectfill(s,*x-25,230,*x+25,235,15);rectfill(s,*x-25, 10230,*x-25+(*F/2),235,7);line(s,*x,210,*x+cx(*a,8),210+cy(*a,8),10);*a=(*a+(((k== 1185)-(k==84))*p))&0xFFFFFL;line(s,*x,210,*x+cx(*a,8),210+cy(*a,8),7);}if(k==75){ 12by=*y-2+(vy=cy(*a,*F/10));bx=*x+(vx=cx(*a,*F/10));while(getpixel(s,bx+2,by+2)== 1311&&getpixel(s,bx-1,by+2)==11){if((bx+=(vx*=.99))<0||bx>318)return 0;if((by+=vy 14+=.2)>238)return 0;rectfill(s,bx,by,bx+1,by+1,15);rest(100);rectfill(s,bx,by,bx+ 151,by+1,11);}for(h=r=0;r<15;r++){circlefill(s,bx,by,r,12);h=(getpixel(s,x1,y1)== 1612||getpixel(s,x2,y2)==12);rest(100);}for(r=0;r<15;r++){circlefill(s,bx,by,r,11) 17;rest(100);}return h;}return k==59;}main(v){set_uformat(U_ASCII);allegro_init(); 18install_timer();install_keyboard();if(set_gfx_mode(GFX_SAFE,320,240,0,0)<0) 19return-1;s=screen;for(;;){bp(0);ct("CAÑÓN",100,2);ct("SPACE or ESC",120,15);ct( 20"(c)Ñuño,2004",220,9);kb();while((k=gk())!=59&&k!=75);if(k==59)return 0;srand( 21time(0));bp(11);rectfill(s,0,180,320,240,10);ellipsefill(s,160,180,rn(50)+20,rn( 22120)+30,10);x2=320-(x1=rn(50)+10);y1=y2=178;a1=f1=f2=0;a2=128;line(s,x1-1,y1+1, 23x1+1,y1-1,7);putpixel(s,x1+1,y1+1,7);line(s,x2+1,y2+1,x2-1,y2-1,7);putpixel(s,x2 24-1,y2+1,7);for(;;){if(ui(&x1,&y1,&a1,&f1,1))break;if(ui(&x2,&y2,&a2,&f2,-1)) 25break;}rest(1500);}return 0;}END_OF_MAIN(); /* I did it! */

8-);D

This other is the uncompressed and commented version. It's exactly the same than the previous one, but it is indented and full of comments (more than 100 lines:o... How I'd put them in only 25? ???)

#SelectExpand
1/* CAÑÓN: Ñuño's ScreenHack 2004 entry (c)2004. Is GPL. */ 2 3/* This is the 'uncompressed' commented version. */ 4 5#include<allegro.h> /* I'll use the Allegro library only. */ 6 7/* No more headers needed. The std functions used (rand, srand & time) 8 uses and return integer, so they don't need prototipes. */ 9 10/* Some typedefs. This is to reduce the number of characters needed. */ 11typedef int i; 12typedef float f; 13typedef void v; 14 15i x1, y1, a1, f1, /* Position, angle and 'force' of player one. */ 16 x2, y2, a2, f2; /* Position, angle and 'force' of player two. */ 17BITMAP* s; /* Alias for screen. Only one character! */ 18 19/* Next functions are used often, so it reduces the number of characters. */ 20 21/* bp: 22 * Clear screen. (from 'borrar pantalla', in Spanish. */ 23v bp (c) 24{ 25 clear_to_color(s,c); 26} 27 28/* gk: 29 * Get a key as scan code. */ 30gk (v) 31{ 32 return readkey()>>8; 33} 34 35/* Clean the keyboard buffer. */ 36v kb(v) 37{ 38 clear_keybuf(); 39} 40 41/* rn: 42 * Generates a random number. */ 43rn (x) 44{ 45 return rand()%x; 46} 47 48/* cx: 49 * cy: 50 * Calculates the cartesian factor for the given vector (angle and length). */ 51f cx (a, l) 52{ 53 return (fixcos (a<<16) * l)>>16; 54} 55 56f cy (a, l) 57{ 58 return (fixsin (a<<16) * l)>>16; 59} 60 61/* ct: 62 * Writes a centered text. */ 63v ct (char *S, i y, i c) 64{ 65 textout_centre (s, font, S, 160, y, c); 66} 67 68/* ui: 69 * User input and his response. Returns TRUE if the game finishes or FALSE if 70 * game continues. */ 71ui (i *x, i *y, i *a, i *F, i p) 72{ 73 i k=0, r, h; /* Key, explosion radius and hit flag. */ 74 f bx, by, vx, vy; /* Bullet position and velocity. */ 75 76/* References circle for the angle. */ 77 circle (s, *x, 210, 10, 15); 78 line (s, *x, 210, *x+cx(*a,8), 210+cy(*a,8), 7); 79 rectfill (s, *x-25, 230, *x+25, 235, 15); 80 rectfill (s, *x-25, 230, *x-25+(*F/2), 235, 7); 81/* Process user input. */ 82 kb (); 83 while ((k=gk())!=59&&k!=75) { /* KEY_ESC = 59. KEY_SPACE = 75.*/ 84 /* 'Force'. (I learnt the key input in old MSX games. 8^) */ 85 *F += ((k==83)-(k==82)); /* KEY_LEFT = 82. KEY_RIGHT = 83. */ 86 if (*F < 0) 87 *F = 0; 88 if (*F>100) 89 *F = 100; 90 /* Draw the 'Force'. */ 91 rectfill (s, *x-25, 230, *x+25, 235, 15); 92 rectfill (s, *x-25, 230, *x-25+(*F/2), 235, 7); 93 /* Angle. First, erase the arrow. */ 94 line (s, *x, 210, *x+cx(*a,8), 210+cy(*a,8), 10); 95 *a = (*a + (((k==85) - (k==84)) * p))&0xFFFFFL; /* KEY_UP = 84. KEY_DOWN = 85. */ 96 /* Draw the arrow. */ 97 line (s, *x, 210, *x+cx(*a,8), 210+cy(*a,8), 7); 98 } 99/* If shoot: */ 100 if(k==75) { /* KEY_SPACE = 75. */ 101 /* Setup the bullet state. */ 102 by = *y - 2 + (vy=cy(*a,*F/10)); 103 bx = *x + (vx=cx(*a,*F/10)); 104 /* Animate, while the bullet is on the air. */ 105 while (getpixel (s, bx+2, by+2)==11 && getpixel (s, bx-1, by+2)==11) { 106 /* Moves the bullet and check if it goes out the screen. */ 107 if ((bx+=(vx*=.99))<0 || bx>318) /* The '.99' is the Gravity factor. */ 108 return 0; 109 if ((by+=vy+=.2)>238) /* The '.2' is the Gravity factor. */ 110 return 0; 111 /* Animation. */ 112 rectfill (s, bx, by, bx+1, by+1, 15); 113 rest (100); 114 rectfill (s, bx, by, bx+1, by+1, 11); 115 } 116 /* Explosion. */ 117 for (h=r=0; r<15; r++) { 118 circlefill (s, bx, by, r, 12); 119 h = (getpixel (s, x1, y1)==12 || getpixel (s, x2, y2)==12); 120 rest (100); 121 } 122 for (r=0; r<15; r++) { 123 circlefill (s, bx, by, r, 11); 124 rest (100); 125 } 126 return h; 127 } 128 return k == 59; /* KEY_ESC = 59. */ 129} 130 131/* main: 132 * The main function and loop. */ 133main(v) { 134/* Game startup. */ 135 set_uformat (U_ASCII); allegro_init (); install_timer (); install_keyboard (); 136 if (set_gfx_mode (GFX_SAFE, 320, 240, 0, 0)<0) 137 return -1; 138 s=screen; 139/* Main loop. */ 140 for(;;) { 141 i k=0; /* The key. */ 142 143 /* A kind of introduction. It has, also, the main menu. */ 144 bp (0); 145 ct ("TANK", 100, 2); 146 ct ("SPACE or ESC", 120, 15); 147 ct ("(c)Ñuño,2004", 220, 9); 148 kb (); 149 /* Get the key and chek it. */ 150 while ((k=gk())!=59&&k!=75); /* KEY_ESC = 59. KEY_SPACE = 75.*/ 151 if (k==59) /* KEY_ESC = 59 */ 152 return 0; 153 srand (time (0)); 154 /* Draw the scenary. */ 155 bp (11); 156 rectfill (s, 0, 180, 320, 240, 10); 157 ellipsefill (s, 160, 180, rn(50)+20, rn(120)+30, 10); 158 /* Set and draw thanks. */ 159 x2 = 320 - (x1=rn(50)+10); 160 y1 = y2 = 178; 161 a1 = f1 = f2 = 0; a2=128; 162 line (s, x1-1, y1+1, x1+1, y1-1, 7); putpixel (s, x1+1, y1+1, 7); 163 line (s, x2+1, y2+1, x2-1, y2-1, 7); putpixel (s, x2-1, y2+1, 7); 164 /* Game loop. */ 165 for (;;) { 166 if (ui (&x1, &y1, &a1, &f1, 1)) 167 break; 168 if (ui (&x2, &y2, &a2, &f2, -1)) 169 break; 170 } 171 /* Pause, to see the screen. */ 172 rest(1500); 173 } 174 return 0; 175} 176END_OF_MAIN(); /* Needed by Allegro. */

BTW, I've seen that someones did a 3D demo. They're cool.

If anybody is interested, my [url http://www.burdjia.com/descarga/libreria/M3D/]UnOptimised Voxel Landscape Renderer (UOVLR.zip)[/url] has only 17 executable lines, and I think it would be packed in 6 or less lines of 80 characters whide (changing some variable names, of course;)). Today, I'm too lazy, but if anybody wants a small landscape renderer for his entry...::)

-----------------
Current projects: Allegro.pas | MinGRo

Ryan Broomfield
Member #3,126
January 2003

http://www.shippysite.com/screen.gif

Did mine in 22 lines :D It's a clone of Kaboom! and it has little bomb explosions, lighted fuses, etc. It's pretty fun :)

*UPDATE - my code is also the smallest 80x25 entry at a mere 1699 bytes :)

CONTROLS: USE THE MOUSE TO CATCH THE BOMBS, THE GAME PICKS UP THE PACE THE LONGER YOU PLAY. IF A BOMB PASSES, YOU LOSE A PLATFORM. WHEN ALL 3 PLATFORMS ARE GONE, GAME OVER!
**********

1#include <allegro.h>
2struct B{int x,u;double y;}z[150];main(int d,char**b){memset(z,0,sizeof(struct B
3)*150);double q=160,bm=.5;int s=0,r=200,Q=60,C=30,P=160,p=3,f=0;allegro_init();
4install_keyboard();install_mouse();set_gfx_mode(GFX_AUTODETECT,320,200,0,0);
5rectfill(screen,0,0,319,199,0);textprintf(screen,font,0,100,15,"BLIGGITY BLAM! H
6IT SPACE!");while(key[KEY_SPACE]){} while(!key[KEY_SPACE]){}while(!key[KEY_ESC])
7{rectfill(screen,0,0,319,40,10);rectfill(screen,0,40,319,199,9);textprintf(
8screen,font,0,0,15,"%i",s);if((int)q<r-bm) q+=bm;else if((int)q>r+bm)q-=bm;else
9r=rand()%320;bm+=.0005;Q=(int)((double)(60/bm));rectfill(screen,q-6,12,q+6,36,0)
10;circlefill(screen,q,16,8,15);circlefill(screen,q-3,16,2,0);circlefill(screen,q+
113,16,2,0);rectfill(screen,q-10,8,q+10,12,0);rectfill(screen,q-5,4,q+5,8,0);for(d
12=0;d<p;++d)rectfill(screen,P-10,175-(d*10),P+9,180-(d*10),15);P=mouse_x;if(P<10)
13P=10;if(P>310) P=310;for(d=0;d<150;++d){if(z[d].u>0){z[d].y+=bm/2;circlefill(
14screen,z[d].x,z[d].y,4,0);circle(screen,z[d].x,z[d].y,4,15);line(screen,z[d].x+3
15,z[d].y-3,z[d].x+5,z[d].y-5,15);line(screen,z[d].x+5,z[d].y-5,z[d].x+5+((rand()%
164)-2),z[d].y-5+((rand()%4)-2),14);if(z[d].y>199){z[d].u=0;--p;q=160;bm=.5;r=200;
17Q=60;C=30;f=0;P=160;memset(z,0,sizeof(struct B)*150);}else if(z[d].y>=178-p*10&&
18z[d].y<=182&&z[d].x>=P-12&&z[d].x<=P+12){z[d].u=-5;s+=50;}}else{if(z[d].u<0){
19circlefill(screen,z[d].x,z[d].y,-z[d].u,12);++z[d].u;}else if(f>=Q+C){z[d].u=1;z
20[d].x=q;z[d].y=16;f=0;C=rand()%Q;}}}if(p<1)break;vsync();++f;}rectfill(screen,0,
210,319,199,0);textprintf(screen,font,0,100,15,"FINAL SCORE: %i.PRESS ESC!",s);
22while(key[KEY_ESC]){}while(!key[KEY_ESC]){}}END_OF_MAIN()

shippay



Go to: