Allegro.cc - Online Community

Allegro.cc Forums » The Depot » 2007 Allegro ScreenHack, 80x25 compo

This thread is locked; no one can reply to it. rss feed Print
2007 Allegro ScreenHack, 80x25 compo
kenmasters1976
Member #8,794
July 2007

Well, it was hard enough for me to make this 80x25 code. Anything under that is obviously out of my league.

Matthew Leverton
Supreme Loser
January 1999
avatar

The 20 line competition was different because it went by semicolons. Some people cheated by using commas as semicolons, but I avoided that.

http://www.matthewleverton.com/misc/20lines.html

I think 80x25 is a harder challenge simply because there is a finite limit to the number of characters you can use. (Compare that to my line 7, which is quite long.)

Næssén
Member #5,025
September 2004
avatar

And here is my and Ted's entry for the competition. For you who haven't played Cursor*10 the game probably needs some instructions. The goal of the game is to get as high score as possible.

  • Blue boxes give score points when clicked and unlocks the door to the next level

  • Red boxes are closed doors

  • Green boxes are open doors

  • Yellow boxes are extra lives

  • Red circles open doors when pushed

  • Black boxes are openings to the previous level, however you can't use them to go back.

At most levels you need to click more than one blue box and/or push more than one red circle in order to unlock the door to the next level. It may seem tough at first, but you'll get help as the game progresses.

Oh, and one more thing, when the time is up you loose a life and have to restart from the first level.

1#include <allegro.h>/////////////////Cursor*n v1.2 By Olof Naessén and Ted Steen
2#define F(i,j)for(i=0;i<j;i++)//////////////////////////////////////////////////
3#define R(x,y,c)rectfill(B,x*f,y*f,x*f+f,y*f+f,c);//////////////////////////////
4#define P(x,y,t,v)textprintf(B,font,x,y,0,t,v);/////////////////////////////////
5int*B,A[99][99999][5],C[99],D[49][10][10][2],E[49][10][10],g=1,o,d,a,r,k,b,i,t,s
6=400,l=3,w,q=3000,*u,*e,h=1,f=40,p=10,j=49;void Q(int z,int x,int y,int t,int s)
7{u=D[z][x][y];if(*u!=0){*u=t;u[1]=s;}}void S(){srand(6);F(i,g)C<i>=1;F(i,j)F(k,p
8)F(r,p)D<i>[r][k][0]=-1;F(i,j){r=rand()%p;k=(rand()%9)+1;Q(i,r,k,0,0);*D[i+1][r]
9[k]=3;F(a,rand()%(i+1)+i/2)Q(i,rand()%p,(rand()%9)+1,1,rand()%((i/2)+2)+1);F(a,
10rand()%2)if(i>5)Q(i,rand()%p,(rand()%9)+1,4,0);}}void v(int c){F(i,j){o=1;F(k,p)
11{F(r,p){u=D<i>[r][k];if(*u==0){a=r;b=k;if(i==c)if(u[1]==0)R(r,k,4)else R(r,k,p)}
12if(*u==1)if(u[1]!=0){o=0;if(i==c){R(r,k,3)P(r*f+18,k*f+18,"%d",u[1])}}if(*u==3&c
13==i)R(r,k,0)if(*u==4){if(u[1]==0){o=0;w=4;}else w=p;if(i==c)circlefill(B,r*f+20,
14k*f+20,20,w);}if(i==c&&E<i>[r][k]==1)R(r,k,14)}}D<i>[a]<b>[1]=o;}}void main(){S(
15);F(i,j)E<i>[rand()%p][rand()%9+1]=1;allegro_init();text_mode(-1);install_mouse(
16);install_keyboard();set_gfx_mode(2,s,s,0,0);B=create_bitmap(s,s);A[g-1][d][3]=0
17;while(!key[59]){if(d>q){l--;g++;d=0;S();if(l==0){P(155,200,"Game Over",0)P(100,
18209,"Highest level reached %d",h)}else rest(q);}if(l!=0){clear_to_color(B,15);P(
199,19,"Score %d",t)P(9,29,"Lives %d",l)P(150,9,"Time %d",q-d)e=A[g-1][d];v(C[g-1]
20);*e=mouse_x;e[1]=mouse_y;e[4]=0;if(mouse_b)e[3]=1;if(!mouse_b&&A[g-1][d-1][3]){
21e[3]=0;e[4]=1;}F(i,j)F(r,p)F(k,p){u=D<i>[r][k];if(*u==4)u[1]=0;}F(i,g){u=A<i>[d]
22;r=*u/f;k=u[1]/f;o=C<i>;if(C<i>==C[g-1])draw_sprite(B,mouse_sprite,*u,u[1]);if(i
23==g-1)circlefill(B,*u,u[1],4,4);e=D[o][r][k];if(*e==4&&u[3])e[1]=1;if(u[4]){if(*
24e==0&&e[1]==1){C<i>++;h=MAX(h,C<i>);}if(*e==1&&e[1]!=0){e[1]--;t++;}u=&E[o][r][k
25];if(*u==1){*u=0;l++;}}}d++;}blit(B,screen,0,0,0,0,s,s);rest(9);}}END_OF_MAIN();

Edit: We managed to squeeze in a small pause between rounds.
Edit: Yet another update. We now have a Game Over message where you can see the highest level reached.
Edit: Fixed a MinGW issue, the code should now compile with MinGW.

_____________________
darkbits.org | Google+

MiquelFire
Member #3,110
January 2003
avatar

@kenmasters1976: Dude, that has maybe the most awesome bug/misfeature I have ever seen in a Tetris game! Don't like the piece you got, just toss it off to a side.

---
Febreze (and other air fresheners actually) is just below perfumes/colognes, and that's just below dead skunks in terms of smells that offend my nose.
MiquelFire.red
If anyone is of the opinion that there is no systemic racism in America, they're either blind, stupid, or racist too. ~Edgar Reynaldo

Vanneto
Member #8,643
May 2007

I am currently enjoying some sun in Croatia. 8-) I already made something before I left, I'll post it when I come back in Saturday.

One question, must all of the 80x25 space be filled with code or can there be gaps in between? I'm just wondering.

In capitalist America bank robs you.

Kikaru
Member #7,616
August 2006
avatar

Use comments like this:

codecodeblah//comment!

or

codecodeblah/////////

to pad your lines. Ideally, the finished program's code will all be in a rectangle, 80 characters wide by 25 lines high. Or, if you wish, less than 25 lines high.

kenmasters1976
Member #8,794
July 2007

Quote:

@kenmasters1976: Dude, that has maybe the most awesome bug/misfeature I have ever seen in a Tetris game! Don't like the piece you got, just toss it off to a side.

I know... I ran out of space for coding.

I may try to fix that later... maybe.

Neil Black
Member #7,867
October 2006
avatar

I've only managed to compile the tetris game, the rest give me errors.

Seppl
Member #4,656
May 2004
avatar

Now with deallocation of the buffer bitmap.
This should compile. As a cpp file btw.
Hmm... 5 lines left. Maybe I'll add a highscore list.

1#include <allegro.h>/////cpp file///////////////////////////by Seppl///////////
2BITMAP*B;int w,tt,i,ts=0;volatile int t=0;void i_t(){t++;}END_OF_FUNCTION(i_t()
3)class C{public:double x,y,vx,vy;void L(){x+=vx;y+=vy;vy*=.95;}};class P:public
4C{public:double r;void L(){C::L();vx*=.95;}P(){r=4;x=200;y=150;vx=vy=0;}void D(
5){circlefill(B,x,y,r,w);}}p;class E:public C{public:void L(){C::L();vx*=.98f;if
6(((vx>0&&((x>p.x+p.vx&&x+vx<p.x)||(x+vx>p.x+p.vx&&x<p.x)))||(vx<0&&((x<p.x+p.vx
7&&x+vx>p.x)||(x+vx<p.x+p.vx&&x>p.x))))&&y<p.y&&y+20>p.y){p.x=x+vx;p.vx=-p.vx+vx
8*2;}if(x>400){y=rand()%280;x=400;vx=-(rand()%21+85)*.1f;}if(x<0){y=rand()%280;x
9=0;vx=(rand()%21+85)*.1f;}}E(){x=-1;vy=0;}void D(){rectfill(B,x,y,x+vx,y+20,w);
10}};void main(){E e[100];allegro_init();install_keyboard();set_color_depth(32)//
11;set_gfx_mode(GFX_AUTODETECT_WINDOWED,400,300,0,0);install_timer();bool go=1;//
12LOCK_FUNCTION(i_t);LOCK_VARIABLE(t);install_int(i_t,20);B=create_bitmap(400,300
13);w=makecol(255,255,255);tt=0;while(!key[KEY_ESC]&&go){clear(B);p.D();for(i=0;i
14<ts;e[i++].D());if(tt<50)textout_ex(B,font,"STAY ON SCREEN SUCKER!",20,100,w,-1
15);else textprintf_ex(B,font,1,1,w,-1,"points: %i",tt);blit(B,screen,0,0,0,0,400
16,300);for(;tt<t;tt++){p.L();if(key[KEY_UP])p.vy-=.5f;if(key[KEY_DOWN])p.vy+=.5f
17;if(key[KEY_LEFT])p.vx-=.5f;if(key[KEY_RIGHT])p.vx+=.5f;for(i=0;i<ts;e[i++].L()
18);ts=tt/100;if(p.x>400||p.x<0||p.y<0||p.y>300)go=0;}}clear(B);textprintf_ex(B//
19,font,20,50,w,-1,"game over score: %i",tt);blit(B,screen,0,0,0,0,400,300)
20;clear_keybuf();while(!key[KEY_ESC]);destroy_bitmap(B);}END_OF_MAIN()//////////

