casse-brick latest
Ce projet est réalisé dans le cadre du cours de Programmation Avancée en M1 Informatique de l'université de Strasbourg.
Loading...
Searching...
No Matches
brique.cpp
Go to the documentation of this file.
1//
2// Created by maxime on 16/04/24.
3//
4
5#include "brique.h"
6
7
8uint8_t randomNumber() {
9 std::random_device rd;
10 std::mt19937 gen(rd());
11
12 std::uniform_int_distribution<> distribution(10, 255);
13
14 return distribution(gen);
15}
16
17std::tuple<SDL_Color,SDL_Color> colorFromCollisionCounter(int counter,int super){
18 if(super==1) return std::make_tuple<SDL_Color,SDL_Color>(blue);
19 if(super==2) return std::make_tuple<SDL_Color,SDL_Color>(lila);
20 if (counter== 1) return std::make_tuple<SDL_Color,SDL_Color>(green);
21 if (counter == 2) return std::make_tuple<SDL_Color,SDL_Color>(yellow);
22 if (counter == 3) return std::make_tuple<SDL_Color,SDL_Color>(red);
23 return std::make_tuple<SDL_Color,SDL_Color>({184,84,80},{248,206,204,255});
24}
25
26int attributionSuperPower(int number){
27 if(number != 1 && number!=2 && number!= 3 ) {return 0;}
28 return number;
29}
30
31Brique::Brique( int x, int y, int w, int h) :
32 CollidingObject(x,y,w,h,"Brique")
33{
34 int n = randomNumber() % 10;
36 if(super_power==0){
38 }else{
40 }
42}
43
44Brique::Brique(int x, int y, int width, int height, bool isTop)
45:
46 CollidingObject(x,y,width,height,isTop,"Brique")
47{
51};
52
53Brique::Brique(int x, int y, int width, int height, int edges)
54 :
55 CollidingObject(x,y,width,height,edges,"Brique")
56{
60};
61
64 if(super_power!=0) return;
65 switch (collision_counter) {
66 case 1:
67 std::tie(color1, color2) = std::make_tuple<SDL_Color,SDL_Color>(green);
68 break;
69 case 2:
70 std::tie(color1, color2) = std::make_tuple<SDL_Color,SDL_Color>(yellow);
71 break;
72 case 3:
73 std::tie(color1, color2) = std::make_tuple<SDL_Color,SDL_Color>(red);
74 break;
75 }
77 collided = true;
78}
std::tuple< SDL_Color, SDL_Color > colorFromCollisionCounter(int counter, int super)
Definition brique.cpp:17
int attributionSuperPower(int number)
Definition brique.cpp:26
uint8_t randomNumber()
Definition brique.cpp:8
#define blue
Definition brique.h:21
#define lila
Definition brique.h:22
#define green
Definition brique.h:20
#define yellow
Definition brique.h:19
#define red
Definition brique.h:18
Brique(int x, int y, int w, int h)
Constructs a new Brique object with specified position and dimensions.
Definition brique.cpp:31
bool collided
Flag indicating whether the block has collided with another object.
Definition brique.h:43
int super_power
The super power level of the block.
Definition brique.h:44
SDL_Color color1
The primary color of the block.
Definition brique.h:38
SDL_Color color2
The secondary color of the block.
Definition brique.h:39
int collision_counter
The collision counter for the block.
Definition brique.h:42
void handleCollisions(point collision) override
Handles collisions with other objects.
Definition brique.cpp:62
The CollidingObject class represents a generic colliding object.
The point struct represents a point in 2D space.