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
Per Larsson
Member #276
April 2000
avatar

It's Friday night and I don't have a party to go to... :( And it seems TINS isn't happening anytime soon.

So, what to do during these most dire circumstances? A game coding competition of course! Following in the footsteps of the most excellent 2004 Allegro ScreenHack (thread), I suggest another 80x25 programming contest.

Rules (same as back in 2004)
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.

I'm going to start coding my entry now, and will be delighted if anyone decides to join in.

Good luck! ;D

________________________
Guichan!

Kikaru
Member #7,616
August 2006
avatar

Set a deadline, and I'll try for something.
Other clarifications:

Quote:

will compile on its own (along with a full complement of Allegro/system headers, that is).

Does this mean "no libraries but Allegro" or something of the sort? If so, then are standard C++ libs like vector okay?

Per Larsson
Member #276
April 2000
avatar

Yep, vector will be fine. You can use all standard C and C++ stuff and allegro, but no other libraries.

Deadline is, umm, whenever people loose interest in this thread. It took about a month in the 2004 competition. :)

________________________
Guichan!

CGamesPlay
Member #2,559
July 2002
avatar

Sweet! I remember wanting to add syntax highlighting to my previous entry, but never getting around to it. Also it is 2008.

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

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

Per Larsson
Member #276
April 2000
avatar

checks watch

Holy shit, you're right!

EDIT:
My entry, version 1. I'll try to add some sound tomorrow :)

(Edit: Newer version below)

1#include <allegro.h>//////////////////////////////////////////////Untangle v1.0
2#include <math.h>////////////////////////////////////////////////By Per Larsson
3#define p(i) x<i>,y<i>/////////////////////////////////////////////////////////
4x[99],y[99],e[99][99],w=457;*c(a,b){return a<b?e[a]+b:e<b>+a;}_(a,b,c){return b
5<c?a>=b&&a<=c:a>=c&&a<=b;}q(w,e,r,t,y,u,i,o){int A=t-e,B=w-r,C=A*w+B*e,D=o-u,E=
6y-i,F=D*y+E*u,d=A*E-D*B,X=(E*C-B*F),Y=(A*F-D*C);return d?_(X/d,w,r)&&_(Y/d,e,t)
7&&_(X/d,y,i)&&_(Y/d,u,o):0;}main(){int l,i,I,j,J,f,F,a,b,s=-1,X,Y,H,h;BITMAP*B;
8allegro_init();set_gfx_mode(GFX_SAFE,w,w,0,0);B=create_bitmap(w,w);*c(1,2)=*c(2
9,3)=1;install_keyboard();install_mouse();text_mode(-1);*c(0,1)=*c(0,2)=*c(0,3)=
10*c(1,3)=1;for(l=4;l<99;l++){for(i=0;i<l;i++){double a=(i*6.3/l)+1;x<i>=cos(a)*w
11/3+w/2;y<i>=sin(a)*w/3+w/2;}do{F=0;key[KEY_ESC]?exit(0):0;clear_to_color(B,15);
12for(i=0;i<l;i++){for(j=0;j<l;j++){f=0;if(*c(j,i)){for(I=0;I<l;I++)for(J=0;J<l;J
13++)f|=j!=I&&i!=J&&i!=I&&j!=J&&*c(I,J)&&q(p(i),p(j),p(I),p(J));for (a=-1;a<2;a++
14)for (b=-1;b<2;b++)line(B,a+p(i)+b,a+p(j)+b,f?12:10);}F|=f;}}for(i=0;i<l;i++){
15circlefill(B,p(i),8,0);circlefill(B,p(i),6,s==i?7:8);s = mouse_b?s:-1;if(mouse\
16_b&&s < 0 && _(mouse_x-x<i>,-7,7) && _(mouse_y-y<i>,-7,7))s = i;}if(s>=0){x[s]=
17mouse_x;y[s]=mouse_y;}textprintf(B,font,10,10,0,"Level %d",l-3);draw_sprite(B,
18mouse_sprite,mouse_x,mouse_y);blit(B,screen,0,0,0,0,w,w);}while(F||mouse_b);H=0
19;for(j=0;j<2000;j++){h=0;x[l]=rand()%w*2-w/2;y[l]=rand()%w*2-w/2;for(i=0;i<l;
20i++){f=0;for(I=0;I<l;I++)for(J=0;J<l;J++)f|=l!=I&&i!=J&&i!=I&&l!=J&&*c(I,J)&&q(
21p(i),p(l),p(I),p(J));h+=1-f;}if (h>H){H=h;X=x[l];Y=y[l];}}x[l]=X;y[l]=Y;for(i=0
22;i<l;i++){f=0;for(I=0;I<l;I++)for(J=0;J<l;J++)f|=l!=I&&i!=J&&i!=I&&l!=J&&*c(I,J
23)&&q(p(i),p(l),p(I),p(J));*c(i,l)=1-f;}}}END_OF_MAIN();/*What?? Wasted space?*/
24///////////////////////////////////////////////////////////////////////////////

________________________
Guichan!

blargmob
Member #8,356
February 2007
avatar

That's hilarious. Now make is scroll and you got matrix codes. 8-)

---
"No amount of prayer would have produced the computers you use to spread your nonsense." Arthur Kalliokoski

kenmasters1976
Member #8,794
July 2007

Untangle v1.0 By Per Larsson is crashing here...

BAF
Member #2,981
December 2002
avatar

2007?

[edit]
Erm, it was already mentioned.

OnlineCop
Member #7,919
October 2006
avatar

I've only been able to get to Level 5 EDIT2:Level 6 EDIT3:Level 7. Where did you get this game (or game idea) from, Per?

EDIT1: And I was able to compile (and run) it right out of the box:
gcc game.c -o game.exe

Per Larsson
Member #276
April 2000
avatar

I remember seeing it briefly at the end of this little clip, and i thought it would be small enough to squeeze into a screenhack. It's also quite fun... and frustrating. I got to level 11 yesterday :).

________________________
Guichan!

Seppl
Member #4,656
May 2004
avatar

Cool game! Fun and addictive. Made it till level 12.

I first misunderstood the idea of this competition and wondered why this game is using real graphic instead of ASCII art on SCREEN 1 or so... OK, i got it. It's not the graphic to fit into 80x25 but the code. ;D

__________________________________
All you need is lunch - The Rutles

Per Larsson
Member #276
April 2000
avatar

Okay, version 2.0 is ready.

I've added a (crappy) sound effect and tweaked the difficulty a bit by randomly removing a few edges before each level which makes the game more interesting, and a bit easier.

This version uses DIGI_DIRECTX(0) as an audio driver, since I for some reason got choppy playback with DIGI_AUTODETECT. If you're not on windows you might want to change this. You should be able to find it even in this mess.

1#include <allegro.h>///////////////////////////////////////////////Untangle v2.0
2#define p(i) x<i>,y<i>////////////////////////////////////////////By Per Larsson
3x[99],y[99],e[99][99],w=600,l;*c(a,b){return a<b?e[a]+b:e<b>+a;}_(a,b,c){return
4b<c?a>=b&&a<=c:a>=c&&a<=b;}q(w,e,r,t,y,u,i,o){int A=t-e,B=w-r,C=A*w+B*e,D=o-u,E=
5y-i,F=D*y+E*u,d=A*E-D*B,X=(E*C-B*F),Y=(A*F-D*C);return d?_(X/d,w,r)&&_(Y/d,e,t)
6&&_(X/d,y,i)&&_(Y/d,u,o):0;}M(i,j){int I,J,f=0;for(I=0;I<l;I++)for(J=0;J<l;J++)f
7+=j!=I&&i!=J&&i!=I&&j!=J&&*c(I,J)&&q(p(i),p(j),p(I),p(J));return f;}main(){int i
8,I,j,J,f,F,a,b,s=-1,X,Y,H,h;BITMAP*B;SAMPLE*S;allegro_init();*c(0,1)=*c(0,2)=*c(
90,3)=1;set_gfx_mode(GFX_AUTODETECT_WINDOWED,w,w,0,0);install_sound(DIGI_DIRECTX(
100),MIDI_NONE,0);B=create_bitmap(w,w);install_keyboard();install_mouse();*c(2,3)=
11*c(1,2)=*c(1,3)=1;text_mode(-1);S=create_sample(8,0,9999,9999);for(i=0;i<9999;i
12++){((unsigned char*)S->data)<i>=(((i+(fixsin(i<<13)>>13))%100+(i)%152)*i)/9000;
13}for(l=4;l<99;l++){play_sample(S,255,55,1600,0);play_sample(S,255,200,1604,0);
14for(i=0;i<l;i++){x<i>=((fixcos((i<<24)/l)*w/3)>>16)+w/2;y<i>=((fixsin((i<<24)/l)
15*w/3)>>16)+w/2;}do{F=0;key[KEY_ESC]?exit(0):0;clear_to_color(B,15);for(i=0;i<l;i
16++){for(j=0;j<l;j++){f=0;if(*c(j,i)){f=M(i,j);for(a=-1;a<2;a++)for(b=-1;b<2;b++)
17line(B,a+p(i)+b,a+p(j)+b,f?12:10);}F|=f;}}for(i=0;i<l;i++){circlefill(B,p(i),8,0
18);circlefill(B,p(i),6,s==i?7:8);s=mouse_b?s:-1;if(mouse_b&&s<0&&_(mouse_x-x<i>,-
197,7)&&_(mouse_y-y<i>,-7,7))s=i;}if(s>=0){x[s]=mouse_x;y[s]=mouse_y;}textprintf(B
20,font,10,10,0,"Level %d",l-3);draw_sprite(B,mouse_sprite,mouse_x,mouse_y);blit(B
21,screen,0,0,0,0,w,w);}while(F||mouse_b);H=0;for(j=0;j<2000;j++){h=0;x[l]=rand()%
22w*2-w/2;y[l]=rand()%w*2-w/2;for(i=0;i<l;i++){h+=M(i,l)==0;}if(h>H){H=h;X=x[l];Y=
23y[l];}}x[l]=X;y[l]=Y;for(i=0;i<l;i++){*c(i,l)=M(i,l)==0;*c(rand()%l,rand()%l)=0;
24}}}END_OF_MAIN();///////////////////////////////////////////////////////////////

Is anyone else coding or am I the only one doing this? :) Anyway, I encourage everyone to try coding up a screenful of code, it's not as hard as it looks (and it's fun!).

________________________
Guichan!

kenmasters1976
Member #8,794
July 2007

Quote:

EDIT1: And I was able to compile (and run) it right out of the box:
gcc game.c -o game.exe

What?... not even -lalleg?...

Doesn't matter. Version 2 is working fine. I don't know what was wrong before.

Kikaru
Member #7,616
August 2006
avatar

I'm trying to find time to do something. I also need an idea of what to do.

[edit]
In my compiler, It needs some variable type definitions.
Heck, I can't make it compile at all right now. I included alleg.h.

Seppl
Member #4,656
May 2004
avatar

1#include <allegro.h>///////////////////////////////////////////////////////////
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);
11set_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,
19font,20,50,w,-1,"game over score: %i",tt);blit(B,screen,0,0,0,0,400,300);
20clear_keybuf();while(!key[KEY_ESC]);}END_OF_MAIN()

OK, now I'll really start preparing for A-levels...

__________________________________
All you need is lunch - The Rutles

Jeff Bernard
Member #6,698
December 2005
avatar

80x25, eh? I'll put together something next weekend. I've got exams this week.

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

MiquelFire
Member #3,110
January 2003
avatar

Suggestion, put a suggested file name to use in the comment area

---
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

Kikaru
Member #7,616
August 2006
avatar

Well, I'm still trying to think up an idea. This always takes a while. :(

Timorg
Member #2,028
March 2002

I am working on something, but its slow going, but I am definitely in for this. :D

____________________________________________________________________________________________
"c is much better than c++ if you don't need OOP simply because it's smaller and requires less load time." - alethiophile
OMG my sides are hurting from laughing so hard... :D

netcat
Member #6,097
August 2005

Decided to try my hands at this.. The below code generates a random "dungeon" in which you can walk around and.. not much more. :P Screenshot is attached.