EDIT:
Every entry here compiles fine for me.

__________________________________
All you need is lunch - The Rutles

Næssén
Member #5,025
September 2004
avatar

We didn't think we would be able to squeeze more stuff into our game, but we did! We added some eye candy in the form of a shake effect when clicking boxes.

Also, I've attached a pre-compiled binary. See my previous post for game instructions.

1#include <allegro.h>/////////////////Cursor*n v1.3 By Olof Naessén and Ted Steen
2#define F(i,j)for(i=0;i<j;i++)//////////////////////////////////////////////////
3int*B,A[99][99999][5],C[99],D[99][10][10][3],E[99][10][10],g=1,o,d,a,r,k,b,i,t,s
4=400,l=3,w,q=3000,*u,*e,*z,h=1,f=40,p=10,j=99,X=0,Y=0;*Q(z,x,y,t,s){u=D[z][x][y]
5;if(*u!=0){*u=t;u[1]=s;u[2]=0;}}int L(int v){return rand()%v;}*R(x,y,v){rectfill
6(B,x*f+X,y*f+Y,x*f+f+Y,y*f+f+Y,v);}*P(x,y,v){textprintf(B,font,x+X,y+Y,0,z,v);}*
7v(int c){F(i,j){o=1;F(k,p){F(r,p){u=D<i>[r][k];if(*u==0){a=r;b=k;if(i==c)if(u[1]
8==0)R(r,k,4);else R(r,k,p);}if(*u==1)if(u[1]!=0){o=0;if(i==c){if(u[2]>0){X=-u[2]
9+L(u[2]*2);Y=-u[2]+L(u[2]*2);u[2]--;}R(r,k,3);z="%d";P(r*f+18,k*f+18,u[1]);X=Y=0
10;}}if(*u==4){if(u[1]==0){o=0;w=4;}else w=p;if(i==c)circlefill(B,r*f+20,k*f+20,20
11,w);}if(*u==3&c==i)R(r,k,0);if(i==c&&E<i>[r][k]==1)R(r,k,14);}}D<i>[a]<b>[1]=o;}
12}*S(){srand(3);F(i,j)F(k,p)F(r,p)*D<i>[r][k]=-1;F(i,j){C<i>=1;r=L(p);k=L(9)+1;Q(
13i,r,k,0,0);*D[i+1][r][k]=3;F(a,L(i+1)+i/2)Q(i,L(p),L(9)+1,1,L((i/2)+2)+1);F(a,L(
142))if(i>5)Q(i,L(p),L(9)+1,4,0);}}*main(){allegro_init();S();F(i,j)E<i>[L(p)][L(9
15)+1]=1;text_mode(-1);install_mouse();install_keyboard();set_gfx_mode(2,s,s,0,0);
16B=create_bitmap(s,s);A[g-1][d][3]=0;while(!key[59]){if(d>q){l--;g++;d=0;S();if(l
17==0){z="Game Over";P(155,200,0);z="Highest level reached %d";P(100,209,h);}else
18rest(q);}if(l!=0){clear_to_color(B,15);z="Time %d";P(150,9,q-d);z="Score %d";P(9
19,19,t);z="Lives %d";P(9,29,l);e=A[g-1][d];v(C[g-1]);*e=mouse_x;e[1]=mouse_y;e[4]
20=0;if(mouse_b)e[3]=1;if(!mouse_b&&A[g-1][d-1][3]){e[3]=0;e[4]=1;}F(i,j)F(r,p)F(k
21,p){u=D<i>[r][k];if(*u==4)u[1]=0;}F(i,g){u=A<i>[d];r=*u/f;k=u[1]/f;o=C<i>;if(C[i
22]==C[g-1])draw_sprite(B,mouse_sprite,*u,u[1]);if(i==g-1)circlefill(B,*u,u[1],4,4
23);e=D[o][r][k];if(*e==4&&u[3])e[1]=1;if(u[4]){if(*e==0&&e[1]==1){C<i>++;h=MAX(h,
24C<i>);}if(*e==1&&e[1]!=0){e[1]--;e[2]+=4;t++;}u=&E[o][r][k];if(*u==1){*u=0;l++;}
25}}d++;}blit(B,screen,0,0,0,0,s,s);rest(9);}}END_OF_MAIN()/////tinyurl.com/6l3ay7

