decna12255

problems

Feb 21st, 2012
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 6.03 KB | None | 0 0
  1. okay i been stuck on these problems for a week now.
  2. 1. being googling around and stil cant figure out to write collision for my pong any help would be nice.
  3. 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.
  4.  
  5. here is the code i have
  6. //stuff to complete is where my main dilimer is!
  7.  
  8.  
  9. //
  10. //#include "stdafx.h"
  11. #include <Windows.h>
  12. #include "GL_Functions.h"
  13. #include "pctimer.h"
  14. #include <string>
  15. #include <cmath>
  16. #include <stdio.h>
  17. #include <crtdbg.h>
  18.  
  19.  
  20.  
  21.     //{ make this a function later =D
  22.    enum STATE
  23.     {
  24.       MAINMENU,  // will take user to main menu at start of game or during
  25.      SINGLEPLAYER,  // one player mode
  26.       MULTIPLAYER, // player vs player mode
  27.       HIGHSCORES, //lists high score
  28.       INSTRUCTIONS, // opens the options menu
  29.       QUIT // when user presses escape key program closes
  30.     };
  31.  
  32.     //bool MAINMENU;
  33.    //bool SINGLEPLAYER;
  34.    STATE currentstate;
  35.  
  36.  
  37.  
  38.  
  39.  
  40.  
  41. int main(int argc, char* argv[])
  42. {
  43.  
  44.     //Lets open the window and initialise opengl
  45.     InitGL(1024,768);
  46.     int background = LoadTexture ("./images/background.png");
  47.     int mball = LoadTexture ("./images/mball.png");
  48.     int leftpaddle_2 = LoadTexture ("./images/paddle_2.png");
  49.     int rightpaddle_1 = LoadTexture ("./images/paddle_1.png");
  50.     int menu = LoadTexture ("./images/menu.png");
  51.  
  52.     //stuff to complete.......!!!!
  53.    //{
  54.     // currentState = MAINMENU;
  55.    //  bool singeplayer() = true;
  56.            
  57.    //  while  (bContinueGame)
  58.       //{
  59.         //      switch(currentstate)
  60.         //  {
  61.         //  case MAINMENU;
  62.         //      bcontinueGame = MAINMENU;
  63.         //  case SINGLEPLAYER;
  64.         //      bcontinueGame = SINGLEPLAYER;
  65.         //  case QUIT;
  66.         //      break;
  67.         //  default:
  68.         //      break;
  69.         //  };
  70.  
  71.      // }  
  72.     //}
  73.    
  74.     //variables
  75.     // 'M' stand for metroid....
  76.     float backgroundx = 0;
  77.     float backgroundy = 0;
  78.     float mballx = 492;
  79.     float mbally = 384;
  80.     float ballxspeed = 4;
  81.     float ballyspeed = 2;
  82.     float rightpaddle_x = 990;
  83.     float rightpaddle_y = 20;
  84.     float leftpaddle_x = 15;
  85.     float leftpaddle_y = 450;
  86.    float ballrside = mballx + 40;
  87.     float position = 0;
  88.     float paddle_width = 5;
  89.     float paddle_length = 15;
  90.     float ball_width = 2.5;
  91.     float ball_length = 5;
  92.    float menu = 0;
  93.  
  94.  
  95.     do
  96.     {
  97.         //Clear the screen, so previous frames don't build up
  98.         ClearScreen();
  99.        
  100.         mballx = mballx + ballxspeed;
  101.         mbally = mbally + ballyspeed;
  102.        
  103.    
  104. //////////draws images to screen////////////////////////////////////////////////////
  105.         DrawSprite(background, backgroundx, backgroundy, 1024, 768);  //////////////
  106.         DrawLine(512,0,512,768);                                      //////////////
  107.         DrawSprite(mball, mballx, mbally, 40, 40);                    //////////////
  108.         DrawSprite(leftpaddle_2, leftpaddle_x,  leftpaddle_y, 20, 100); //////////
  109.         DrawSprite(rightpaddle_1, rightpaddle_x, rightpaddle_y, 20, 100); ////////
  110.         //Headings and menu items                   ////////////////////////////////
  111.         DrawString("METROID PONG", 64, 64, 5.0f);   ////////////////////////////////
  112.         DrawString("1. Singleplayer", 64, 256, 3.0f);  /////////////////////////////
  113.         DrawString("2. Multiplayer", 64, 384, 3.0f);  /////////////////////////////
  114.         DrawString("3. Instructions",  64, 400, 3.0f);  /////////////////////////////
  115.         DrawString("4. High Scores", 64, 512, 3.0f);   /////////////////////////////
  116.         DrawString("5. Exit", 64, 640, 3.0f);          /////////////////////////////
  117. ////////////////////////////////////////////////////////////////////////////////////
  118. ////////////////////////////////////////////////////////////////////////////////////
  119.        
  120.        
  121.         //highscores
  122.         //{
  123.         //  int iHighscore[6}
  124.         //  int iScore = 0
  125.         //  char scorestring[] = "score"
  126.         //  while (iscore < 6)
  127.         //  printf("Highscore: %i %i/n"), (iScore+1), iHighscore[iScore]);
  128.         //  ++iScore;
  129.         //   for{
  130.         //     (int iHighscore = 0;, iHighscore < 10, iHighscore++)
  131.         //  printf(
  132.         //  }
  133.         //}
  134.  
  135.  
  136.         // ball speed/control
  137.  
  138.         if (mballx > 984)  
  139.         {
  140.             mballx = 492;
  141.             mbally = 384;
  142.             ballxspeed *= -1;
  143.         }
  144.  
  145.         if ( mballx < 0)   
  146.         {
  147.             mballx = 492;
  148.             mbally = 384;
  149.             ballxspeed *= -1;
  150.         }
  151.        
  152.         if (mbally > 1024 || mbally < 0)
  153.                 ballyspeed *= -.5;
  154.  
  155.         // controls for players one and two
  156.         // player one's controls ( 'w' and 's')
  157.         // player two's controls ( 'up' and 'down')
  158.  
  159.        
  160.         if (IsKeyDown(KEY_UP))
  161.         {
  162.             rightpaddle_y = rightpaddle_y -5;
  163.             if( rightpaddle_y < 0 )
  164.             {
  165.                 rightpaddle_y = 0; 
  166.             }
  167.         }
  168.  
  169.         if (IsKeyDown(KEY_DOWN) && rightpaddle_y < 668)
  170.             rightpaddle_y = rightpaddle_y +5;
  171.  
  172.         if (IsKeyDown('w') && leftpaddle_x > 0)
  173.             leftpaddle_y = leftpaddle_y -5;
  174.        
  175.         if (IsKeyDown('s') && leftpaddle_x < 668)
  176.             leftpaddle_y = leftpaddle_y +5;
  177.        
  178.         // closes program down atfer user presses escape!
  179.         if (IsKeyDown(KEY_ESCAPE))
  180.             CloseDown();
  181.    
  182.  
  183.         //limit paddles so that stay with in boundaries placed
  184.         // well they would if i could program
  185.         {
  186.         if(leftpaddle_y < 0)
  187.             leftpaddle_y = 0;
  188.          
  189.         if(leftpaddle_y + paddle_width > 668)
  190.             leftpaddle_y = 668 - paddle_width;
  191.        
  192.         if(rightpaddle_y + paddle_width > 668)
  193.            rightpaddle_y = 668 - paddle_width;  
  194.         }
  195.         //ball impact values below
  196.         //makes ball go bouncy bouncy
  197.         //collision is surpost to be here...
  198.         {
  199.         if(ball_length + ball_width > paddle_width + paddle_length)
  200.         mballx,mbally = 0;
  201.            
  202.         // these do stuff
  203.         // without them game crashes....no idea why
  204.         if(mballx > rightpaddle_x + rightpaddle_y)
  205.        
  206.         if(mballx = leftpaddle_x - position && leftpaddle_y > ball_width)
  207.            
  208.         if(mbally = rightpaddle_x + position && rightpaddle_x > ball_width)
  209.         return(0);
  210.         }
  211.         //Stop it from running too fast! Sleep ZZzzz
  212.         Sleep(5);
  213.        
  214.         } while (FrameworkUpdate()); //Do some secret stuff,
  215.  
  216.        
  217.         FreeTexture(leftpaddle_2);
  218.         FreeTexture(rightpaddle_1);
  219.         FreeTexture(background);
  220.         FreeTexture(mball);
  221.         FreeTexture(menu);
  222.  
  223.  
  224.         //Close down
  225.         CloseDown();
  226.  
  227.         _CrtDumpMemoryLeaks();
  228.  
  229.         //Quit!
  230.         return 0;
  231.  }
Advertisement
Add Comment
Please, Sign In to add comment