Advertisement
Guest User

Untitled

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