All pastes #1005332 Raw Edit

Allegro Pong Screenhack

public c v1 · immutable
#1005332 ·published 2008-05-02 19:45 UTC
rendered paste body
#include <allegro.h>// Pong, by Michael Swiger ////////////////////////////////#include <time.h>//////////////////////////////////////////////////////////////#define W makecol(255,255,255)/////////////////////////////////////////////////volatile long s;void isc(){s++;}END_OF_FUNCTION(isc) int main(){allegro_init();install_keyboard();install_timer();set_color_depth(desktop_color_depth());/////set_gfx_mode(GFX_AUTODETECT_WINDOWED,640,480,0,0);BITMAP * b=create_bitmap(640,480);srand(time(0));install_int_ex(isc,BPS_TO_TIMER(50)); r: int p1s=0,p2s=0,p;while(1){textout_centre_ex(screen,font,"(1)1 Player, (2)2 Players, (ESC) Quit",320,240,W,0);int v=readkey();if(v>>8==KEY_1){p=1;goto s;};if(v>>8==KEY_2) {p=2;goto s;}if(v>>8==KEY_ESC)exit(0);} s: float bx=310,by=230,pbx,pby,vbx,vby,pvbx,pvby,i[4]={1,-1,0.5,-0.5};int p1x=10,p1y=205,p2x=610,p2y=205,t=rand()%490;vbx=i[rand()%4];vby=i[rand()%4]; while(1){bx+=vbx;by+=vby;if(bx<=30&&p1y+70>=by&&p1y<=by&&p1x<=bx&&p1x+20>=bx){vbx=-vbx;vbx+=0.15;bx=p1x+20;t=rand()%490;}if(bx+20>=610&&p2y+70>=by&&p2y<=by&&p2x<=bx+20&&p2x+20>=bx+20){vbx=-vbx;vbx-=0.15;bx=p2x-20;}if(bx+20<=0){p2s++;goto s;} if(bx>=640){p1s++;goto s;}if(by<=0){vby=-vby;}if(by>=460){vby=-vby;}for(pbx=bx,pby=by,pvbx=vbx,pvby=vby;pbx<=610&&pbx>=30;pbx+=pvbx){if((pvby<0&&pby<=0)||(pvby>0&&pby>=620))pvby=-pvby;pby+=pvby;}while(s>0){if(key[KEY_UP]&&p1y>1)p1y-=6;if(key[KEY_DOWN]&&p1y<409)p1y+=6;if(key[KEY_W]&&p2y>1&&p==2)p2y-=6;if(key[KEY_S]&&p2y<409&&p==2)p2y+=6;if(vbx>0&&p==1) {if(p2y+35>pby&&p2y>0&&bx>=t)p2y-=6;if(p2y+35<pby&&p2y<410&&bx>=t)p2y+=6;}else if(p==1){if(p2y>205)p2y-=6; if(p2y<205)p2y+=6;} if(key[KEY_ESC]){clear_keybuf(); clear(screen ); goto r; } s--;} textprintf_ex (b,font,100,2,W,0,"P1 Score: %d", p1s);textprintf_ex(b,font,450,2,W,0,"P2 Score: %d",p2s); rectfill (b,p1x,p1y,p1x+20,p1y+70,W);rectfill(b,p2x,p2y,p2x+20,p2y+70,W); rectfill(b,bx,by,bx+20,by+20,W);blit(b,screen,0,0,0,0,640,480);clear(b);}allegro_exit();return 0;}END_OF_MAIN()