Advertisement
Guest User

pong_ndless_buffer_1

a guest
Apr 19th, 2012
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 5.35 KB | None | 0 0
  1. #include <os.h>
  2. #include <nGUI.h>
  3. #include <nGEO.h>
  4. #include <nMATHS.h>
  5.  
  6. int randnum(int s); //making my own temporary random function
  7.  
  8. int main()
  9. {
  10.     // Create a new screen buffer
  11.     ScreenBuffer buffer = GetNewScreenBuffer();
  12.  
  13.     int x, y, xvel = -256, yvel = 0, l, r, players = 0, seed = 0, die = 0, lmov = 0, rmov = 0, lscore = 0, rscore = 0, ran;
  14.     Color green = RGB(0, 255, 0);
  15.     Color black = RGB(0, 0, 0);
  16.     l = SCREEN_HEIGHT / 2 - 15;
  17.     r = l;
  18.     x = SCREEN_WIDTH * 128;
  19.     y = SCREEN_HEIGHT * 128;
  20.     clearScreen(black, buffer);
  21.     drawStr(1, 0,
  22.             "\n                  PONG\n\n"
  23.             "Created by Epic7\n"
  24.             "Using nRGBlib\n\n"
  25.             "Multiplayer Controls:\n"
  26.             "   - Player 1 up   : 9\n"
  27.             "   - Player 1 down : 3\n"
  28.             "   - Player 2 up   : 7\n"
  29.             "   - Player 2 down : 1\n"
  30.             "Singleplayer Controls:\n"
  31.             "   - Player 1 Up   : 8\n"
  32.             "   - Player 1 Down : 2\n\n"
  33.             "Push Ctrl to Start Multiplayer\n"
  34.             "Push Tab to Start Singleplayer", 1, 1, green, buffer);
  35.     display(buffer);
  36.     while(players  == 0)
  37.     {
  38.         seed++;
  39.         if(isKeyPressed(KEY_NSPIRE_CTRL))
  40.         {
  41.             players = 2;
  42.         }
  43.         else if(isKeyPressed(KEY_NSPIRE_TAB))
  44.         {
  45.             players = 1;
  46.         }
  47.     }
  48.     while(lscore < 10 && rscore < 10 && !isKeyPressed(KEY_NSPIRE_ESC))
  49.     {
  50.         clearScreen(black, buffer);
  51.         l = SCREEN_HEIGHT / 2 - 15;
  52.         r = l;
  53.         x = SCREEN_WIDTH * 128;
  54.         y = SCREEN_HEIGHT * 128;
  55.         die = 0;
  56.         yvel = 0;
  57.         xvel = -256;
  58.         seed = randnum(seed); //my goal is to give yvel a random value -128 to 128
  59.         yvel = seed % 257 - 128;
  60.         while(!isKeyPressed(KEY_NSPIRE_ESC) && die == 0)
  61.         {
  62.             lmov = 0;
  63.             rmov = 0;
  64.             if(players == 2)
  65.             {
  66.                 if(isKeyPressed(KEY_NSPIRE_9) && r > 1)
  67.                 {
  68.                     drawBox_(SCREEN_WIDTH - 15, r, 5, 30, black, buffer);
  69.                     r--;
  70.                     rmov = -64;
  71.                 }
  72.                 else if(isKeyPressed(KEY_NSPIRE_3) && r < SCREEN_HEIGHT - 30)
  73.                 {
  74.                     drawBox_(SCREEN_WIDTH - 15, r, 5, 30, black, buffer);
  75.                     r++;
  76.                     rmov = 64;
  77.                 }
  78.                 if(isKeyPressed(KEY_NSPIRE_7) && l > 1)
  79.                 {
  80.                     drawBox_(10, l, 5, 30, black, buffer);
  81.                     l--;
  82.                     lmov = -64;
  83.                 }
  84.                 else if(isKeyPressed(KEY_NSPIRE_1) && l < SCREEN_HEIGHT - 30)
  85.                 {
  86.                     drawBox_(10, l, 5, 30, black, buffer);
  87.                     l++;
  88.                     lmov = 64;
  89.                 }
  90.             }
  91.             if(players == 1)
  92.             {
  93.                 if(isKeyPressed(KEY_NSPIRE_8) && r > 1)
  94.                 {
  95.                     drawBox_(SCREEN_WIDTH - 15, r, 5, 30, black, buffer);
  96.                     r--;
  97.                     rmov = -64;
  98.                 }
  99.                 else if(isKeyPressed(KEY_NSPIRE_2) && r < SCREEN_HEIGHT - 30)
  100.                 {
  101.                     drawBox_(SCREEN_WIDTH - 15, r, 5, 30, black, buffer);
  102.                     r++;
  103.                     rmov = 64;
  104.                 }
  105.                 if(x / 256 < SCREEN_WIDTH / 2)
  106.                 {
  107.                     if(y / 256 - 15 < l && l > 1)
  108.                     {
  109.                         drawBox_(10, l, 5, 30, black, buffer);
  110.                         l--;
  111.                         lmov = -64;
  112.                     }
  113.                     else if(y / 256 - 15 > l && l < SCREEN_HEIGHT - 30)
  114.                     {
  115.                         drawBox_(10, l, 5, 30, black, buffer);
  116.                         l++;
  117.                         lmov = 64;
  118.                     }
  119.                 }
  120.             }
  121.             if(x / 256 - 4 < 15)
  122.             {
  123.                 if((y / 256 + 4 > l) && (y / 256 - 4 < l + 30))
  124.                 {
  125.                     xvel = abs(xvel);
  126.                     yvel += lmov;
  127.                 }
  128.             }
  129.             if(x / 256 - 4 < 10)
  130.             {
  131.                 die = 1;
  132.                 lscore++;
  133.             }
  134.             if(x / 256 + 4 > SCREEN_WIDTH - 10)
  135.             {
  136.                 die = 1;
  137.                 rscore++;
  138.             }
  139.  
  140.  
  141.             if(x / 256 + 4 > SCREEN_WIDTH - 15)
  142.             {
  143.                 if((y / 256 + 4 > r) && (y / 256 - 4 < r + 30))
  144.                 {
  145.                     xvel = -abs(xvel);
  146.                     yvel += rmov;
  147.                 }
  148.             }
  149.             if(y / 256 - 4 < 1)
  150.             {
  151.                 yvel = -yvel;
  152.             }
  153.             if(y / 256 + 4 > SCREEN_HEIGHT)
  154.             {
  155.                 yvel = -yvel;
  156.             }
  157.             drawBox_(10, l, 5, 30, green, buffer);
  158.             drawBox_(SCREEN_WIDTH - 15, r, 5, 30, green, buffer);
  159.             drawDisc_(x / 256, y / 256, 5, black, buffer);
  160.             y += yvel;
  161.             x += xvel;
  162.             drawDisc_(x / 256, y / 256, 5, green, buffer);
  163.             display(buffer);
  164.             sleep(4);
  165.         }
  166.     }
  167.     return 0;
  168. }
  169.  
  170. int randnum(int s)
  171. {
  172.     return s * 46 - 78 / s * 57 - s + 87 * s; //Why yes, this is my random number formula :P
  173. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement