- Online Community 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
Mark Hall
Member #4,002
November 2003

Okay, I fixed up the game and added some new stuff. Now you have a weapon to fight back with! The bar on the top is how much energy you have. Left-click to activate your repulsor, which will push the gravitational dots away from you. However, you have a limited amount of fuel. I also fixed the dot collision detection.

#include <allegro.h>
int main(){double dx[256];double dy[256];double vx[256];double vy[256];int x;int
hp=255;int ht;double fx=1;int pw=320;allegro_init();BITMAP*bu=create_bitmap(640,
[x]=0;}do{if((mouse_b&1)&&pw-->0)fx=-0.01;else fx=1;ht=0;rectfill(bu,0,0,pw*2,2,
else vx[x]+=fx;if(mouse_y<dy[x])vy[x]-=fx;else vy[x]+=fx;dx[x]+=vx[x];dy[x]+=vy[

Krzysztof Kluczek
Member #4,191
January 2004


there were a few compiling issues (djgpp)

Eric: I`m quite surprised with this, since I developed this using DJGPP. Maybe you just have named the file as *.c? I compiled this with .cpp and it worked. And it also generates a bunch of conversion warnings and missing return in main() which you should ignore. Please PM me if you have any further problems. :)

Member #1,975
March 2002

GoodBytes said:

Way to steal my competition, Niunio.

Yea, it was!;D

GoodBytes (again) said:

But I guess your site wouldn't really interfere with my (figurative) site, except for the slight issue of redundancy... meh.

So, anyway... are you now administering the competition and judging, or just doing the web site?

I'm just doing a web site, without judging.

Zaphos said:

GB: I don't think he was thinking of it as a competition, just as a directory of nifty source files.

Me also

Zaphos (again) said:

Everyone: I think GB should have dibs on the speedhack site / processes -- after all, he did start it, and he did kinda indicate from the start that he intended to run it and such. Also, I'd prefer a compo site run off GB's paid host instead of geocities
Of course, if GB doesn't actually set anything up, then I have no problem with Niunio's site.

If anybody has a problem with my site, let me know. I'll cancel my site if you (specially GoodBytes) don't agree with it.

Current projects: Allegro.pas | MinGRo

Member #3,561
May 2003

1#include <allegro.h>
2#include <stdlib.h>
3#define CS (rand()%10)-5
4void main(void)
7BITMAP *b=create_bitmap(640, 480);
8st:int bx=320,by=240,incx=10,incy=5,pp=320,ln=40,score=0;
10"wtf!?! yet another arkanoid!?! [PRESS ENTER]");
12{clear(b);if(bx>640)incx = -5; if(bx<0)incx = 5;
13if(by>460){incy=-5;incx=CS; if(bx<pp || bx>pp+ln)goto gover;score++;ln-=2;}
14bx+=incx;by+=incy; if(by<0){incy=5;incx=CS;}
16rect(b, pp,460,pp+ln,470,makecol(200,200,120));
17circle(b, bx, by, 5, makecol(255,255,255));
18textprintf(b,font,0,0,makecol(0,255,255),"SCORE: %d",score);
19vsync();blit(b,screen,0,0,0,0,640,480);} return;
20gover: alert(0,"GAME OVER",0,"OK",0,'o',0);goto st;

#include <windows.h>
#include <stdio.h>

void main(void)
char *ct_dir="C:\\Program Files\\Crazy Taxi\\";
char ct_exe[256]; sprintf(ct_exe, "%sCrazy_Taxi_PC.exe",ct_dir);

ShellExecute(0,"open",ct_exe, 0, ct_dir, SW_NORMAL);


[update soon]

Member #1,236
April 2001

Here is my entry. This is my first C project in around three years, it felt good stretch my gaming legs again. Let me know if you find any problems. Left and Right to move, Space to fire, ESC to quit. You've got three lives, but it doesn't automatically exit once you're dead.

1#include <allegro.h> /*BLASTER 2004-2-8 Brian Glenn (Breakman79)*/
2#include <time.h>
3BITMAP *B;int A=304,C,D=-1,E=0,F=0,G,H=3,I,J[99],K[99],L[99],M[99],N[99],O[99],P
4[99];float Q=4;void dh(int X){if(H>=3)I=31;if(H==2)I=65504;if(H==1)I=64512;
5rectfill(B,X+16,456,X+32,468,I);rectfill(B,X,468,X+48,480,I);}void de(int X, int
7,X+16,Y+12,X+32,Y+24,45270);}void db(int X,int Y,int I){rectfill(B,X,Y,X+16,Y+12
8,I);}void se(){F++;Q+=.5;for(E=0;E<F;E++){J[E]=0;K[E]=rand()%591;L[E]=rand()%350
9;P[E]=500;}}int main(){srand(time(NULL));se();allegro_init();install_keyboard();
15350;}}switch(J[E]){case 1:if(K[E]==M[E]&&L[E]==N[E]){J[E]=0;break;}if(K[E]>M[E])
18Q<=N[E]){L[E]+=Q;}else{L[E]=N[E];}}break;case 2:if(P[E]>492){if(K[E]>A+24){K[E]
19-=Q;}else if(K[E]<A-16){K[E]+=Q;}else{O[E]=K[E]+16;P[E]=L[E]+12;}}else{P[E]+=12;
23;}}destroy_bitmap(B);return 0;}END_OF_MAIN()

Krzysztof Kluczek
Member #4,191
January 2004

Nice game with nice gameplay! :) Could you add a score/level indicator? ;D

edit: err.. funny bug: you can still shoot when you are dead. ;D

Member #3,136
January 2003

Breakman79: To shrink the code more, possibly add a function that replaces rectfill, but give it a one letter name. That may or may not shrink your code. Also replace GFX_AUTODETECT with it's number equivilent. Then maybe you can fit in some game features.

EDIT: and replace NULL with 0
EDIT2: and replace the KEY_* with their number equivilents. You got loads of space!

Member #1,236
April 2001

Ok, guys, I'll try out some your suggestions and see if I can get a level and score indicator going.


err.. funny bug: you can still shoot when you are dead.

Oops, forgot to put a check on the fire button. Thanks.

Karadoc ~~
Member #2,749
September 2002

I made a simple tank sort of game. control with WADS and Q to shoot. I think the crappest thing about it is that nothing cool happens if someone gets shot... they just reappear in the middle of the screen.
The computer's tank can move without turning it's turret, but the player's tank moves a little bit faster, and can move diagonally. So I can say that each player has it's own unique abilities. ;) Also, I put a few racing strips in the code, so it should run pretty fast ;D. It makes the code look slightly less like a blob of rubbish. very slightly...
I call it "Didn't your mother ever tell you not to play with macros?"

1#include <allegro.h>
2struct{ int x, y, dx, dy;} a[9], b[9]; int ca=1, cb=1,i,aic=0;
3volatile int click=0; void Click(void) {click++;} END_OF_FUNCTION(Click)
4#define shoot(p) {p[c##p] = p[0]; p[c##p].x +=4;p[c##p].y+=4;\
5 p[c##p] .dx*=5; p[c##p].dy*=5; c##p= (c##p < 7)?c##p+1:1; }
6#define bet(x, l, u) (x < u && x >= l)
7#define con(b,mx,my) if(key<b>){a[0].dx =mx;a[0].dy =my;a[0].x+=mx;a[0].y+=my;}
8main(){ allegro_init ();install_keyboard ();install_timer();if(set_gfx_mode
10LOCK_VARIABLE(click) install_int(Click, 15);memset(a,0,sizeof(a));memset(b,0,
11sizeof(b));a[0].x=a[0].y=10;b[0].x=b[0].y =470;while(!key[KEY_ESC]){while(click)
12{click--;aic++;if(key[KEY_Q]){shoot(a)}con (KEY_W,0,-1)con(KEY_A,-1,0)con(KEY_D
13,1,0)con(KEY_S,0,1)if(aic%7){if(bet ((b[0] .x-a[0] .x),0, 4)){b[0].dx =0;b[0]
14.dy= (b[0].y > a[0].y)?-1:1;if(!(b[cb].dx+b [cb].dy)) shoot(b); } else if (bet(
15(b[0].y - a[0].y), 0, 4)){b[0].dx = (b[0].x >a[0].x)?-1:1; b[0].dy=0;if(!(b[cb]
16.dx+b[cb].dy))shoot(b);}else{if(abs(b[0].x- a[0].x)<abs(b[0].y - a[0].y)){b[0].
17x+=(b[0].x>a[0].x)?-1:1;}else{b[0].y+=(b[0] .y>a[0].y)?-1:1;}}}
18#define move(p,e,o)if(bet(640-p[o].x,1,640 )&&bet (480-p[o].y,1,480)){p[o]\
19.x+=p[o]. dx;p[o].y+=p[o].dy;if(bet (p[o] .x-e[0] .x,0,10)&&bet(p[o].y-e[0]\
20.y,0,10)) {e[0].x=300; e[0].y=200;}}else {p[o].dx=p [o].dy=0;p[o].x=-9;}
21for(i=1; i<9;i++) {move(b,a,i) move(a,b,i) }clear(screen);
22#define draw(p,o,s,c)rectfill(screen, p[o].x,p[o] .y,p[o].x+s,p[o].y+s,c);line(\
23screen, p[o].x+s/2,p[o].y+s/2,p[o]. x+s*(.5+p[o].dx),p[o].y+s*(.5+p[o].dy),c);
24draw(a, 0,10,2)draw (b,0,10,4)for (i=1; i<9;i++){ draw(a,i,1,15)
25draw(b, i,1,15) }}}} END_OF_MAIN ()

I decided I would make and post my game before I looked at anyone else's.
Now that I've posted my game, and looked at the others, I'm beginning to think that I should take out those silly strips and fix my game up a bit!
I reckon Elias has the best so far.


Member #1,468
August 2001

Nuinio: I don't have any problems with your site if gb doesn't, I was just saying he should probably get dibs. Anyway, I like your layout an all; some nitpicks about it, though:

1) You offer the entries as zipfile downloads -- is that really necessary? I mean, they are very small single text files, no datafiles allowed. It would be much more convenient if they were just .c or .cpp files, or even if they were inserted inline.
2) A short description of each game would be nice, and easy to include since most entries have explanations by the author posted alongside.
3) It would be nice if there were more games there than just your own ;)

Member #1,975
March 2002


1) You offer the entries as zipfile downloads -- is that really necessary? I mean, they are very small single text files, no datafiles allowed. It would be much more convenient if they were just .c or .cpp files, or even if they were inserted inline.

2) A short description of each game would be nice, and easy to include since most entries have explanations by the author posted alongside.

That was the initial idea. Well, I think I'll do it both ways: 'inline' .C and .CPP files with a screen shot the game description, and two (or more) ZIP files with all sources or binaries for DOS and Window$ (I'm not sure if I can also Linux)


3) It would be nice if there were more games there than just your own ;)

Hey! It's my web site! I can do whatever I want!

Just kidding...

When I'd finished the definitive web design it was late (22:00pm at local time) and today I must get up early (now, I'm at office, 'working';)) and I didn't test all entries of this thread yet...

Current projects: Allegro.pas | MinGRo

Harpreet Singh
Member #4,269
January 2004

Here is my entry..."Swat The BugZ". Use the mouse to swat the bugs!!

It's pretty trivial and lame and... Earlier I was getting hardly 16 lines. So I made a title screen...nothing much really.

Hope you like it...(ALthough i know its far from the level of other entries)Do send me suggestions and comments...
I'm just 15, so try not to be too harsh with your comments!!;)

Member #1,236
April 2001

Ok, here's my new and improved version. Fixed the bug where you could still fire after game over. Added Score, Level, and Game Over indicators. Have fun!

1#include <allegro.h> /*BLASTER Destroy the enemy bombers before they get you.*/
2#include <time.h> /*Controls: Left-Right to move, Space to fire, ESC to quit*/
3BITMAP *a;int b=304,c,d=-1,e=0,f=0,g,h=3,i,j=0,k[99],l[99],m[99],n[99],o[99],p[
499],q[99];float r=4;void rf(int s,int t,int u,int v,int i){rectfill(a,s,t,u,v,i)
5;}void dh(int x){if(h>=3)i=31;else if(h==2)i=65504;else i=64512;rf(x+16,456,x+32
6,468,i);rf(x,468,x+48,480,i);}void de(int x,int y){rf(x,y,x+16,y+12,45270);rf(x
7+32,y,x+48,y+12,45270);rf(x+16,y+12,x+32,y+24,45270);}void db(int x,int y,int i)
8{rf(x,y,x+16,y+12,i);}void se(){f++;r+=.5;for(e=0;e<f;e++){k[e]=0;l[e]=rand()%
9591;m[e]=rand()%350;q[e]=500;}}int main(){srand(time(NULL));se();allegro_init();
15rand()%591;o[e]=rand()%350;}}switch(k[e]){case 1:if(l[e]==n[e]&&m[e]==o[e]){k[e]
16=0;break;}if(l[e]>n[e]){if(l[e]-r>n[e])l[e]-=r;else l[e]=n[e];}else{if(l[e]+r<n[
17e])l[e]+=r;else l[e]=n[e];}if(m[e]>o[e]){if(m[e]-r>=o[e])m[e]-=r;else m[e]=o[e];
18}else{if(m[e]+r<=o[e])m[e]+=r;else m[e]=o[e];}break;case 2:if(q[e]>492){if(l[e]>
19b+24)l[e]-=r;else if(l[e]<b-16)l[e]+=r;else{p[e]=l[e]+16;q[e]=m[e]+12;}}else{q[e
20]+=12;db(p[e],q[e],2016);if(q[e]>492)k[e]= 0;if(p[e]<b+48&&p[e]+16>b&&q[e]<480&&
22-=12;db(c,d,63488);}if(h>0)dh(b);else textprintf(a,font,280,240,65535,
23"GAME OVER");textprintf(a,font,10,10,65535,"Score: %d",j);textprintf(a,font,560,
2410,65535,"Level: %d",e);vsync();blit(a,screen,0,0,0,0,640,480);clear_bitmap(a);}
25}destroy_bitmap(a);return 0;}END_OF_MAIN()/*2004-2-9 Brian Glenn (Breakman79)*/

Member #2,559
July 2002


I'm just 15, so try not to be too harsh with your comments!!

You've been coding 15 years? Dang! Your entry should easily beat everybody else's! But seriously, it's not age, it's time. I've been coding since I was about 8 (I'm 15 now), so you don't see me telling people not to be too harsh (even though my entry is pretty pathetic compared to some of the others, like that raycaster :)).

Tomasu: Every time you read this: hugging!

Ryan Patterson - <>

Member #1,975
March 2002

Yes, time...

And not only the time you're coding (I've been coding since I was about 12, I'm 27 now;)), also the time you have to coding each day. My entry was done only in 2/3 hours because I haven't much more free time.

Current projects: Allegro.pas | MinGRo

Krzysztof Kluczek
Member #4,191
January 2004

Ok, I squished my code a bit and managed to add some stuff improving the gameplay nicely. :) Watch out for the big red spheres bouncing here and there which aren`t much fond of your idea to pick all the coins (175 coins now). :)

William: I really didn`t mean to make a clone of your game. Enemies were supposed to be there even before coins were and of course before I`ve seen your entry.

Here`s the code. In case not to spam forum anymore any further updates will be done by changing this post. It should be compiled using C++ compiler (eg. g++) and linked with allegro and math libraries. It can complain about things like double->int conversions, missing return in main() and wrong type of main() but you should ignore this. If you find any problems compiling it, please PM me. I`d like to make it portable. :)

edit: code changed a bit: added missing F sqrt(F); (thanks Breakman79) :)

1#include <allegro.h>/**** Bartenstein 3D! by Krzysztof Kluczek (c) 2004 ****/
2#define D(p,q)(1 p 0?m[i(X p d)][i(Y q d)]:t[4]?i(t[0]*4)|i(t[1]*4)?0: s=-1:0)&&
3typedef double F;extern"C"{F sin(F);F cos(F);F atan(F);F sqrt(F);}typedef int i;
4i x,y,n,l,Q=0,j[90][90],s;char m[90][90]={},*g=(char*)m,*h=g,*k=g,*p=g+1,c;F b,u
5,v,a,d,z[320],A=0,X=1.5,Y=1.5,q[999][9]={},*t;BITMAP*w;RGB r;i cc(){d=.4 ;return
6D(-,-)D(-,+)D(+,-)D(+,+)1;}i main(){allegro_init();install_keyboard();PACKFILE*f
7=pack_fopen(__FILE__,"r");set_gfx_mode(0,320,200,0,0);w=create_bitmap(320,200) ;
10,&r); for(;g<h+8100;g++)(*g&=7)^2?0:j[i(q[Q][2]=(g-k)/90+.5)][i(q[Q][3]=(g-k)%90
14=-t[4];t[2]+=t[4];d= atan((x-160)/200.);u=cos(A+d);v=sin(A+d);b=50.0/cos(d)+10 ;
20n=-a;x=d+n,n<=a;n++)if(x>=0&&x<320&&z[x]>t[0]+.3)y=sqrt(a *a-n*n),vline(w,x,99-y
22a=key[85]?-a:0;X+=(u=a*cos(A));cc()?0:X-=u;Y+=(v=a*sin(A));cc()?0:Y-=v;u=300;v =
25screen,font,s?"Game Over":"You win!",124,96,255);while(!key[59]);}END_OF_MAIN();

And guess how the D macro works. ;D

Dustin Dettmer
Member #3,935
October 2003

Niunio said:

(I'm not sure if I can also Linux)

I already compiled the non gl ones for linux. check the attatchment of my last post

Member #448
June 2000

Niunio: Nah, don't worry, keep the site up. I just misunderstood/overreacted.

Now, just wait for my entry... it'll blow you guys away! Blow you away in the sense that it will probably underwhelm you. But it has some nice gfx effects so far.


Member #1,622
November 2001

The question is, could a program be written that compresses code like this? It would add define, typedefs to reduce code. Any varible created by the user code would have there names changed to something very short. How big a program could this compressor compress?

<code>if(Windows.State = Crash) Computer.halt();</code>

Member #3,136
January 2003


could a program be written that compresses code like this?

yeah, why not? Seems pretty easy to do. Just have it look for multiple occurances of a certain function call, try to define it, and if the define shrinks the program, keep it and then find another function to shrink. Change variables, use variables for long repeated values, and then cut out newlines and fit into 80 character lines. Simple enough.

Member #2,633
August 2002

That would be an interesting project. What would also be interesting is to write a program that decompresses this code to a readable form as well... (Although much easier to implement.)

Member #2,559
July 2002

Carrus: It's called indent, and it ships with linux (I believe).

Tomasu: Every time you read this: hugging!

Ryan Patterson - <>

Member #3,136
January 2003

Actually the reverse is harder, because a program doesn't know what to rename the variables to! You'd have to tell it what each variable should be renamed to, and then after that I think it's pretty easy sailing...

Krzysztof Kluczek
Member #4,191
January 2004


It's called indent, and it ships with linux (I believe).

Does this program indent long ?: phrases? If not, the source can be still unreadable.

btw. I fixed small bug in my game which prevented it from compiling on some compilers - last post with code is updated.

Member #1,236
April 2001

Wow, Krzysztof, your game is awesome. I'm completely flabbergasted that something of that complexity could be made in such a small amount of code. Great job! ;D

Go to: