Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.86 KB | None | 0 0
  1. /*
  2. ** EPITECH PROJECT, 2019
  3. ** guitarhero
  4. ** File description:
  5. ** main
  6. */
  7.  
  8. #include <unistd.h>
  9. #include <math.h>
  10. #include <iostream>
  11. #include <algorithm>
  12. #include "SDLDisplay.hpp"
  13. #include "Input.hpp"
  14. #include "Colors.hpp"
  15. #include "RNG.hpp"
  16.  
  17. bool RNG::_initialized = false;
  18. SDLDisplay display("minijeu", 900, 900);
  19.  
  20. void Afficher_rect(int x, int y, int taille_x, int taille_y, int color);
  21.  
  22.  
  23.  
  24.  
  25. int main()
  26. {
  27. /* Gestion de la fenêtre */
  28.  
  29. /* Gestion des touches */
  30. Input input;
  31.  
  32. // Les déclarations de variables se font ici
  33. bool temps = false;
  34. int elapsed_time = 0;
  35. int posR,posB,posG,posY,posC,posM = 0;
  36. bool R = false;
  37. bool B = false;
  38. bool G = false;
  39. bool Y = false;
  40. bool C = false;
  41. bool M = false;
  42. int temps_pop = 500;
  43. int score = 0;
  44. int combo = 0;
  45. int vitesse = 1;
  46.  
  47. while (!(input.shouldExit()) && !(input.getKeyState(SDL_SCANCODE_ESCAPE)))
  48. {
  49. display.clearScreen(); // "Nettoie" la fenêtre
  50.  
  51. /* La fenêtre fait 900*900, les cases font donc 300*300 */
  52.  
  53. for (int i = 0; i < 6 ; i++) {
  54. Afficher_rect(20+150*i,770,110,110,i+1);
  55. Afficher_rect(25+150*i,775,100,100,-1);
  56. Afficher_rect(i*150,0,2,900,7);
  57. }
  58. Afficher_rect(898,0,2,900,7);
  59. Afficher_rect(0,825,900,2,7);
  60.  
  61. if (temps) {
  62. int nb = RNG::generate(6);
  63.  
  64.  
  65. switch (nb) {
  66. case 0 :
  67. if (!R) {
  68. R = true;
  69. posR = 0;
  70. }
  71. break;
  72. case 1 :
  73. if (!B) {
  74. B = true;
  75. posB = 0;
  76. }
  77. break;
  78. case 2 :
  79. if (!G) {
  80. G = true;
  81. posG = 0;
  82. }
  83. break;
  84. case 3 :
  85. if (!Y) {
  86. Y = true;
  87. posY = 0;
  88. }
  89. break;
  90. case 4 :
  91. if (!C) {
  92. C = true;
  93. posC = 0;
  94. }
  95. break;
  96. case 5 :
  97. if (!M) {
  98. M = true;
  99. posM = 0;
  100. }
  101. break;
  102. }
  103.  
  104.  
  105. temps = false;
  106. }
  107.  
  108.  
  109.  
  110. if (elapsed_time >= temps_pop) {
  111. elapsed_time = 0;
  112. temps = true;
  113. }
  114. elapsed_time ++;
  115.  
  116.  
  117.  
  118.  
  119.  
  120.  
  121.  
  122.  
  123.  
  124.  
  125. if (temps_pop <= 10) {
  126. vitesse++;
  127. temps_pop = 500;
  128.  
  129. }
  130.  
  131. if (R) {
  132. posR += vitesse;
  133. if (posR >= 880) {
  134. R = false;
  135. return 0;
  136.  
  137. }
  138. if (input.getKeyStateOnce(SDL_SCANCODE_Q)) {
  139. if (posR+40 > 730) {
  140. combo ++;
  141. score += (vitesse+combo/(10-100/temps_pop))*(100-sqrt(pow(825-(posR+40),2)));
  142. printf("score : %d\n",score);
  143. printf("combo : %d\n",combo);
  144. temps_pop *= 0.90;
  145. //printf("temps : %d\n",temps_pop);
  146.  
  147. R = false;
  148. }
  149. else {
  150. combo = 0;
  151.  
  152. }
  153. }
  154. Afficher_rect(35,posR,80,80,1);
  155. }
  156. if (B) {
  157. posB += vitesse;
  158. if (posB >= 880) {
  159. B = false;
  160. return 0;
  161.  
  162. }
  163. if (input.getKeyStateOnce(SDL_SCANCODE_W)) {
  164. if (posB+40 > 730) {
  165. combo ++;
  166. score += (vitesse+combo/(10-100/temps_pop))*(100-sqrt(pow(825-(posB+40),2)));
  167.  
  168. printf("%d\n",score);
  169. printf("combo : %d\n",combo);
  170. temps_pop *= 0.90;
  171. //printf("temps : %d\n",temps_pop);
  172.  
  173. B = false;
  174. }
  175. else {
  176. combo = 0;
  177.  
  178. }
  179. }
  180. Afficher_rect(185,posB,80,80,2);
  181. }
  182. if (G) {
  183. posG += vitesse;
  184. if (posG >= 880) {
  185. G = false;
  186. return 0;
  187.  
  188. }
  189. if (input.getKeyStateOnce(SDL_SCANCODE_E)) {
  190. if (posG+40 > 730) {
  191. combo ++;
  192. score += (vitesse+combo/(10-100/temps_pop))*(100-sqrt(pow(825-(posG+40),2)));
  193.  
  194. printf("%d\n",score);
  195. printf("combo : %d\n",combo);
  196. temps_pop *= 0.90;
  197. ///printf("temps : %d\n",temps_pop);
  198.  
  199. G = false;
  200. }
  201. else {
  202. combo = 0;
  203.  
  204. }
  205. }
  206. Afficher_rect(335,posG,80,80,3);
  207. }
  208. if (Y) {
  209. posY += vitesse;
  210. if (posY >= 880) {
  211. Y = false;
  212. return 0;
  213.  
  214. }
  215. if (input.getKeyStateOnce(SDL_SCANCODE_R)) {
  216. if (posY+40 > 730) {
  217. combo ++;
  218. score += (vitesse+combo/(10-100/temps_pop))*(100-sqrt(pow(825-(posY+40),2)));
  219.  
  220. printf("%d\n",score);
  221. printf("combo : %d\n",combo);
  222. temps_pop *= 0.90;
  223. //printf("temps : %d\n",temps_pop);
  224.  
  225. Y = false;
  226. }
  227. else {
  228. combo = 0;
  229.  
  230. }
  231. }
  232. Afficher_rect(485,posY,80,80,4);
  233. }
  234. if (C) {
  235. posC += vitesse;
  236. if (posC >= 880) {
  237. C = false;
  238. return 0;
  239.  
  240. }
  241. if (input.getKeyStateOnce(SDL_SCANCODE_T)) {
  242. if (posC+40 > 730) {
  243. combo ++;
  244. score += (vitesse+combo/(10-100/temps_pop))*(100-sqrt(pow(825-(posC+40),2)));
  245.  
  246. printf("%d\n",score);
  247. printf("combo : %d\n",combo);
  248. temps_pop *= 0.90;
  249. //printf("temps : %d\n",temps_pop);
  250.  
  251. C = false;
  252. }
  253. else {
  254. combo = 0;
  255.  
  256. }
  257. }
  258. Afficher_rect(635,posC,80,80,5);
  259. }
  260. if (M) {
  261. posM += vitesse;
  262. if (posM >= 880) {
  263. M = false;
  264. return 0;
  265.  
  266. }
  267. if (input.getKeyStateOnce(SDL_SCANCODE_Y)) {
  268. if (posM+40 > 730) {
  269. combo ++;
  270. score += (vitesse+combo/(10-100/temps_pop))*(100-sqrt(pow(825-(posM+40),2)));
  271.  
  272. printf("%d\n",score);
  273. printf("combo : %d\n",combo);
  274. temps_pop *= 0.90;
  275. //printf("temps : %d\n",temps_pop);
  276.  
  277. M = false;
  278. }
  279. else {
  280. combo = 0;
  281.  
  282. }
  283. }
  284. Afficher_rect(785,posM,80,80,6);
  285. }
  286.  
  287.  
  288.  
  289.  
  290. // Le reste de votre code ici
  291.  
  292. display.refreshScreen(); // Rafraîchit la fenêtre
  293. input.flushEvents(); // Met à jour les touches pressées / clics de souris
  294. }
  295. return (0);
  296. }
  297.  
  298.  
  299.  
  300.  
  301.  
  302. void Afficher_rect(int x, int y, int taille_x, int taille_y, int color) {
  303.  
  304. switch (color) {
  305. case 1 :
  306. display.putRect(x,y,taille_x,taille_y,Colors::Red);
  307. break;
  308. case 2 :
  309. display.putRect(x,y,taille_x,taille_y,Colors::Blue);
  310. break;
  311. case 3 :
  312. display.putRect(x,y,taille_x,taille_y,Colors::Green);
  313. break;
  314. case 4 :
  315. display.putRect(x,y,taille_x,taille_y,Colors::Yellow);
  316. break;
  317. case 5 :
  318. display.putRect(x,y,taille_x,taille_y,Colors::Cyan);
  319. break;
  320. case 6 :
  321. display.putRect(x,y,taille_x,taille_y,Colors::Magenta);
  322. break;
  323. case 7 :
  324. display.putRect(x,y,taille_x,taille_y,Colors::White);
  325. break;
  326. default :
  327. display.putRect(x,y,taille_x,taille_y,Colors::Black);
  328. break;
  329.  
  330. }
  331.  
  332. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement