Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- int movetype;
- int xpos,ypos;
- int xpos2,ypos2;
- int oldxpos, oldypos;
- int oldxpos2, oldypos2;
- int forthing;
- int upperleft_obxpos[10];
- int upperleft_obypos[10];
- int lowerright_obxpos[10];
- int lowerright_obypos[10];
- int oldupperleft_obxpos[10];
- int oldupperleft_obypos[10];
- int oldlowerright_obxpos[10];
- int oldlowerright_obypos[10];
- int rnd(int range);
- void seedrnd(void);
- char crnd(void);
- //int movetypey;
- int player1score,player2score;
- #define playerwidth 8
- #define playerheight 18//4
- #define bgcolor makecol(255, 255, 0)
- #define playerwidth2 18
- #define playerheight2 36//9
- #include <allegro.h>
- #define objects 10
- int main(void)
- {
- player1score = 0;
- player2score = 0;
- int movetypey;
- movetypey=1;
- PALETTE pal;
- movetype=1;
- int scancode;
- int a;
- /* you should always do this at the start of Allegro programs */
- if (allegro_init() != 0)
- return 1;
- /* set up the keyboard handler */
- install_keyboard();
- /* set a graphics mode sized 320x200 */
- if (set_gfx_mode(GFX_AUTODETECT, 320, 200, 0, 0) != 0) {
- if (set_gfx_mode(GFX_SAFE, 320, 200, 0, 0) != 0) {
- set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
- allegro_message("Unable to set any graphic mode\n%s\n", allegro_error);
- return 1;
- }
- }
- /* load bitmaps */
- BITMAP *smile1 = load_bitmap("smile3.bmp", pal);
- BITMAP *smile2 = load_bitmap("smile4.bmp", pal);
- /* set the color palette */
- set_palette(pal);
- /* clear the screen to white */
- clear_to_color(screen, makecol(rnd(255), rnd(255), rnd(255)));
- /* you don't need to do this, but on some platforms (eg. Windows) things
- * will be drawn more quickly if you always acquire the screen before
- * trying to draw onto it.
- */
- // acquire_screen();
- /* you must always release bitmaps before calling any input functions */
- // release_screen();
- //Startspots X and Ys
- xpos=20;
- ypos=20;
- xpos2=300;
- ypos2=50;
- while (scancode != KEY_ESC)
- {
- clear_to_color(screen, makecol(rnd(255), rnd(255), rnd(255)));
- /* don't wait for a keypress */
- if (keypressed()) {
- ureadkey(&scancode);
- }
- //Player1
- oldxpos=xpos;
- oldypos=ypos;
- if (key[KEY_UP]) {
- ypos -= 2;
- }
- if (key[KEY_DOWN]) {
- ypos += 2;
- }
- if (key[KEY_LEFT]) {
- xpos -= 2;
- }
- if (key[KEY_RIGHT]) {
- xpos += 2;
- }
- //Check if out of bounds
- if (!key[KEY_P]) {
- if(xpos > 319/2)
- {
- xpos -= 8;
- }
- if(xpos < 0)
- {
- xpos += 8;
- }
- if(ypos > 199)
- {
- ypos -= 8;
- }
- if(ypos < 0)
- {
- ypos += 8;
- }
- }
- //check if in objects
- //lowerright_obypos[10];
- for(forthing=0;forthing != objects;forthing ++)
- {
- if(xpos+playerwidth > upperleft_obxpos[10])
- {
- if(ypos+playerheight > upperleft_obypos[10])
- {
- if(xpos-playerwidth < lowerright_obxpos[10])
- {
- if(ypos-playerheight < lowerright_obypos[10])
- {
- xpos=oldxpos;
- ypos=oldypos;
- movetype=1;
- }
- }
- }
- }
- //check if in players
- //lowerright_obypos[10];
- if(xpos+playerwidth > xpos2-playerwidth)
- {
- if(ypos+playerheight > ypos2-playerheight)
- {
- if(xpos-playerwidth < xpos2+playerwidth)
- {
- if(ypos-playerheight < ypos2+playerheight)
- {
- xpos=oldxpos;
- ypos=oldypos;
- }
- }
- }
- }
- }
- //Player2
- oldxpos2=xpos2;
- oldypos2=ypos2;
- if (key[KEY_W]) {
- ypos2 -= 2;
- }
- if (key[KEY_S]) {
- ypos2 += 2;
- }
- if (key[KEY_A]) {
- xpos2 -= 2;
- }
- if (key[KEY_D]) {
- xpos2 += 2;
- }
- //Check if out of bounds
- if (!key[KEY_P]) {
- if(xpos2 > 319)
- {
- xpos2 -= 8;
- }
- if(xpos2 < 319/2)
- {
- xpos2 += 8;
- }
- if(ypos2 > 199)
- {
- ypos2 -= 8;
- }
- if(ypos2 < 0)
- {
- ypos2 += 8;
- }
- }
- //check if in objects
- //lowerright_obypos[10];
- for(forthing=0;forthing != objects;forthing ++)
- {
- if(xpos2+playerwidth > upperleft_obxpos[10])
- {
- if(ypos2+playerheight > upperleft_obypos[10])
- {
- if(xpos2-playerwidth < lowerright_obxpos[10])
- {
- if(ypos2-playerheight < lowerright_obypos[10])
- {
- xpos2=oldxpos2;
- ypos2=oldypos2;
- movetype=-1;
- }
- }
- }
- }
- //check if in players
- //lowerright_obypos[10];
- if(xpos2+playerwidth > xpos-playerwidth)
- {
- if(ypos2+playerheight > ypos-playerheight)
- {
- if(xpos2-playerwidth < xpos+playerwidth)
- {
- if(ypos2-playerheight < ypos+playerheight)
- {
- xpos2=oldxpos2;
- ypos2=oldypos2;
- }
- }
- }
- }
- }
- //Debug Info
- // textprintf_ex(screen, font, 0, 0, 0, 15,
- // "(%3d,%3d) was (%3d,%3d)",
- // xpos, ypos, oldxpos, oldypos);
- //Score Info
- textprintf_ex(screen, font, 0, 0, 0, 15,
- "SIEZURE PONG!");
- textprintf_ex(screen, font, 130, 0, 0, 15,
- "%d",player1score);
- textprintf_ex(screen, font, 150, 0, 0, 15,
- "%d",player2score);
- //Draw Player
- // putpixel(screen, xpos, ypos, makecol(0, 0, 0));
- // putpixel(screen, oldxpos, oldypos, makecol(255, 255, 255));
- //circlefill(screen, oldxpos, oldypos, playerwidth, bgcolor);
- //circlefill(screen, xpos, ypos, playerwidth, makecol(0, 255, 0));
- //P1
- rectfill(screen, oldxpos-playerwidth, oldypos-playerheight, oldxpos+playerwidth, oldypos+playerheight, makecol(rnd(255), rnd(255), rnd(255)));
- //blit(smile1, screen,
- // 0, 0,
- // xpos-playerwidth, ypos - playerheight,
- // smile1->w, smile1->h);
- rectfill(screen, xpos-playerwidth, ypos-playerheight, xpos+playerwidth, ypos+playerheight, makecol(rnd(255), rnd(255), rnd(255)));
- //P2
- rectfill(screen, oldxpos2-playerwidth, oldypos2-playerheight, oldxpos2+playerwidth, oldypos2+playerheight, makecol(rnd(255), rnd(255), rnd(255)));
- rectfill(screen, xpos2-playerwidth, ypos2-playerheight, xpos2+playerwidth, ypos2+playerheight, makecol(rnd(255), rnd(255), rnd(255)));
- //blit(smile2, screen,
- // 0, 0,
- // xpos2-playerwidth, ypos2 - playerheight,
- // smile2->w, smile2->h);
- //movetype=1;
- //Move Moving Objects
- oldupperleft_obxpos[10]=upperleft_obxpos[10];
- oldupperleft_obypos[10]=upperleft_obypos[10];
- rectfill(screen, oldupperleft_obxpos[10], oldupperleft_obypos[10], oldupperleft_obxpos[10]+9, oldupperleft_obypos[10]+9, makecol(rnd(255), rnd(255), rnd(255)));
- //if(movetype != 2)
- //{
- upperleft_obxpos[10]=upperleft_obxpos[10]+movetype;
- //upperleft_obypos[10]=50;
- upperleft_obypos[10]=upperleft_obypos[10]+movetypey;
- //}
- if(upperleft_obxpos[10] > 320-9)
- {
- upperleft_obxpos[10]=320/2;
- upperleft_obypos[10]=200/2;
- player1score++;
- //movetype=-1;
- }
- if(upperleft_obxpos[10] < 0)
- {
- upperleft_obxpos[10]=320/2;
- upperleft_obypos[10]=200/2;
- //movetype=1;
- player2score++;
- }
- if(upperleft_obypos[10] > 191)
- {
- //upperleft_obxpos[10]=0;
- //upperleft_obypos[10]=0;
- movetypey=-1;
- }
- if(upperleft_obypos[10] < 0)
- {
- //upperleft_obxpos[10]=0;
- //upperleft_obypos[10]=0;
- movetypey=1;
- }
- rectfill(screen, 160, 0, 160, 200, makecol(rnd(255), rnd(255), rnd(255)));
- rectfill(screen, upperleft_obxpos[10], upperleft_obypos[10], upperleft_obxpos[10]+9, upperleft_obypos[10]+9, makecol(rnd(255), rnd(255), rnd(255))); //draw ball
- lowerright_obxpos[10]=upperleft_obxpos[10]+9;
- lowerright_obypos[10]=upperleft_obypos[10]+9;
- rest(10);
- }
- // readkey();
- return 0;
- }
- END_OF_MAIN()
- int rnd(int range)
- {
- int r;
- r=rand()%range;
- return(r);
- }
- void seedrnd(void)
- {
- srand((unsigned)time(NULL));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement