Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- okay i been stuck on these problems for a week now.
- 1. being googling around and stil cant figure out to write collision for my pong any help would be nice.
- 2. why doesn't my enum_state work properly and why cant i make my main menu appear first in game not overlap over the top of my game.
- here is the code i have
- //stuff to complete is where my main dilimer is!
- //
- //#include "stdafx.h"
- #include <Windows.h>
- #include "GL_Functions.h"
- #include "pctimer.h"
- #include <string>
- #include <cmath>
- #include <stdio.h>
- #include <crtdbg.h>
- //{ make this a function later =D
- 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
- };
- //bool MAINMENU;
- //bool SINGLEPLAYER;
- STATE currentstate;
- 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");
- //stuff to complete.......!!!!
- //{
- // currentState = MAINMENU;
- // bool singeplayer() = true;
- // while (bContinueGame)
- //{
- // switch(currentstate)
- // {
- // case MAINMENU;
- // bcontinueGame = MAINMENU;
- // case SINGLEPLAYER;
- // bcontinueGame = SINGLEPLAYER;
- // case QUIT;
- // break;
- // default:
- // break;
- // };
- // }
- //}
- //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); ////////
- //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); /////////////////////////////
- ////////////////////////////////////////////////////////////////////////////////////
- ////////////////////////////////////////////////////////////////////////////////////
- //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 surpost to be here...
- {
- if(ball_length + ball_width > paddle_width + paddle_length)
- mballx,mbally = 0;
- // these do stuff
- // without them game crashes....no idea why
- if(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);
- }
- //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;
- }
Advertisement
Add Comment
Please, Sign In to add comment