Breakout
Brick.h
Go to the documentation of this file.
1 #ifndef BRICK
2 #define BRICK
3 #include <SDL2/SDL.h>
4 #include "Ball.h"
5 #include "ResourceManager.h"
6 
7 #define BRICK_WIDTH 75
8 #define BRICK_HEIGHT 25
9 #define SPACING 16
10 
14 struct Point {
15  float x, y;
16 };
20 class Brick{
21 
22 public:
26  Brick();
27 
31  ~Brick();
32 
37  bool hit = false;
38 
46  void init(int x, int y, SDL_Renderer* ren, int rowNumber);
47 
52  void draw(SDL_Renderer* ren);
53 
57  void update();
58 
62  void setSelected();
63 
67  bool getSelected();
68 
72  bool CollisionWithBall(Ball& ball, float& dt);
76  int getContactEdge(Ball& ball, float& dt);
81 
82 
83 
84 private:
88  SDL_Surface* spriteSheet;
89 
93  SDL_Texture* texture;
94 
98  SDL_Rect Dest;
99 
103  SDL_Rect Src;
104 
108  bool selected;
112  ResourceManager resourceManager = ResourceManager::getInstance();
116  int x;
120  int y;
124  int width;
128  int height;
129 };
130 
131 
132 #endif
Represents Ball in the game.
Definition: Ball.h:16
Represents the a single brick.
Definition: Brick.h:20
void draw(SDL_Renderer *ren)
Method used to render ball on screen.
Definition: Brick.cpp:83
~Brick()
Destructor for Brick class.
Definition: Brick.cpp:27
bool isUpperSideOfLine(Point *, Point *, Point *)
This Method is used determie if the ball hit the upper side of the brick.
Definition: Brick.cpp:119
int getContactEdge(Ball &ball, float &dt)
This method returns which edge of the brick is hit by the ball.
Definition: Brick.cpp:123
bool getSelected()
Method used to get whether brick is selected.
Definition: Brick.cpp:115
void init(int x, int y, SDL_Renderer *ren, int rowNumber)
Method to initialize a brick by loading it's image.
Definition: Brick.cpp:37
bool hit
Variable to keep state of whether brick was hit or not Initialized to false by default.
Definition: Brick.h:37
Brick()
Constructor of the Brick Class.
Definition: Brick.cpp:17
bool CollisionWithBall(Ball &ball, float &dt)
Method used to update brick and ball after a collision.
Definition: Brick.cpp:184
void update()
Method used to update brick.
Definition: Brick.cpp:101
void setSelected()
Method used to update whether brick is selected.
Definition: Brick.cpp:108
The resource manager is responsible for handling and managing resources regarding the game.
Definition: ResourceManager.h:12
static ResourceManager & getInstance()
Method used to get instance of ResourceManager class.
Definition: ResourceManager.cpp:10
GLint GLsizei width
Definition: glad.h:1462
GLint GLsizei GLsizei height
Definition: glad.h:1462
GLint y
Definition: glad.h:1462
GLdouble x
Definition: glad.h:2344
GLuint texture
Definition: glad.h:2396
Represents a single point in the 2D plane.
Definition: Brick.h:14
float x
Definition: Brick.h:15
float y
Definition: Brick.h:15