-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGameMap.cpp
More file actions
123 lines (105 loc) · 3.25 KB
/
GameMap.cpp
File metadata and controls
123 lines (105 loc) · 3.25 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
#include <iostream>
#include "GameMap.h"
using namespace std;
GameMap::GameMap(int flags) {
this->flags = flags;
}
GameMap::~GameMap() {
}
void GameMap::tick() {
}
void GameMap::render(SDL_Surface* display) {
//cout << this->bricks.size() << endl;
for (unsigned int i=0; i < this->bricks.size(); i++) {
this->bricks.at(i)->render(display);
}
}
void GameMap::reset() {
}
void GameMap::generateNew() {
int rows, columns, brickType, incX, incY, initX;
SDL_Surface* brickImg;
// cout << sImg << endl;
if (flags & MAP_TYPE_LARGE) {
brickImg = lImg;
brickType = 2;
columns = LMX;
rows = LMY - 2;
incX = 32;
incY = 16;
initX = 16;
} else if (flags & MAP_TYPE_SMALL) {
brickImg = sImg;
brickType = 3;
columns = SMX;
rows = SMY - 5;
incX = 16;
incY = 8;
initX = 8;
} else {
return;
}
int x = 0;
int y = 22;
cout << "After init" << endl;
for (int i = 1; i <= rows; i++) {
x = initX;
for (int j = 1; j <= columns; j++) {
Brick* brick = new Brick(brickImg, incX, incY);
brick->x = x;
brick->y = y;
brick->brickType = rand() % 10;
brick->brickFlag = brickType;
bricks.push_back(brick);
x += incX;
}
y += incY;
}
cout << "After everything" << endl;
}
void GameMap::loadMap(const string file) {
}
void GameMap::collidesWith(Ball* item) {
// cout << this->bricks.size() << endl;
for (unsigned int i=0; i < this->bricks.size(); i++) {
Brick* brick = this->bricks.at(i);
if (!brick->hidden) {
ColliderData hitData;
bool hit = brick->circle2Rectangle(item->x, item->y, brick, &hitData);
if (hit) {
//item->stop = true;
brick->hidden = true;
//ColliderData hitNoth;
//while (brick->circle2Rectangle(item->x, item->y, brick, &hitNoth)) {
// item->y += 1.4 * item->direction.get_y();
// item->x -= 1.4 * item->direction.get_x();
//}
switch(hitData.config) {
/** Collision with a corner: it is a point 2 point collision
* so use the impact vector. */
case 0:
case 2:
case 4:
case 6:
item->bounceX();
item->bounceY();
return;
/** Collision with an edge: it is point 2 line collision
* so the adjustement vector depends only on the
* line verticality. */
case 1:
case 5:
item->bounceY();
return;
case 3:
case 7:
item->bounceX();
return;
default:
return;
break;
}
}
}
}
}