Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <os.h>
- #include <nGUI.h>
- #include <nGEO.h>
- #include <nMATHS.h>
- int randnum(int s); //making my own temporary random function
- int main()
- {
- // Create a new screen buffer
- ScreenBuffer buffer = GetNewScreenBuffer();
- int x, y, xvel = -256, yvel = 0, l, r, players = 0, seed = 0, die = 0, lmov = 0, rmov = 0, lscore = 0, rscore = 0, ran;
- Color green = RGB(0, 255, 0);
- Color black = RGB(0, 0, 0);
- l = SCREEN_HEIGHT / 2 - 15;
- r = l;
- x = SCREEN_WIDTH * 128;
- y = SCREEN_HEIGHT * 128;
- clearScreen(black, buffer);
- drawStr(1, 0,
- "\n PONG\n\n"
- "Created by Epic7\n"
- "Using nRGBlib\n\n"
- "Multiplayer Controls:\n"
- " - Player 1 up : 9\n"
- " - Player 1 down : 3\n"
- " - Player 2 up : 7\n"
- " - Player 2 down : 1\n"
- "Singleplayer Controls:\n"
- " - Player 1 Up : 8\n"
- " - Player 1 Down : 2\n\n"
- "Push Ctrl to Start Multiplayer\n"
- "Push Tab to Start Singleplayer", 1, 1, green, buffer);
- display(buffer);
- while(players == 0)
- {
- seed++;
- if(isKeyPressed(KEY_NSPIRE_CTRL))
- {
- players = 2;
- }
- else if(isKeyPressed(KEY_NSPIRE_TAB))
- {
- players = 1;
- }
- }
- while(lscore < 10 && rscore < 10 && !isKeyPressed(KEY_NSPIRE_ESC))
- {
- clearScreen(black, buffer);
- l = SCREEN_HEIGHT / 2 - 15;
- r = l;
- x = SCREEN_WIDTH * 128;
- y = SCREEN_HEIGHT * 128;
- die = 0;
- yvel = 0;
- xvel = -256;
- seed = randnum(seed); //my goal is to give yvel a random value -128 to 128
- yvel = seed % 257 - 128;
- while(!isKeyPressed(KEY_NSPIRE_ESC) && die == 0)
- {
- lmov = 0;
- rmov = 0;
- if(players == 2)
- {
- if(isKeyPressed(KEY_NSPIRE_9) && r > 1)
- {
- drawBox_(SCREEN_WIDTH - 15, r, 5, 30, black, buffer);
- r--;
- rmov = -64;
- }
- else if(isKeyPressed(KEY_NSPIRE_3) && r < SCREEN_HEIGHT - 30)
- {
- drawBox_(SCREEN_WIDTH - 15, r, 5, 30, black, buffer);
- r++;
- rmov = 64;
- }
- if(isKeyPressed(KEY_NSPIRE_7) && l > 1)
- {
- drawBox_(10, l, 5, 30, black, buffer);
- l--;
- lmov = -64;
- }
- else if(isKeyPressed(KEY_NSPIRE_1) && l < SCREEN_HEIGHT - 30)
- {
- drawBox_(10, l, 5, 30, black, buffer);
- l++;
- lmov = 64;
- }
- }
- if(players == 1)
- {
- if(isKeyPressed(KEY_NSPIRE_8) && r > 1)
- {
- drawBox_(SCREEN_WIDTH - 15, r, 5, 30, black, buffer);
- r--;
- rmov = -64;
- }
- else if(isKeyPressed(KEY_NSPIRE_2) && r < SCREEN_HEIGHT - 30)
- {
- drawBox_(SCREEN_WIDTH - 15, r, 5, 30, black, buffer);
- r++;
- rmov = 64;
- }
- if(x / 256 < SCREEN_WIDTH / 2)
- {
- if(y / 256 - 15 < l && l > 1)
- {
- drawBox_(10, l, 5, 30, black, buffer);
- l--;
- lmov = -64;
- }
- else if(y / 256 - 15 > l && l < SCREEN_HEIGHT - 30)
- {
- drawBox_(10, l, 5, 30, black, buffer);
- l++;
- lmov = 64;
- }
- }
- }
- if(x / 256 - 4 < 15)
- {
- if((y / 256 + 4 > l) && (y / 256 - 4 < l + 30))
- {
- xvel = abs(xvel);
- yvel += lmov;
- }
- }
- if(x / 256 - 4 < 10)
- {
- die = 1;
- lscore++;
- }
- if(x / 256 + 4 > SCREEN_WIDTH - 10)
- {
- die = 1;
- rscore++;
- }
- if(x / 256 + 4 > SCREEN_WIDTH - 15)
- {
- if((y / 256 + 4 > r) && (y / 256 - 4 < r + 30))
- {
- xvel = -abs(xvel);
- yvel += rmov;
- }
- }
- if(y / 256 - 4 < 1)
- {
- yvel = -yvel;
- }
- if(y / 256 + 4 > SCREEN_HEIGHT)
- {
- yvel = -yvel;
- }
- drawBox_(10, l, 5, 30, green, buffer);
- drawBox_(SCREEN_WIDTH - 15, r, 5, 30, green, buffer);
- drawDisc_(x / 256, y / 256, 5, black, buffer);
- y += yvel;
- x += xvel;
- drawDisc_(x / 256, y / 256, 5, green, buffer);
- display(buffer);
- sleep(4);
- }
- }
- return 0;
- }
- int randnum(int s)
- {
- return s * 46 - 78 / s * 57 - s + 87 * s; //Why yes, this is my random number formula :P
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement