Advertisement
NovaYoshi

seizure pong

Dec 18th, 2014
269
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 7.42 KB | None | 0 0
  1. #include <stdlib.h>
  2.  
  3. int movetype;
  4. int xpos,ypos;
  5. int xpos2,ypos2;
  6. int oldxpos, oldypos;
  7. int oldxpos2, oldypos2;
  8. int forthing;
  9. int upperleft_obxpos[10];
  10. int upperleft_obypos[10];
  11. int lowerright_obxpos[10];
  12. int lowerright_obypos[10];
  13. int oldupperleft_obxpos[10];
  14. int oldupperleft_obypos[10];
  15. int oldlowerright_obxpos[10];
  16. int oldlowerright_obypos[10];
  17.  
  18. int rnd(int range);
  19. void seedrnd(void);
  20. char crnd(void);
  21.  
  22. //int movetypey;
  23. int player1score,player2score;
  24.  
  25. #define playerwidth 8
  26. #define playerheight 18//4
  27. #define bgcolor makecol(255, 255, 0)
  28. #define playerwidth2 18
  29. #define playerheight2 36//9
  30. #include <allegro.h>
  31. #define objects 10
  32. int main(void)
  33. {
  34. player1score = 0;
  35. player2score = 0;
  36. int movetypey;
  37. movetypey=1;
  38.    PALETTE pal;
  39. movetype=1;
  40.    int scancode;
  41.    int a;
  42.  
  43.    /* you should always do this at the start of Allegro programs */
  44.    if (allegro_init() != 0)
  45.       return 1;
  46.  
  47.    /* set up the keyboard handler */
  48.    install_keyboard();
  49.  
  50.    /* set a graphics mode sized 320x200 */
  51.    if (set_gfx_mode(GFX_AUTODETECT, 320, 200, 0, 0) != 0) {
  52.       if (set_gfx_mode(GFX_SAFE, 320, 200, 0, 0) != 0) {
  53.      set_gfx_mode(GFX_TEXT, 0, 0, 0, 0);
  54.      allegro_message("Unable to set any graphic mode\n%s\n", allegro_error);
  55.      return 1;
  56.       }
  57.    }
  58.  
  59.  
  60. /* load bitmaps */
  61.    BITMAP *smile1 = load_bitmap("smile3.bmp", pal);
  62.    BITMAP *smile2 = load_bitmap("smile4.bmp", pal);
  63.  
  64.  
  65.  
  66.  
  67.    /* set the color palette */
  68.    set_palette(pal);
  69.  
  70.    /* clear the screen to white */
  71.    clear_to_color(screen, makecol(rnd(255), rnd(255), rnd(255)));
  72.  
  73.    /* you don't need to do this, but on some platforms (eg. Windows) things
  74.     * will be drawn more quickly if you always acquire the screen before
  75.     * trying to draw onto it.
  76.     */
  77. //   acquire_screen();
  78.  
  79.    /* you must always release bitmaps before calling any input functions */
  80. //   release_screen();
  81.  
  82. //Startspots X and Ys
  83. xpos=20;
  84. ypos=20;
  85.  
  86. xpos2=300;
  87. ypos2=50;
  88.  
  89.  
  90. while (scancode != KEY_ESC)
  91. {
  92. clear_to_color(screen, makecol(rnd(255), rnd(255), rnd(255)));
  93.    /* don't wait for a keypress */
  94.    if (keypressed()) {
  95.       ureadkey(&scancode);
  96.    }
  97.  
  98. //Player1
  99.    oldxpos=xpos;    
  100.    oldypos=ypos;    
  101.  
  102.    if (key[KEY_UP]) {
  103.         ypos -= 2;
  104.    }
  105.    if (key[KEY_DOWN]) {
  106.         ypos += 2;
  107.    }
  108.    if (key[KEY_LEFT]) {
  109.         xpos -= 2;
  110.    }
  111.    if (key[KEY_RIGHT]) {
  112.         xpos += 2;
  113.    }
  114. //Check if out of bounds
  115. if (!key[KEY_P]) {
  116.  if(xpos > 319/2)
  117.  {
  118. xpos -= 8;
  119.  }
  120.  if(xpos < 0)
  121.  {
  122. xpos += 8;
  123.  }
  124.  if(ypos > 199)
  125.  {
  126. ypos -= 8;
  127.  }
  128.  if(ypos < 0)
  129.  {
  130. ypos += 8;
  131.  }
  132. }
  133.  
  134. //check if in objects
  135. //lowerright_obypos[10];
  136. for(forthing=0;forthing != objects;forthing ++)
  137. {
  138. if(xpos+playerwidth > upperleft_obxpos[10])
  139.  {
  140.   if(ypos+playerheight > upperleft_obypos[10])
  141.    {
  142.      if(xpos-playerwidth < lowerright_obxpos[10])
  143.        {
  144.        if(ypos-playerheight < lowerright_obypos[10])
  145.     {
  146.     xpos=oldxpos;
  147.         ypos=oldypos;
  148. movetype=1;
  149.     }
  150.        }  
  151.    }
  152.  }
  153.  
  154. //check if in players
  155. //lowerright_obypos[10];
  156.  
  157. if(xpos+playerwidth > xpos2-playerwidth)
  158.  {
  159.   if(ypos+playerheight > ypos2-playerheight)
  160.    {
  161.      if(xpos-playerwidth < xpos2+playerwidth)
  162.        {
  163.        if(ypos-playerheight < ypos2+playerheight)
  164.     {
  165.     xpos=oldxpos;
  166.         ypos=oldypos;
  167.  
  168.     }
  169.        }  
  170.    }
  171.  }
  172. }
  173.  
  174.  
  175. //Player2
  176.    oldxpos2=xpos2;    
  177.    oldypos2=ypos2;    
  178.    if (key[KEY_W]) {
  179.         ypos2 -= 2;    
  180.    }
  181.    if (key[KEY_S]) {
  182.         ypos2 += 2;
  183.    }
  184.    if (key[KEY_A]) {
  185.         xpos2 -= 2;
  186.    }
  187.    if (key[KEY_D]) {
  188.         xpos2 += 2;
  189.    }
  190.  
  191.  
  192. //Check if out of bounds
  193. if (!key[KEY_P]) {
  194.  if(xpos2 > 319)
  195.  {
  196. xpos2 -= 8;
  197.  }
  198.  if(xpos2 < 319/2)
  199.  {
  200. xpos2 += 8;
  201.  }
  202.  if(ypos2 > 199)
  203.  {
  204. ypos2 -= 8;
  205.  }
  206.  if(ypos2 < 0)
  207.  {
  208. ypos2 += 8;
  209.  }
  210. }
  211.  
  212. //check if in objects
  213. //lowerright_obypos[10];
  214. for(forthing=0;forthing != objects;forthing ++)
  215. {
  216. if(xpos2+playerwidth > upperleft_obxpos[10])
  217.  {
  218.   if(ypos2+playerheight > upperleft_obypos[10])
  219.    {
  220.      if(xpos2-playerwidth < lowerright_obxpos[10])
  221.        {
  222.        if(ypos2-playerheight < lowerright_obypos[10])
  223.     {
  224.     xpos2=oldxpos2;
  225.         ypos2=oldypos2;
  226. movetype=-1;
  227.     }
  228.        }  
  229.    }
  230.  }
  231.  
  232.  
  233. //check if in players
  234. //lowerright_obypos[10];
  235.  
  236. if(xpos2+playerwidth > xpos-playerwidth)
  237.  {
  238.   if(ypos2+playerheight > ypos-playerheight)
  239.    {
  240.      if(xpos2-playerwidth < xpos+playerwidth)
  241.        {
  242.        if(ypos2-playerheight < ypos+playerheight)
  243.     {
  244.     xpos2=oldxpos2;
  245.         ypos2=oldypos2;
  246.     }
  247.        }  
  248.    }
  249.  }
  250. }
  251.  
  252.  
  253.  
  254.  
  255.  
  256.  
  257. //Debug Info
  258. //  textprintf_ex(screen, font, 0, 0, 0, 15,
  259. //                 "(%3d,%3d) was (%3d,%3d)",
  260. //                 xpos, ypos, oldxpos, oldypos);
  261.  
  262. //Score Info
  263.   textprintf_ex(screen, font, 0, 0, 0, 15,
  264.                  "SIEZURE PONG!");
  265.   textprintf_ex(screen, font, 130, 0, 0, 15,
  266.                  "%d",player1score);
  267.   textprintf_ex(screen, font, 150, 0, 0, 15,
  268.                  "%d",player2score);
  269. //Draw Player
  270. //  putpixel(screen, xpos, ypos, makecol(0, 0, 0));
  271. //   putpixel(screen, oldxpos, oldypos, makecol(255, 255, 255));
  272. //circlefill(screen, oldxpos, oldypos, playerwidth, bgcolor);
  273. //circlefill(screen, xpos, ypos, playerwidth, makecol(0, 255, 0));
  274. //P1
  275.  
  276.  
  277.  
  278. rectfill(screen, oldxpos-playerwidth, oldypos-playerheight, oldxpos+playerwidth, oldypos+playerheight, makecol(rnd(255), rnd(255), rnd(255)));
  279. //blit(smile1, screen,
  280. //     0, 0,
  281. //     xpos-playerwidth, ypos - playerheight,
  282. //     smile1->w, smile1->h);
  283. rectfill(screen, xpos-playerwidth, ypos-playerheight, xpos+playerwidth, ypos+playerheight, makecol(rnd(255), rnd(255), rnd(255)));
  284. //P2
  285. rectfill(screen, oldxpos2-playerwidth, oldypos2-playerheight, oldxpos2+playerwidth, oldypos2+playerheight, makecol(rnd(255), rnd(255), rnd(255)));
  286. rectfill(screen, xpos2-playerwidth, ypos2-playerheight, xpos2+playerwidth, ypos2+playerheight, makecol(rnd(255), rnd(255), rnd(255)));
  287.  
  288.  
  289. //blit(smile2, screen,
  290. //     0, 0,
  291. //     xpos2-playerwidth, ypos2 - playerheight,
  292. //     smile2->w, smile2->h);
  293.  
  294.  
  295.  
  296. //movetype=1;
  297.  
  298. //Move Moving Objects
  299.  
  300. oldupperleft_obxpos[10]=upperleft_obxpos[10];
  301. oldupperleft_obypos[10]=upperleft_obypos[10];
  302. rectfill(screen, oldupperleft_obxpos[10], oldupperleft_obypos[10], oldupperleft_obxpos[10]+9, oldupperleft_obypos[10]+9, makecol(rnd(255), rnd(255), rnd(255)));
  303.  
  304. //if(movetype != 2)
  305. //{
  306. upperleft_obxpos[10]=upperleft_obxpos[10]+movetype;
  307. //upperleft_obypos[10]=50;
  308. upperleft_obypos[10]=upperleft_obypos[10]+movetypey;
  309. //}
  310.  
  311.  
  312.  
  313. if(upperleft_obxpos[10] > 320-9)
  314. {
  315. upperleft_obxpos[10]=320/2;
  316. upperleft_obypos[10]=200/2;
  317. player1score++;
  318. //movetype=-1;
  319. }
  320.  
  321. if(upperleft_obxpos[10] < 0)
  322. {
  323. upperleft_obxpos[10]=320/2;
  324. upperleft_obypos[10]=200/2;
  325. //movetype=1;
  326. player2score++;
  327. }
  328. if(upperleft_obypos[10] > 191)
  329. {
  330. //upperleft_obxpos[10]=0;
  331. //upperleft_obypos[10]=0;
  332. movetypey=-1;
  333. }
  334. if(upperleft_obypos[10] < 0)
  335. {
  336. //upperleft_obxpos[10]=0;
  337. //upperleft_obypos[10]=0;
  338. movetypey=1;
  339. }
  340. rectfill(screen, 160, 0, 160, 200, makecol(rnd(255), rnd(255), rnd(255)));
  341.  
  342. 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
  343. lowerright_obxpos[10]=upperleft_obxpos[10]+9;
  344. lowerright_obypos[10]=upperleft_obypos[10]+9;
  345.  
  346.    rest(10);
  347. }
  348.  
  349. //   readkey();
  350.    return 0;
  351. }
  352.  
  353.  
  354. END_OF_MAIN()
  355.  
  356. int rnd(int range)
  357. {
  358. int r;
  359. r=rand()%range;
  360. return(r);
  361. }
  362. void seedrnd(void)
  363. {
  364. srand((unsigned)time(NULL));
  365. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement