-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBlock.h
More file actions
236 lines (192 loc) · 8.03 KB
/
Block.h
File metadata and controls
236 lines (192 loc) · 8.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
/*
* Authors: Christine Seng, Erick Martinez, Georgia Rushing, Graham Balas, Nolan Schirripa
* Assignment Title: Group Project (Block.h)
* Assignment Description: declares block class that can be hit for score and change color when hit
* Due Date: 12/09/2024
* Date Created: 10/25/2024
* Date Last Modified: 12/07/2024
*/
#ifndef BLOCK_H
#define BLOCK_H
#include "SDL_Plotter.h"
#include "HitBox.h"
class Block
{
private:
//Block Attributes
point location;
int life;
color blockColor;
string shape;
//HitBoxes
HitBox hb;
//Level
int currentLevel = 0;
int levelOffsetY = 0;//how far a block should move up
vector<Block> allActiveShapes;
public:
//Constructors
Block();
Block(point loc, string s);
//setters
//************************************************************
// description: sets location to point p
// return: void
// pre: valid argument point p
// post: location changed to point p
//************************************************************
void setLocation(point p) {
location.x = p.x;
location.y = p.y;
}
//************************************************************
// description: sets life to l
// return: void
// pre: valid argument int l
// post: life changed to int l
//************************************************************
void setLife(int l) {life = l;}
//************************************************************
// description: sets allActiveShapesLife
// return: void
// pre: valid int arguments
// post: life of allActiveShapesLife[index] set to l
//************************************************************
void setAllActiveShapesLife (int l, int index);
//************************************************************
// description: sets shape to string s
// return: void
// pre: valid string argument for s
// post: shape changed to s
//************************************************************
void setShape(string s) {shape = s;}
//************************************************************
// description: changes blockColor based on life
// return: void
// pre: life has been initialized
// post: blockColor changed
//************************************************************
void updateBlockColor();
//getters
//************************************************************
// description: returns life
// return: int
// pre: life initialized
// post: life remains unchanged
//************************************************************
int getLife() const {return life;}
//************************************************************
// description: gets location
// return: point
// pre: location initialized
// post: location remains unchanged
//************************************************************
point getLocation() const {return location;}
//************************************************************
// description: gets blockColor
// return: color
// pre: blockColor initialized
// post: blockColor remains unchanged
//************************************************************
color getColor() const {return blockColor;}
//************************************************************
// description: gets shape string
// return: string
// pre: shape string initialized
// post: shape remains unchanged
//************************************************************
string getShape() const {return shape;}
//************************************************************
// description: gets hit box
// return: HitBox
// pre: hit box initialized
// post: hit box remains unchanged
//************************************************************
HitBox getHitBox() const {return hb;}
//************************************************************
// description: gets allActiveShapes on screen
// return: vector<Block>
// pre: allActiveShapes initialized
// post: vector allActiveShapes returned
//************************************************************
vector<Block>& getAllActiveShapes() {
return allActiveShapes;
}
//Member functions:
//************************************************************
// description: decreases block life
// return: void
// pre: life initialized
// post: life decreased by 1 if above 0
//************************************************************
void decreaseLife();
//************************************************************
// description: draws a square of color c on screen at point
// return: void
// pre: valid loc, color, and window
// post: square drawn location changed to center of square
//************************************************************
void drawSquare(point loc, int size, color c, SDL_Plotter &win);
//************************************************************
// description: draws a triangle of color c on screen at point
// return: void
// pre: valid loc, color, and window
// post: triangle drawn location changed to center of triangle
//************************************************************
void drawTriangle(point centroid, int size, color c, SDL_Plotter& g);
void drawMirroredTriangle(point leftVertex, point rightVertex, point bottomVertex, color c, SDL_Plotter &g);
//************************************************************
// description: draws a circle of color c on screen at point
// return: void
// pre: valid loc, color, and window
// post: circle drawn location changed to center of circle
//************************************************************
void drawCircle(point loc, int size, color c, SDL_Plotter &g);
//************************************************************
// description: draws a line from two points on screen
// return: void
// pre: valid loc1 and loc2, color, and window
// post: line drawn, data members unchanged
//************************************************************
void drawLine (point loc1, point loc2, color c, SDL_Plotter &g) const;
//************************************************************
// description: returns true if a block is hit
// return: bool
// pre: valid HitBox ballHB and window
// post: boolean returned data members unchanged
//************************************************************
bool isHit(HitBox ballHB, SDL_Plotter &g){
return (HitBox::isHit(ballHB, hb));
}
//************************************************************
// description: calculates distance between two points
// return: double
// pre: valid points loc1 and loc2
// post: distance found and data members unchanged
//************************************************************
double distance (point loc1, point loc2) const;
//Levels
//************************************************************
// description: creates a new level with three shapes based on the start location
// return: void
// pre: startLoc is centered on the x axis, and valid point on the screen
// post: three new shapes added to allActiveShapes vector
//************************************************************
void createLevel(point startLoc);
//************************************************************
// description: draws all shapes
// return: void
// pre: startLoc is same point used to create levels
// post: all shapes drawn onto the screen
//************************************************************
void drawLevel(point startLoc, SDL_Plotter& g);
//************************************************************
// description: increases current level by one
// return: void
// pre: currentLevel is initialized
// post: currentLevel += 1
//************************************************************
void nextLevel();
bool gameOver();
};
#endif //BLOCK_H