-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwell.cpp
More file actions
67 lines (61 loc) · 1.5 KB
/
Copy pathwell.cpp
File metadata and controls
67 lines (61 loc) · 1.5 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
#include "well.hpp"
Well::Well():
data{{false}}
{
}
void Well::draw(SDL_Renderer *renderer)
{
SDL_SetRenderDrawColor(renderer, 0xff, 0xff, 0xff, 0xff);
for (auto x = 0; x < Width; ++x)
for (auto y = 0; y < Height; ++y)
{
if (data[x][y])
{
SDL_Rect rect{ x * 720 / 2 / 10 + 1, y * 720 / 2 / 10 + 1, 720 / 2 / 10 - 2, 720 / 2 / 10 - 2};
SDL_RenderFillRect(renderer, &rect);
}
else
SDL_RenderDrawPoint(renderer, x * 720 / 2 / 10 + 720 / 2 / 10 / 2,
y * 720 / 2 / 10 + 720 / 2 / 10 / 2);
}
}
bool Well::isCollision(const Tetromino &t) const
{
for (int x = 0; x < 4; ++x)
for (int y = 0; y < 4; ++y)
if (t.isBlock(x, y))
{
auto wx = t.x() + x;
auto wy = t.y() + y;
if (wx < 0 || wx >= Width || wy < 0 || wy >= Height)
return true;
if (data[wx][wy])
return true;
}
return false;
}
void Well::unite(const Tetromino &t)
{
for (int x = 0; x < 4; ++x)
for (int y = 0; y < 4; ++y)
if (t.isBlock(x, y))
data[t.x() + x][t.y() + y] = true;
for (int y = Height - 1; y >= 0; --y)
{
bool solid = true;
for (int x = 0; x < Width; ++x)
if (!data[x][y])
{
solid = false;
break;
}
if (solid)
{
for (int yy = y - 1; yy >= 0; --yy)
for (int x = 0; x < Width; ++x)
data[x][yy + 1] = data[x][yy];
for (int x = 0; x < Width; ++x)
data[x][0] = false;
}
}
}