1#include <allegro.h>
2#define P(a,b) if(a>1&&b>1&&a<79&&b<24)
3BITMAP *bf;char m[25][80];char fog[25][80];int px, py;void a(int x,int y,int
4w,int h){int _x, _y;for(_y=y;_y<y+h;_y++)for(_x=x;_x<x+w;_x++)P(_x,_y)m[_y][
5_x]=1;}void b(int x,int y,int l,int d){int _x=x,_y=y;if(d==0){for(_x=x;_x<x+
6l;_x++)P(_x,_y)m[_y][_x]=1;}else if(d==1){for(_y=y-l;_y<y;_y++)P(_x,_y)m[_y]
7[_x]=1;}else if(d==2){for(_x=x-l;_x<x;_x++)P(_x,_y)m[_y][_x]=1;}else if(d==3
8){for(_y=y;_y<y+l;_y++)P(_x,_y)m[_y][_x]=1;}}void g(){int r=10+rand()%10;int
9n;int x=1+rand()%79;int y=1+rand()%24;for(n=0;n<r;n++){int w=4+rand()%4;int
10h=4+rand()%4;int d=rand()%4;int l=4+rand()%12;a(x,y,w,h);b((!d)?x+w:(d==2)?x
11:x+rand()%w,(d==1)?y:(d==2)?y+h:y+rand()%h,l,d);int lx=x;int ly=y;x=(!d)?x+l
12:(d==2)?x-l:x-rand()%w;y=(d==3)?y+l:(d==1)?y-l:y-rand()%h;if (x<1||x>79||y<1
13||y>24){x=1+rand()%79;y=1+rand()%24;while(lx!=x){lx=(lx<x)?lx+1:lx-1;m[ly][
14lx]=1;}while(ly!=y){ly=(ly<y)?ly+1:ly-1;m[ly][lx]=1;}}}do{px=rand()%80;py=r\
15and()&25;}while(m[py][px]!=1);}void c(){clear_bitmap(bf);int x,y;for(y=0;y<
1625;y++)for(x=0;x<80;x++)if(fog[y][x])textout_ex(bf,font,((m[y][x]==1)?".":
17"#"),x*8,y*8,(fog[y][x]==1)?24:18,-1);textout_ex(bf,font,"@",px*8,py*8,14,-1
18);blit(bf,screen,0,0,0,0,640,240);}main(){allegro_init();srand(time(NULL));
19memset(m,0,2000);memset(fog,0,2000);install_keyboard();set_gfx_mode(GFX_AUT\
20ODETECT_WINDOWED,640,240,0,0);bf=create_bitmap(640, 240);g();while(!key[KEY\
21_ESC]){int x,y;for(y=0;y<25;y++)for(x=0;x<80;x++)if(fog[y][x]==1)fog[y][x]=2
22;for(y=py-6;y<=py+6;y++)for(x=px-6;x<=px+6;x++)if((x>=0&&x<80&&y>=0&&y<25)&&
23(px-x)*(px-x)+(py-y)*(py-y)<=4)fog[y][x]=1;c();int tx=px,ty=py;int k=readkey
24()>>8;if(k==KEY_RIGHT)px++;if(k==KEY_LEFT)px--;if(k==KEY_DOWN)py++;if(k==KE\
25Y_UP)py--;if(m[py][px]!=1){px=tx;py=ty;}}}END_OF_MAIN()

kenmasters1976
Member #8,794
July 2007

I decided to take my shot on this. It's my first time and I thought I could manage to get a working Tetris clone on a 80x25 code file, so I dedicated an afternoon to work on it, but turns out I was wrong.

It seems I can't get it under 34 lines without sacrificing gameplay and leaving it heavily crippled.

I'm taking a rest on it. Maybe I'll come back later and try to strip it down.

Kikaru
Member #7,616
August 2006
avatar

I still need a game idea before I start coding.

Seppl
Member #4,656
May 2004
avatar

you don't. look at me

__________________________________
All you need is lunch - The Rutles

kenmasters1976
Member #8,794
July 2007

OK, here it is. I had never coded a Tetris before 'cause I've always believed that the world doesn't need yet another Tetris clone, but a 80x25 compo seemed like a perfect excuse.

I had to sacrifice the blinking for removing completed lines and the next piece preview which was a terrible lost, but I decided to rather sacrifice that than messing with the controls.

I don't think I'm going to try to do something like this again. It was a pain to make it fit and I don't think it can be pushed much more further.