Neil Black said:

I've only managed to compile the tetris game, the rest give me errors.

What was your error with our entry? The game has to be compiled with C, not C++.

_____________________
darkbits.org | Google+

Arvidsson
Member #4,603
May 2004
avatar

Wow, I actually finished something and it was fun too!

Move left and right with arrowkeys, use X to jump and double-jump in midair and Z to boost yourself even higher up in the air. You get the boosts when collecting the coins. You win when all coins are collected and you lose if you fall off the screen. Should compile in both C and C++. Oh and press R to generate a new level.

1#include <allegro.h>///////////////////////////////////BoxJump v2.0 by arvidsson
2#define P(x,y,t,a) textprintf_ex(B,font,x,y,makecol(255,255,255),-1,t,a);///////
3#define Q(m,n) ((rand()%((m+1)-n)+n))///////////////////////////////////////////
4int w=640,t,x,y,b[20][2],c[5][3],n,i,j,k,m,q,o,p,z;float g; int C(int x1,int y1,
5int w1,int h1,int x2,int y2,int w2,int h2){if((x1>x2+w2)||(y1>y2+h2)||(x2>x1+w1)
6||(y2>y1+h1))return 0;return 1;};void G(){n=j=g=z=0;x=Q(580,20);y=Q(40,0);for(i=
70;i<20;i++){V:b<i>[0]=Q(580,20);b<i>[1]=Q(580,20);k=0;do{if(k!=i)if(C(b<i>[0],b[
8i][1],19,19,b[k][0],b[k][1],19,19))goto V;k++;}while(k<i);}for(i=0;i<5;i++){J:c[
9i][0]=Q(580,20);c<i>[1]=Q(580,20);c<i>[2]=1;for(k=0;k<20;k++){if(C(b[k][0],b[k][
101],19,19,c<i>[0]-10,c<i>[1]-10,10,10))goto J;}}}void T(){t++;}void main(){srand(
11time(0));allegro_init();install_keyboard();set_gfx_mode(2,w,w,0,0);install_int(T
12,20); BITMAP* B=create_bitmap(w,w); set_keyboard_rate(0,0);G(); while(!key[59]){
13while(t>0){t--;if(keypressed()){i=readkey();if((i&0xff)=='x'&&j){g=-2;j--;} else
14if((i&0xff)=='z'&&z){g=-5;z--;}}if(key[82])x-=2;if(key[83])x+=2;if(g>6)g=6;for(i
15=0;i<20;i++){if(C(x,y,9,9,b<i>[0],b<i>[1],19,19)){m=MAX(x,b<i>[0]);q=MAX(y,b<i>[
161]);o=MIN(x+9,b<i>[0]+19);p=MIN(y+9,b<i>[1]+19);if(o-m>p-q){if(q==b<i>[1]){y=b[i
17][1]-10;j=2;g=0;}else{y=b<i>[1]+20;}}else{if(m==b<i>[0]){x=b<i>[0]-10;}else{x=b[
18i][0]+20;}}}}for(i=0;i<5;i++)if(C(x,y,9,9,c<i>[0]-5,c<i>[1]-5,9,9)&&c<i>[2]){c[i
19][2]=0;n++;z++;}if(x<0||x>640||y>640){P(300,300,"FAIL!",0);blit(B,screen,0,0,0,0
20,w,w);readkey();G();}if(n>=5){P(275,300,"YOU ARE WIN!",0);blit(B,screen,0,0,0,0,
21w,w);readkey(); G();}g+=0.1;y+=g;if(key[18])G();}rect(B,x,y,x+9,y+9,makecol(255,
22255,255));P(10,10,"Boost: %d",z);for(i=0;i<5;i++)if(c<i>[2])circlefill(B,c<i>[0]
23,c<i>[1],5,makecol(255,255,0)); for(i=0;i<20;i++)rect(B,b<i>[0],b<i>[1],b<i>[0]+
2419, b<i>[1]+19, makecol(0,0,255)); blit(B,screen,0,0,0,0,w,w); clear_bitmap(B);}
25destroy_bitmap(B);}END_OF_MAIN()////////////////////////////////////////////////

{"name":"595181","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/e\/7\/e703b0e31767c4718ab280baa62362f5.png","w":323,"h":336,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/e\/7\/e703b0e31767c4718ab280baa62362f5"}595181

edit: Oops, seems my entry is 79x25. Scite fooled me.
edit2: Updated my entry. It is now in 80x25 format and destroys the buffer like a good little hack. Didn't add anything new gameplay wise, just optimized the use of space a little. Added screenshot too!

Jeff Bernard
Member #6,698
December 2005
avatar

Quote:

It may seem tough at first, but you'll get help as the game progresses.

Is the help those other cursors that appear? At first I thought I had lagged the game really bad or something because the second cursor appeared to do exactly what I had done on the first level.

--
I thought I was wrong once, but I was mistaken.

BAF
Member #2,981
December 2002
avatar

I need an idea for a game to write.

Ted Steen
Member #9,736
April 2008
avatar

Jeff Bernard said:

Is the help those other cursors that appear? At first I thought I had lagged the game really bad or something because the second cursor appeared to do exactly what I had done on the first level.

Yes, that's your mouse from the previous round helping you. You need to do some clever cooperation with yourself to get the high scores!

The current world My record is 1510 points, I reached level 11. (see attachment)

Edit:
Now my best score is 2749. I didn't beat Jeff, but I beat Olof :)
http://www.allegro.cc/files/attachment/595182

Næssén
Member #5,025
September 2004
avatar

Ted Steen said:

The current world record is 1510 points, I reached level 11. (see attachment)

I beat your record Ted, 2720 points and I reached level 14!

_____________________
darkbits.org | Google+

Jeff Bernard
Member #6,698
December 2005
avatar

Quote:

I beat your record Ted, 2720 points and I reached level 14!

pwned: 3139, level 15.
http://www.allegro.cc/files/attachment/595179

It may just be a quick hack, but it's a really fun game.;D

--
I thought I was wrong once, but I was mistaken.

kenmasters1976
Member #8,794
July 2007

Updated mine too. Tweaked the drawing code, reduced almost all variable names to single letter ones and replaced all Allegro constants with numbers to save space and have room to improve it.

I made the playfield 10 blocks wide as usual in Tetris games - this also fixed the problem that MiquelFire mentioned (and likely created new ones). Also added the features I couldn't include in the previous one and reduced window size to fit just the game area.

1#include <allegro.h> // SHTetris.c
2#define f() for(i=0;i<4;i++) /////////////
3#define B() blit(O,screen,0,0,0,0,640,480)
4#define RF(c) rectfill(O,xo+j*16,yo+y*16,xo+j*16+16,yo+y*16+16,c)
5int F[25];int ps[8][16]={0,0,0,15,1,1,1,1,0,0,0,15,1,1,1,1,0,2,2,3,0,0,7,4,0,3,
61,1,0,0,1,7,0,1,1,3,0,0,4,7,0,3,2,2,0,0,7,1,0,1,3,2,0,0,6,3,0,1,3,2,0,0,6,3,0,2
7,3,1,0,0,3,6,0,2,3,1,0,0,3,6,0,0,7,2,0,1,3,1,0,0,2,7,0,2,3,2,0,0,3,3,0,0,3,3,0,
80,3,3,0,0,3,3};int i,j,p,q=0,m[4],x,y,w,a=0,o,no=0,d,e,g,k,lt,rt,ltl,rtl, cf,h,
9cm,rp,cr;BITMAP *O;int UF(){for(i=23;i>=0;i--)if(F<i>==0xFFFF){DL(0,0,i,0xFFFF,
100xFFFFFF,-1);B();rest(50);DL(0,0,i,0xFFFF,0x44A3FF,-1);B();rest(50);}for(i=23;i
11>0;i--){if(F<i>==0xFFFF)for(j=i;j>=1;j--)F[j]=F[j-1];}}int DL(int xo,int yo,int
12 y,int d,int c,int sc){for(j=0;j<16;j++)if(d&1<<j)RF(c);else if(sc)RF(sc);} int
13 main() { allegro_init(); set_color_depth(24); set_gfx_mode(2, 256, 400, 0, 0);
14install_keyboard();O=create_bitmap(640,480);F[24]=0xFFFFFFFF;for(i=0;i<24;i++)F
15<i>=0xE007;srand(time(NULL));while(!key[59]){if(!a){p=q;q=rand()%7;o=no;no=rand
16()%4;d=0;a=1;x=6;y=3;w=6;e=10;g=32;}if(h>e){y++;h=0;}if(cm)x=w;rp=0;if(key[82])
17{lt++;if(lt>ltl){lt=0;w=x-1;ltl/=2;if(ltl<4)ltl=4;}}if(key[83]){rt++;if(rt>rtl)
18{rt=0;w=x+1;rtl/=2;if(rtl<4)rtl=4;}}if(key[75]&&!k){o=(o+1)%4;rp=1;k=1;}if(!key
19[75])k=0;if(!key[82]){ltl=32;lt=31;}if(!key[83]){rtl=32;rt=31;}if(key[85]){e=1;
20g=1;}if(!key[85]){e=10;g=32;}if(rp){f()m<i>=ps[p][(o)*4+i];cr=1;f(){cr=cr&&((F[
21y-i]&(m<i>)<<x)==0);}if(!cr){o=o==0?3:o-1;}}f()m<i>=ps[p][(o)*4+i];cm=1; f()cm=
22cm&&(F[y-1-i]&m<i><<w)==0;cf=1; f()cf=cf&&(F[y-i]&m<i><<x)==0; if(cf){d=0;h++;}
23else d++;if(d>g){f()F[y-i-1]|=m<i><<x;a=0;}for(i = 0;i < 25; i++)DL(0,0,i,F<i>,
240xFFA6A6,0xFFFFA9);f()DL(0,0,y-1-i,m<i><<x,0x44A3FF,0);UF();f(){m<i>=ps[q][no*4
25+i];DL(208,100,5-i,m<i>,0x44A3FF,0xFFA6A6);}B();rest(15);}}END_OF_MAIN()

{"name":"595180","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/5\/7\/57c86258f645a0ce3fed379913e2afa0.gif","w":261,"h":431,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/5\/7\/57c86258f645a0ce3fed379913e2afa0"}595180

Næssén
Member #5,025
September 2004
avatar

kenmasters1976, your tetris game is really starting to shape up. The only thing I miss is a score counter.

Jeff Bernard said:

3139, level 15

I'm impressed.

_____________________
darkbits.org | Google+

Ted Steen
Member #9,736
April 2008
avatar

Kenmasters1976, That is one squeezed game of tetris! but you could double the fun with a score counter!

My suggestion is to replace these defines with functions instead.

#define B() blit(O,screen,0,0,0,0,640,480)                                     
#define RF(c) rectfill(O,xo+j*16,yo+y*16,xo+j*16+16,yo+y*16+16,c)

will turn into something like this

*B(){blit(O,screen,0,0,0,0,640,480);}
*R(c){rectfill(O,xo+j*16,yo+y*16,xo+j*16+16,yo+y*16+16,c);}

Now you can almost fit them into one line.

A few minor optimizations would be to replace
BITMAP *O
with
int*O
And replace

int DL(int xo,int yo,int y,int d,int c,int sc)

with

*DL(xo,yo,y,d,c,sc)

Now... that should be enough for a score counter ;)

Arvidsson
Member #4,603
May 2004
avatar

What the hell is wrong with me? Another entry, that is what's wrong with me.

ARE YOU UP TO THE TASK TO TAKE COMMAND AND DODGE FUNNY LOOKING ASTEROIDS?

Steer your spacecraft with arrowkeys. Reset with R. Quit with ESC. Every 15 seconds the difficulty level is increased which means more asteroids (or space balls if you'd like) to dodge. The maximum level is 10 which means 50 asteroidballs onscreen at ALL times. I almost made it to level 5, level 10 must be hell I suppose (only hardcore gamers need apply 8-)). The blue box on the ship (aka the cockpit) is the hit area.

1#include <allegro.h>////////////////////////////////SpaceDodge v1.0 by arvidsson
2int w=400,i,j,x,y,c,l,q,z,t,u,k,s[75][4],e[50][6];R(m,n){return(rand()%(m+1-n))+
3n;}C(x1,y1,w1,h1,x2,y2,w2,h2){if((x1>x2+w2)||(y1>y2+h2)||(x2>x1+w1)||(y2>y1+h1))
4return 0;return 1;}void T(){t++;u++;}N(){l=1;c=u=q=k=z=0;for(i=0;i<75;i++){s<i>[
50]=R(400,0);s<i>[1]=R(400,0);s<i>[2]=R(5,2);j=s<i>[2]*51;s<i>[3]=makecol(j,j,j);
6}for(i=0;i<50;i++)e<i>[5]=0;x=w/2;y=350;}main(){allegro_init();set_gfx_mode(2,w,
7w,0,0); install_keyboard();install_int(T,20);BITMAP *B=create_bitmap(w,w);srand(
8time(0));N();while(!key[59]){while(t>0){t--;if(u>=50){k++;q++;u=0;}if(q>=15){l++
9;q=0;}if(l>=10)l=10;for(i=0;i<75;i++){s<i>[1]+=s<i>[2];if(s<i>[1]>w){s<i>[1]=0;s
10<i>[0]=R(400,0);s<i>[2]=R(5,2);j=s<i>[2]*51;s<i>[3]=makecol(j,j,j);}}i=0;while(i
11<50&&c<l*5){if(!e<i>[5]){c++;e<i>[5]=1;e<i>[4]=makecol(R(255,0),R(255,0),R(255,0
12));int d=R(3,1);if(d==1){e<i>[0]=R(w,0);e<i>[1]=-10;e<i>[2]=R(2,0);e<i>[3]=R(5,1
13);}if(d==2){e<i>[0]=-10;e<i>[1]=R(300,0);e<i>[2]=R(5,1);e<i>[3]=R(2,0);}if(d==3)
14{e<i>[0]=410;e<i>[1]=R(300,0);e<i>[2]=-R(5,1);e<i>[3]=R(2,0);}}i++;}for(i=0;i<50
15;i++){if(e<i>[5]){e<i>[0]+=e<i>[2];e<i>[1]+=e<i>[3];}if(e<i>[0]<-20||e<i>[0]>420
16||e<i>[1]<-20||e<i>[1]>400){e<i>[5]=0;c--;}}for(i=0;i<50;i++){if(e<i>[5])if(C(x-
172,y,4,5,e<i>[0]-5,e<i>[1]-5,5,5)){e<i>[5]=0;z=1;}}if(key[82])x-=4;if(key[83])x+=
184;if(key[84])y-=4;if(key[85])y+=4;if(key[18])N();if(x<10)x=10;if(x>390)x=390;if(
19y<10)y=10;if(y>390)y=390;}while(!t)rest(1);for(i=0;i<75;i++)putpixel(B,s<i>[0],s
20<i>[1],s<i>[3]);for(i=0;i<50;i++)if(e<i>[5])circlefill(B,e<i>[0],e<i>[1],5,e<i>[
214]);if(z)textprintf_centre_ex(B,font,w/2,w/2,15,-1,"GAME OVER!");if(!z){triangle
22(B,x,y-10,x+10,y+10,x-10,y+10,15);rectfill(B,x-2,y,x+2,y+5,32);}textprintf_ex(B,
23font,10,10,15,-1,"Level: %d Time: %d",l,k);blit(B,screen,0,0,0,0,w,w);//////woot
24clear_bitmap(B);if(z){i=0;while(!i){clear_keybuf();j=readkey();if((j>>8)==59)///
25return;else if((j>>8)==18){N();i=1;}}}}destroy_bitmap(B);}END_OF_MAIN()/////////

{"name":"595186","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/9\/0\/90c88f30bfdf23fdcc43fd926665e9aa.png","w":403,"h":430,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/9\/0\/90c88f30bfdf23fdcc43fd926665e9aa"}595186

This contest will be the end of me, I already have a new thingy I want to implement. Curses, programming is supposed to be boring, no? :)

edit: I actually got to level 7 and discovered a cheat which is fixed now.

Paul Pridham
Member #250
April 2000
avatar

Quote:

*B(){blit(O,screen,0,0,0,0,640,480);}
*R(c){rectfill(O,xo+j*16,yo+y*16,xo+j*16+16,yo+y*16+16,c);}

Why is everyone prefixing their K&R-style default functions with a * ? I don't see the purpose... you're returning no value (especially not a pointer to int) and wasting a character in your code.

Ted Steen
Member #9,736
April 2008
avatar

ppridham said:

Why is everyone prefixing their K&R-style default functions with a * ? I don't see the purpose... you're returning no value (especially not a pointer to int) and wasting a character in your code.

You are right, I just assumed that you needed to specify the return type, and * is smaller than void. C is not my "native language" ;)

Yay! Now we have four more characters to play with!! Olof - let's add network support!

Kikaru
Member #7,616
August 2006
avatar

Urg, I had an idea, but it was really boring compared to these... I'm starting over now. ::)

Matthew Leverton
Supreme Loser
January 1999
avatar

Tetris

{"name":"595191","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/8\/9\/8975a23dbdf433e7ee0863aff039dacd.png","w":304,"h":388,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/8\/9\/8975a23dbdf433e7ee0863aff039dacd"}595191

Download Windows Version

1#include <allegro.h> // Tetris, by Matthew Leverton
2int s[]={0xcc00cc00,0xcc00cc00,0x4e004640,0xe404c40,0xe2044c0,0x8e006440,
30xe80c440,0x2e004460,0x6c008c40,0x6c008c40,0xc6004c80,0xc6004c80,0xf004444,
40xf004444},w[24],i,q,r,y,x,R,Y,X,c,d,e=0,f=0,g;S(){return s[q*2+r/2]>>(1-r%2)*16
5;}D(){if((d=(100-e)/10)<2)d=2;};p(A,B){int s=c;for(i=16;--i>=0;s>>=1){B=(s&1)<<(
6x+i%4);if(A)w[y+i/4]|=B;else if(w[y+i/4]&B)return 1;}return 0;}z(){y=0;x=7;q=
7rand()%7;r=0;D();c=S();};main(){allegro_init();install_keyboard();set_gfx_mode(
8GFX_GDI,288,352,0,0);BITMAP *b=create_bitmap(640,480);srand(time(0));z();i=24;
9while(i--)w<i>=i>19?0x3ffff:0x3c00f;while(!key[59]){if(retrace_count>3){X=x,Y=y,
10R=r;if(!--d)y++;else{if(key[83])x++;if(key[82])x--;if(key[85]){y++;f++;}if(key[
1184])r=(r+1)%4;}c=S();if(p(0)){x=X,y=Y,r=R,c=S();if(!d){p(1);i=20;g=10;while(i--)
12{if(w<i>==0x3ffff){memmove(w+1,w,i++*4);w[0]=0x3c00f;++e;f+=g;g*=10;}}z();if(p(0
13)){rest(5000);break;}}}else if(!d||key[85])D();for(i=0;i<378;++i)rectfill(b,(i%
1418)*16,(i/18)*16,(i%18)*16+15,(i/18)*16+15,w[i/18]&1<<(i%18)?((e/10)%15)+1:0);i=
1516;while(i--){if(c&1)rectfill(b,(x+i%4)*16,(y+i/4)*16,(x+i%4)*16+15,(y+i/4)*16+
1615,3);c>>=1;}textprintf(b,font,0,340,15," Lines: %d Score: %d",e,f);blit(b,
17screen,0,0,0,0,288,352);retrace_count=0;}};}END_OF_MAIN()

Controls are a bit sluggish and scoring for pressing the down key is generous (especially if you bump against the side), but it's good enough for demo #1.

Change GFX_GDI to the constant for windowed mode if you aren't on Windows. It also assumes integers are 4 bytes.

Mokkan
Member #4,355
February 2004
avatar

Those of you making Tetris should figure out a way to use more color ;).

I'd love to try this, but I'm not sure if I could come up with anything. Perhaps I'll give it a go anyway...



Go to: