Advertisement
Guest User

Light up squares

a guest
Dec 12th, 2017
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.51 KB | None | 0 0
  1. #include "Game.h"
  2.  
  3. namespace GameDev2D//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  4. {
  5. Game::Game()////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  6. { //VARIABLES
  7. g_Duration = 24.0f;
  8. g_Delay = 2.0f;
  9. g_Timer = 4.0f;
  10. //g_Swap=false; ask teacher bout this pls
  11.  
  12. }
  13.  
  14. Game::~Game()////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  15. {
  16.  
  17. }
  18.  
  19. void Game::Update(double delta)///////////////////////////////////////////////////////////////////////////////////////////////////////////
  20. {
  21.  
  22. //Variable
  23. double g_SwapTrack[4] = { 1, 0 , 1 , 0 };
  24.  
  25.  
  26.  
  27. // DELTA / ASSIGNMENT
  28. g_Duration -= delta;
  29.  
  30.  
  31.  
  32.  
  33.  
  34. //Resets g_Timer after each Rectangle and starts g_Delay
  35. if (g_Swap == false)
  36. {
  37. g_Delay -= delta;
  38. g_Timer = 4;
  39. }
  40.  
  41.  
  42. // Resets g_Delay and starts g_Timer
  43. if (g_Swap == true)
  44. {
  45. g_Timer -= delta;
  46. g_Delay = 2;
  47. }
  48.  
  49.  
  50. // SHOWS TIMER IN OUTPUT window
  51. Log::Message("%f", g_Duration);
  52.  
  53.  
  54. // Resets g_Swap
  55. for (int i = 0; i < 4; i++)
  56. {
  57. if (g_SwapTrack[i] == 1)
  58. {
  59. g_Swap = false;
  60. }
  61. }
  62. }
  63.  
  64. void Game::Draw() // On is off off is on deal with it.////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  65. {
  66.  
  67.  
  68. //Variable
  69. double g_lightoff[8] = { 1, .5, 1, .5 , 1 , .5 , 1, .5 };
  70.  
  71. //variable
  72. double g_lightOn[5] = { .75f ,.75f,.75f ,.75f, .75f };
  73.  
  74. //variable
  75. string g_Reload = ("Press R to reset");
  76.  
  77.  
  78. // RECTANGLE BASE
  79. DrawRectangle(0.0f, 0.0f, 384.0f, 384.0f, 0.0f, Color::CyanColor(g_lightOn[0]), true);
  80.  
  81. DrawRectangle(384.0f, 0.0f, 384.0f, 384.0f, 0.0f, Color::BarnRedColor(g_lightOn[2]), true);
  82.  
  83. DrawRectangle(384.0f, 384.0f, 384.0f, 384.0f, 0.0f, Color::RoyalYellowColor(g_lightOn[2]), true);
  84.  
  85. DrawRectangle(0.0f, 384.0f, 384.0f, 384.0f, 0.0f, Color::ShamrockGreenColor(g_lightOn[3]), true);
  86.  
  87.  
  88.  
  89.  
  90.  
  91.  
  92. // MILLION IF STATEMENTS THAT TURN ON THE RECTANGLES
  93.  
  94. if (g_Duration <= 0.1f)
  95. {
  96. DrawString(g_Reload, 295.0f, 500.0f, Color::GhostWhiteColor());
  97. }
  98.  
  99.  
  100.  
  101. if (g_Duration <= 22.0f && g_Duration >= 18.0f) //blue
  102. {
  103. DrawRectangle(0.0f, 0.0f, 384.0f, 384.0f, 0.0f, Color::CyanColor(g_lightoff[0]), true);
  104.  
  105. g_Swap = true;
  106. }
  107.  
  108.  
  109. if (g_Duration <= 16.0f && g_Duration >= 12.0f) //red
  110. {
  111. DrawRectangle(384.0f, 0.0f, 384.0f, 384.0f, 0.0f, Color::BarnRedColor(g_lightoff[2]), true);
  112.  
  113. g_Swap = true;
  114. }
  115.  
  116. if (g_Duration <= 10.0f && g_Duration >= 6.0f) // Ew
  117. {
  118. DrawRectangle(384.0f, 384.0f, 384.0f, 384.0f, 0.0f, Color::RoyalYellowColor(g_lightoff[4]), true);
  119.  
  120. g_Swap = true;
  121. }
  122.  
  123. if (g_Duration <= 4.0f && g_Duration >= 0) // Green
  124. {
  125. DrawRectangle(0.0f, 384.0f, 384.0f, 384.0f, 0.0f, Color::ShamrockGreenColor(g_lightoff[6]), true);
  126.  
  127. g_Swap = true;
  128.  
  129. }
  130.  
  131.  
  132. // STRING OUTPUTS
  133.  
  134. //variable
  135. string output = to_string(g_Duration);
  136. string g2_Delay = to_string(g_Delay);
  137. string g2_Timer = to_string(g_Timer);
  138. string NameTag1 = ("Delay");
  139. string NameTag2 = ("Timer");
  140.  
  141.  
  142.  
  143. DrawString(output, 355.0f, 380.0f, Color::EgyptianBlueColor());
  144. DrawString(g2_Delay, 150.0f, 100.0f, Color::EgyptianBlueColor());
  145. // Delay
  146. DrawString(NameTag1, 70.0f, 100.0f, Color::EgyptianBlueColor());
  147.  
  148. DrawString(g2_Timer, 150.0f, 50.0f, Color::EgyptianBlueColor());
  149. // Timer
  150. DrawString(NameTag2, 70.0f, 50.0f, Color::EgyptianBlueColor());
  151.  
  152.  
  153.  
  154.  
  155.  
  156.  
  157.  
  158. }
  159.  
  160. void Game::HandleLeftMouseClick(float x, float y)/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  161. {
  162.  
  163. }
  164.  
  165. void Game::HandleRightMouseClick(float x, float y)//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  166. {
  167.  
  168. }
  169.  
  170. void Game::HandleKeyPress(Keyboard::Key key)////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  171. { //RESET FUNCTION
  172. if (IsKeyDown(Keyboard::R))
  173. {
  174. g_Duration = 24.0f;
  175. g_Delay = 2.0f;
  176. g_Timer = 4.0f;
  177.  
  178. }
  179. }
  180. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement