Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- ** EPITECH PROJECT, 2019
- ** guitarhero
- ** File description:
- ** main
- */
- #include <unistd.h>
- #include <math.h>
- #include <iostream>
- #include <algorithm>
- #include "SDLDisplay.hpp"
- #include "Input.hpp"
- #include "Colors.hpp"
- #include "RNG.hpp"
- bool RNG::_initialized = false;
- SDLDisplay display("minijeu", 900, 900);
- void Afficher_rect(int x, int y, int taille_x, int taille_y, int color);
- int main()
- {
- /* Gestion de la fenêtre */
- /* Gestion des touches */
- Input input;
- // Les déclarations de variables se font ici
- bool temps = false;
- int elapsed_time = 0;
- int posR,posB,posG,posY,posC,posM = 0;
- bool R = false;
- bool B = false;
- bool G = false;
- bool Y = false;
- bool C = false;
- bool M = false;
- int temps_pop = 500;
- int score = 0;
- int combo = 0;
- int vitesse = 1;
- while (!(input.shouldExit()) && !(input.getKeyState(SDL_SCANCODE_ESCAPE)))
- {
- display.clearScreen(); // "Nettoie" la fenêtre
- /* La fenêtre fait 900*900, les cases font donc 300*300 */
- for (int i = 0; i < 6 ; i++) {
- Afficher_rect(20+150*i,770,110,110,i+1);
- Afficher_rect(25+150*i,775,100,100,-1);
- Afficher_rect(i*150,0,2,900,7);
- }
- Afficher_rect(898,0,2,900,7);
- Afficher_rect(0,825,900,2,7);
- if (temps) {
- int nb = RNG::generate(6);
- switch (nb) {
- case 0 :
- if (!R) {
- R = true;
- posR = 0;
- }
- break;
- case 1 :
- if (!B) {
- B = true;
- posB = 0;
- }
- break;
- case 2 :
- if (!G) {
- G = true;
- posG = 0;
- }
- break;
- case 3 :
- if (!Y) {
- Y = true;
- posY = 0;
- }
- break;
- case 4 :
- if (!C) {
- C = true;
- posC = 0;
- }
- break;
- case 5 :
- if (!M) {
- M = true;
- posM = 0;
- }
- break;
- }
- temps = false;
- }
- if (elapsed_time >= temps_pop) {
- elapsed_time = 0;
- temps = true;
- }
- elapsed_time ++;
- if (temps_pop <= 10) {
- vitesse++;
- temps_pop = 500;
- }
- if (R) {
- posR += vitesse;
- if (posR >= 880) {
- R = false;
- return 0;
- }
- if (input.getKeyStateOnce(SDL_SCANCODE_Q)) {
- if (posR+40 > 730) {
- combo ++;
- score += (vitesse+combo/(10-100/temps_pop))*(100-sqrt(pow(825-(posR+40),2)));
- printf("score : %d\n",score);
- printf("combo : %d\n",combo);
- temps_pop *= 0.90;
- //printf("temps : %d\n",temps_pop);
- R = false;
- }
- else {
- combo = 0;
- }
- }
- Afficher_rect(35,posR,80,80,1);
- }
- if (B) {
- posB += vitesse;
- if (posB >= 880) {
- B = false;
- return 0;
- }
- if (input.getKeyStateOnce(SDL_SCANCODE_W)) {
- if (posB+40 > 730) {
- combo ++;
- score += (vitesse+combo/(10-100/temps_pop))*(100-sqrt(pow(825-(posB+40),2)));
- printf("%d\n",score);
- printf("combo : %d\n",combo);
- temps_pop *= 0.90;
- //printf("temps : %d\n",temps_pop);
- B = false;
- }
- else {
- combo = 0;
- }
- }
- Afficher_rect(185,posB,80,80,2);
- }
- if (G) {
- posG += vitesse;
- if (posG >= 880) {
- G = false;
- return 0;
- }
- if (input.getKeyStateOnce(SDL_SCANCODE_E)) {
- if (posG+40 > 730) {
- combo ++;
- score += (vitesse+combo/(10-100/temps_pop))*(100-sqrt(pow(825-(posG+40),2)));
- printf("%d\n",score);
- printf("combo : %d\n",combo);
- temps_pop *= 0.90;
- ///printf("temps : %d\n",temps_pop);
- G = false;
- }
- else {
- combo = 0;
- }
- }
- Afficher_rect(335,posG,80,80,3);
- }
- if (Y) {
- posY += vitesse;
- if (posY >= 880) {
- Y = false;
- return 0;
- }
- if (input.getKeyStateOnce(SDL_SCANCODE_R)) {
- if (posY+40 > 730) {
- combo ++;
- score += (vitesse+combo/(10-100/temps_pop))*(100-sqrt(pow(825-(posY+40),2)));
- printf("%d\n",score);
- printf("combo : %d\n",combo);
- temps_pop *= 0.90;
- //printf("temps : %d\n",temps_pop);
- Y = false;
- }
- else {
- combo = 0;
- }
- }
- Afficher_rect(485,posY,80,80,4);
- }
- if (C) {
- posC += vitesse;
- if (posC >= 880) {
- C = false;
- return 0;
- }
- if (input.getKeyStateOnce(SDL_SCANCODE_T)) {
- if (posC+40 > 730) {
- combo ++;
- score += (vitesse+combo/(10-100/temps_pop))*(100-sqrt(pow(825-(posC+40),2)));
- printf("%d\n",score);
- printf("combo : %d\n",combo);
- temps_pop *= 0.90;
- //printf("temps : %d\n",temps_pop);
- C = false;
- }
- else {
- combo = 0;
- }
- }
- Afficher_rect(635,posC,80,80,5);
- }
- if (M) {
- posM += vitesse;
- if (posM >= 880) {
- M = false;
- return 0;
- }
- if (input.getKeyStateOnce(SDL_SCANCODE_Y)) {
- if (posM+40 > 730) {
- combo ++;
- score += (vitesse+combo/(10-100/temps_pop))*(100-sqrt(pow(825-(posM+40),2)));
- printf("%d\n",score);
- printf("combo : %d\n",combo);
- temps_pop *= 0.90;
- //printf("temps : %d\n",temps_pop);
- M = false;
- }
- else {
- combo = 0;
- }
- }
- Afficher_rect(785,posM,80,80,6);
- }
- // Le reste de votre code ici
- display.refreshScreen(); // Rafraîchit la fenêtre
- input.flushEvents(); // Met à jour les touches pressées / clics de souris
- }
- return (0);
- }
- void Afficher_rect(int x, int y, int taille_x, int taille_y, int color) {
- switch (color) {
- case 1 :
- display.putRect(x,y,taille_x,taille_y,Colors::Red);
- break;
- case 2 :
- display.putRect(x,y,taille_x,taille_y,Colors::Blue);
- break;
- case 3 :
- display.putRect(x,y,taille_x,taille_y,Colors::Green);
- break;
- case 4 :
- display.putRect(x,y,taille_x,taille_y,Colors::Yellow);
- break;
- case 5 :
- display.putRect(x,y,taille_x,taille_y,Colors::Cyan);
- break;
- case 6 :
- display.putRect(x,y,taille_x,taille_y,Colors::Magenta);
- break;
- case 7 :
- display.putRect(x,y,taille_x,taille_y,Colors::White);
- break;
- default :
- display.putRect(x,y,taille_x,taille_y,Colors::Black);
- break;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement