decna12255

Untitled

Mar 19th, 2012
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.86 KB | None | 0 0
  1. //\====================================================================================
  2. //\ Author: Declan.corcoran
  3. //\ Date : 19 March 2012
  4. //\ About : main.cpp - Defines the entry point for our Simple SDL Project
  5. //\====================================================================================
  6.  
  7. #include <Windows.h>
  8. #include "GL_Functions.h"
  9. #include "pctimer.h"
  10. #include <string>
  11. #include <cmath>
  12. #include <crtdbg.h>
  13.  
  14.  
  15. int main(int argc, char* argv[])
  16. {
  17.  
  18. //Lets open the window and initialise opengl
  19. InitGL(1024,768);
  20.  
  21.  
  22. //Loads an Image,
  23. int ball = LoadTexture("./images/ball.png");
  24. int background = LoadTexture("./images/background.png");
  25. int leftpaddle = LoadTexture("./images/leftpaddle.png");
  26. int rightpaddle = LoadTexture("./images/rightpaddle.png");
  27.  
  28. float Ball = 1;
  29. float ballx = 450;
  30. float bally = 350;
  31.  
  32. float ballspeedx = 2;
  33. float ballspeedy = 3;
  34.  
  35. float Background = 1;
  36. float backgroundx = 0;
  37. float backgroundy = 0;
  38.  
  39. float Rightpaddle = 1;
  40. float rightpaddlex = 990;
  41. float rightpaddley = 20;
  42.  
  43. float Leftpaddle = 1;
  44. float leftpaddlex = 15;
  45. float leftpaddley = 450;
  46.  
  47. float paddle_width = 2;
  48. float paddle_length = 10;
  49. float ball_width = 2.5;
  50. float ball_length = 2.5;
  51. do
  52. {
  53.  
  54.  
  55. //Clear the screen, so previous frames don't build up
  56. ClearScreen();
  57.  
  58. ballx = ballx + ballspeedx;
  59. bally = bally + ballspeedy;
  60.  
  61. DrawSprite(background, backgroundx, backgroundy, 1024, 768);
  62. DrawLine(512,0,512,768);
  63. DrawSprite(ball, ballx, bally, 40, 40);
  64. DrawSprite(leftpaddle, leftpaddlex, leftpaddley, 20, 100);
  65. DrawSprite(rightpaddle, rightpaddlex, rightpaddley, 20, 100);
  66.  
  67.  
  68. // ball speed/control
  69. //
  70. if (ballx > 984)
  71. {
  72. ballx = 492;
  73. bally = 384;
  74. ballspeedx *= -1;
  75. }
  76.  
  77. if ( ballx < 0)
  78. {
  79. ballx = 492;
  80. bally = 384;
  81. ballspeedx *= -1;
  82. }
  83.  
  84. if (bally > 1024 || bally < 0)
  85. ballspeedy *= -.5;
  86.  
  87.  
  88. //paddle controlls
  89. // player one's controls ( 'w' and 's')
  90. // player two's controls ( 'up' and 'down')
  91.  
  92. if (IsKeyDown(KEY_UP))
  93. {
  94. rightpaddley = rightpaddley -5;
  95. if( rightpaddley < 0 )
  96. {
  97. rightpaddley = 0;
  98. }
  99. }
  100.  
  101. if (IsKeyDown(KEY_DOWN) && rightpaddley < 668)
  102. rightpaddley = rightpaddley +5;
  103.  
  104. if (IsKeyDown('w') && leftpaddley > 0)
  105. leftpaddley = leftpaddley -5;
  106.  
  107. if (IsKeyDown('s') && leftpaddley < 668)
  108. leftpaddley = leftpaddley +5;
  109.  
  110. // closes program down atfer user presses escape!
  111. if (IsKeyDown(KEY_ESCAPE))
  112. CloseDown();
  113. //Stop it from running too fast! Sleep ZZzzz
  114. Sleep(5);
  115.  
  116. } while (FrameworkUpdate()); //Do some secret stuff,
  117.  
  118. //Before you exit, clean up after yourself
  119. FreeTexture(ball);
  120. FreeTexture(background);
  121. FreeTexture(leftpaddle);
  122. FreeTexture(rightpaddle);
  123.  
  124. //Close down
  125. CloseDown();
  126.  
  127. _CrtDumpMemoryLeaks();
  128.  
  129. //Quit!
  130. return 0;
  131. }
  132.  
  133.  
  134.  
  135.  
  136.  
  137.  
  138. have fun =D
Advertisement
Add Comment
Please, Sign In to add comment