1#include <allegro.h> // SHTetris.c
2#define B() blit(off,screen,0,0,0,0,640,480) ///////////////////////////////
3#define RF(xo,yo,x,y,c) rectfill(off,xo+x*16,yo+y*16,xo+x*16+16,yo+y*16+16,c)
4int F[25];int ps[8][8]={1,1,1,241,1,1,1,241,0,32,39,52,0,48,17,23,0,16,20,55,0,
548,39,33,0,16,54,35,0,16,54,35,0,32,51,22,0,32,51,22,0,2,35,114,0,1,115,33,0,0,
651,51,0,0,51,51};int i,j,p,np=0,m[4],xcm[4],x,y,nx,lk,pa=FALSE,o,no=0,ct,lx,lv,
7c=0,xc=0,oc=0,cl,ctl,ksp,kl,kr,kap,lt,rt,ltl,rtl;BITMAP *off;int uF(){for(i=23;
8i>0;i--){if((F<i>&0xFFFF)==0xFFFF)for(j=i;j>=1;j--)F[j]=F[j-1];}} int DP(int xo
9,int yo){for(j=0;j<4;j++)for(i=0;i<16;i++){if(m[j]&(1<<i))RF(xo,yo,i,(y-j-1),
100x0000FF);}} int DF() {for(j=0;j<25;j++)for(i=0;i<16;i++){if(F[j]&(1<<i))RF(0,0
11,i,j,0xFF0000);else RF(0,0,i,j,0xFFFF00);}}int main(){srand(time(NULL));
12allegro_init();set_color_depth(24);set_gfx_mode(GFX_AUTODETECT_WINDOWED,640,480
13,0,0);install_keyboard();off=create_bitmap(640,480);F[24]=0xFFFFFFFF;while(!key
14[KEY_ESC]){if(!pa){p=np;np=rand()%7;o=no;no=rand()%4;ct=0;pa=TRUE;x=6;nx=6;y=0;
15cl=10;ctl=32;}lv=(o<2)?3:7;lx=(o%2==0)?0:1;for(i=0;i<4;i++){m<i>=ps[p][lv-i];m[
16i]=(lx==0)?(m<i>&0xF0)>>4:m<i>&0x0F;}if(key[KEY_LEFT]){lt++;if(lt>ltl){lt=0;nx=
17x-1;ltl/=2;if(ltl<4)ltl=4;}}if(key[KEY_RIGHT]){rt++;if (rt>rtl){rt=0;nx=x+1;rtl
18/=2;if(rtl<4)rtl=4;}}if(key[KEY_SPACE]&&!ksp){o=(o+1)%4;ksp=1;}if(!key[
19KEY_SPACE])ksp=0;if(!key[KEY_LEFT]){ltl=32;lt=31;}if(!key[KEY_RIGHT]){rtl=32;rt
20=31;}if(key[KEY_DOWN]){cl=1;ctl=1;}if(!key[KEY_DOWN]){cl=10;ctl=32;}for(i=0;i<4
21;i++){xcm<i>=m<i><<nx;}if(((F[y-1]&xcm[0])==0)&&((F[y-2]&xcm[1])==0)&&((F[y-3]&
22xcm[2])==0)&&((F[y-4]&xcm[3])==0)){x=nx;}for(i=0;i<4;i++){m<i>=m<i><<x;}if(((F[
23y]&m[0])==0)&&((F[y-1] & m[1])==0)&&((F[y-2]&m[2])==0)&&((F[y-3]&m[3])==0)){ct=
240;c++;if(c>cl){y++;c=0;}}else{ct++;}if(ct>ctl){for(i=0;i<4;i++){F[y-i-1]=F[y-i-
251]|m<i>;}pa=FALSE;ct=0;}DF();DP(0,0);uF();B();rest(15);}}END_OF_MAIN()

KEYS: LEFT, RIGHT, DOWN, SPACE

http://www.allegro.cc/files/attachment/595142

---------------------------------------
PS. The game has some flaws, I know it.

[EDIT]: Screenshot attached.

Michael Jensen
Member #2,870
October 2002
avatar

Quote:

It seems I can't get it under 34 lines without sacrificing gameplay and leaving it heavily crippled.

Didn't ML put together a working tetris game for the 20 lines of code contest? IIRC, that contest only allowed 20 lines with one semi colon per line. :P

Edit: I think someone even did Pac Man! ;D



Go to: