Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- below lies the main function for my metroid version of pong.
- MAIN FUNCTION<><><><><><><><><>
- ///SDL_App.cpp : Defines the entry point for our Project
- //
- //#include "stdafx.h"
- #include <Windows.h>
- #include "GL_Functions.h"
- #include "pctimer.h"
- #include <string>
- #include <cmath>
- #include <stdio.h>
- #include <crtdbg.h>
- int main(int argc, char* argv[])
- {
- //Lets open the window and initialise opengl
- InitGL(1024,768);
- int background = LoadTexture ("./images/background.png");
- int mball = LoadTexture ("./images/mball.png");
- int leftpaddle_2 = LoadTexture ("./images/paddle_2.png");
- int rightpaddle_1 = LoadTexture ("./images/paddle_1.png");
- //int menu = LoadTexture ("./images/menu.png");
- //variables
- // 'M' stand for metroid....
- float backgroundx = 0;
- float backgroundy = 0;
- float mballx = 492;
- float mbally = 384;
- float ballxspeed = 4;
- float ballyspeed = 2;
- float rightpaddle_x = 990;
- float rightpaddle_y = 20;
- float leftpaddle_x = 15;
- float leftpaddle_y = 450;
- float ballrside = mballx + 40;
- float position = 0;
- float paddle_width = 5;
- float paddle_length = 15;
- float ball_width = 2.5;
- float ball_length = 5;
- //float menu = 0;
- do
- {
- //Clear the screen, so previous frames don't build up
- ClearScreen();
- mballx = mballx + ballxspeed;
- mbally = mbally + ballyspeed;
- //////////draws images to screen////////////////////////////////////////////////////
- DrawSprite(background, backgroundx, backgroundy, 1024, 768); //////////////
- DrawLine(512,0,512,768); //////////////
- DrawSprite(mball, mballx, mbally, 40, 40); //////////////
- DrawSprite(leftpaddle_2, leftpaddle_x, leftpaddle_y, 20, 100); ////////////
- DrawSprite(rightpaddle_1, rightpaddle_x, rightpaddle_y, 20, 100); //////////
- ////////////////////////////////////////////////////////////////////////////////////
- //highscores
- //{
- // int iHighscore[6}
- // int iScore = 0
- // char scorestring[] = "score"
- // while (iscore < 6)
- // printf("Highscore: %i %i/n"), (iScore+1), iHighscore[iScore]);
- // ++iScore;
- // for{
- // (int iHighscore = 0;, iHighscore < 10, iHighscore++)
- // printf(
- // }
- //}
- // ball speed/control
- if (mballx > 984)
- {
- mballx = 492;
- mbally = 384;
- ballxspeed *= -1;
- }
- if ( mballx < 0)
- {
- mballx = 492;
- mbally = 384;
- ballxspeed *= -1;
- }
- if (mbally > 1024 || mbally < 0)
- ballyspeed *= -.5;
- // controls for players one and two
- // player one's controls ( 'w' and 's')
- // player two's controls ( 'up' and 'down')
- if (IsKeyDown(KEY_UP))
- {
- rightpaddle_y = rightpaddle_y -5;
- if( rightpaddle_y < 0 )
- {
- rightpaddle_y = 0;
- }
- }
- if (IsKeyDown(KEY_DOWN) && rightpaddle_y < 668)
- rightpaddle_y = rightpaddle_y +5;
- if (IsKeyDown('w') && leftpaddle_x > 0)
- leftpaddle_y = leftpaddle_y -5;
- if (IsKeyDown('s') && leftpaddle_x < 668)
- leftpaddle_y = leftpaddle_y +5;
- // closes program down atfer user presses escape!
- if (IsKeyDown(KEY_ESCAPE))
- CloseDown();
- //limit paddles so that stay with in boundaries placed
- //well they would if i could program
- {
- if(leftpaddle_y < 0)
- leftpaddle_y = 0;
- if(leftpaddle_y + paddle_width > 668)
- leftpaddle_y = 668 - paddle_width;
- if(rightpaddle_y + paddle_width > 668)
- rightpaddle_y = 668 - paddle_width;
- }
- //ball impact values below
- //makes ball go bouncy bouncy
- //collision is ment to be here...
- {
- if(rightpaddle_x >= mballx || rightpaddle_x <= (mballx + ball_width))
- if(ball_length + ball_width > paddle_width + paddle_length)
- mballx,mbally = 0;
- }
- {
- if(rightpaddle_x >= mballx && rightpaddle_x <= (mballx + ball_width) ||
- (rightpaddle_x + paddle_width ) >= mballx && (rightpaddle_x + paddle_width ) <= (mballx + ball_width))
- if(rightpaddle_y >= mbally && rightpaddle_y <= ( mbally + ball_length) ||
- (rightpaddle_y + paddle_length) >= mbally && (rightpaddle_y + paddle_length) <= ( mbally +ball_length))
- //The ball and paddle appear to overlap.
- return true;
- //The ball and the paddle appear to NOT overlap:
- return false;
- }
- //these do stuff
- //without them game crashes....no idea why
- //fiddling around with collision and these were results
- {
- while(mballx > rightpaddle_x + rightpaddle_y)
- if(mballx = leftpaddle_x - position && leftpaddle_y > ball_width)
- if(mbally = rightpaddle_x + position && rightpaddle_x > ball_width)
- return(0);
- break;
- }
- //Stop it from running too fast! Sleep ZZzzz
- Sleep(5);
- {
- while (FrameworkUpdate()); //Do some secret stuff,
- FreeTexture(leftpaddle_2);
- FreeTexture(rightpaddle_1);
- FreeTexture(background);
- FreeTexture(mball);
- //FreeTexture(menu);
- }
- {
- //Close down
- CloseDown();
- _CrtDumpMemoryLeaks();
- //Quit!
- return(0);
- }
- }
- menu functionsss::::
- and here is the menu function which doesn't work yet but thats for another day.
- // SDL_App.cpp : Defines the entry point for our Project
- //
- //#include "stdafx.h"
- #include <Windows.h>
- #include "GL_Functions.h"
- #include "pctimer.h"
- #include <string>
- #include <cmath>
- #include <stdio.h>
- #include <crtdbg.h>
- enum STATE
- {
- MAINMENU, // will take user to main menu at start of game or during
- SINGLEPLAYER, // one player mode
- MULTIPLAYER, // player vs player mode
- HIGHSCORES, //lists high score
- INSTRUCTIONS, // opens the options menu
- QUIT // when user presses escape key program closes
- };
- STATE currentstate;
- void main(int argc, char* argv[])
- {
- //Opens the window
- InitGL(1024, 768);
- //The selectors texture load and X,Y values
- int Arrow = LoadTexture("./images/arrow.png");
- int ArrowY = 250;
- int Arrowx = 150;
- float Rot = 0;
- const int MAINMENU = 1;
- const int SINGLEPLAYER = 2;
- ////////////////////////////////
- //MAINMENU SWITCHING
- {
- currentstate = MAINMENU;
- bool bcontinueGame = true;
- while (bcontinueGame)
- {
- switch(currentstate)
- {
- case MAINMENU:
- bcontinueGame = MAINMENU;
- case SINGLEPLAYER:
- bcontinueGame = SINGLEPLAYER;
- case QUIT:
- break;
- default:
- break;
- };
- }
- }
- do
- {
- //Clear Screen
- ClearScreen();
- //Headings and menu items///////////////////////////////////////////////////
- DrawString("METROID PONG", 64, 64, 5.0f); ////////////////////////////////
- DrawString("1. Singleplayer", 64, 256, 3.0f); /////////////////////////////
- DrawString("2. Multiplayer", 64, 384, 3.0f); //////////////////////////////
- DrawString("3. Instructions", 64, 400, 3.0f); ////////////////////////////
- DrawString("4. High Scores", 64, 512, 3.0f); /////////////////////////////
- DrawString("5. Exit", 64, 640, 3.0f); /////////////////////////////
- ////////////////////////////////////////////////////////////////////////////
- //The arrow
- DrawSpriteRotated(Arrow, 32, ArrowY, 32, 32, Rot += 200.0f);
- //Moving the arrow
- if (IsKeyDown(KEY_DOWN))
- {
- ArrowY = ArrowY + 100;
- }
- if (ArrowY > 700)
- {
- ArrowY = 250;
- }
- if (IsKeyDown(KEY_UP))
- {
- ArrowY = ArrowY - 100;
- }
- if (ArrowY < 255)
- {
- ArrowY = 250;
- }
- //Slows the game
- Sleep(60);
- }
- //Do some secret stuff
- while (FrameworkUpdate());
- //Clean up after yourself
- FreeTexture(Arrow);
- //Close down
- CloseDown();
- _CrtDumpMemoryLeaks();
- }
Advertisement
Add Comment
Please, Sign In to add comment