games
pages
posts

iconicejunk.c

2000-01-01

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