forked from bermo0d/mipt_arkanoid_cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBlock.cpp
More file actions
42 lines (34 loc) · 979 Bytes
/
Block.cpp
File metadata and controls
42 lines (34 loc) · 979 Bytes
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
#include "Block.h"
#include <FL/fl_draw.H>
#include <FL/Fl_PNG_Image.H>
Block::Block(Point xy, int width, int height, int hp)
: Rectangle(xy, width, height), health(hp), texture(nullptr) {
int textureIndex = (xy.x / width + xy.y / height) % 4;
const char* textures[] = {
"sources/textures/roflan_block.png",
"sources/textures/nerd_block.png",
"sources/textures/moustache_block.png",
"sources/textures/purple_block.png"
};
textureName = textures[textureIndex];
texture = new Fl_PNG_Image(textureName);
}
Block::~Block() {
if (texture) {
delete texture;
}
}
void Block::draw_lines() const {
int x = point(0).x;
int y = point(0).y;
int w = width();
int h = height();
if (texture && texture->w() > 0) {
texture->draw(x, y, w, h);
} else {
fl_color(FL_RED);
fl_rectf(x, y, w, h);
}
fl_color(FL_BLACK);
fl_rect(x, y, w, h);
}