forked from bermo0d/mipt_arkanoid_cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlatform.cpp
More file actions
50 lines (37 loc) · 1.01 KB
/
Platform.cpp
File metadata and controls
50 lines (37 loc) · 1.01 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
#include "Platform.h"
#include "Graph_lib/Graph.h"
#include "iostream"
#include <FL/fl_draw.H>
#include <FL/Fl_PNG_Image.H>
#include <ctime>
using namespace Graph_lib;
Platform::Platform(Point xy, int ww, int hh) : Rectangle(xy, ww, hh) {
}
void Platform::setPos(int x, int y) {
set_point(0, Point{x, y});
}
void Platform::triggerAwake() {
awake = true;
awakeStartTime = std::time(nullptr);
}
void Platform::draw_lines() const {
int x = point(0).x;
int y = point(0).y;
int w = width();
int h = height();
if (awake && std::time(nullptr) - awakeStartTime > 0.4) {
awake = false;
}
const char* texturePath = awake ?
"sources/textures/awaked_platform.png" :
"sources/textures/sleepy_platform.png";
Fl_PNG_Image texture(texturePath);
if (texture.w() > 0) {
texture.draw(x, y, w, h);
} else {
fl_color(awake ? FL_RED : FL_BLUE);
fl_rectf(x, y, w, h);
}
fl_color(FL_BLACK);
fl_rect(x, y, w, h);
}