forked from bermo0d/mipt_arkanoid_cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBall.cpp
More file actions
63 lines (49 loc) · 1.2 KB
/
Ball.cpp
File metadata and controls
63 lines (49 loc) · 1.2 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
#include "Ball.h"
#include <FL/fl_draw.H>
#include <FL/Fl_PNG_Image.H>
#include <ctime>
Ball::Ball(Point xy, int rr) : Circle(xy, rr), prevPos(xy) {
}
int Ball::get_dx() const {
return dx;
}
int Ball::get_dy() const {
return dy;
}
void Ball::set_dx(int v) {
dx = v;
}
void Ball::set_dy(int v) {
dy = v;
}
void Ball::move(int dx, int dy) {
prevPos = point(0);
Shape::move(dx, dy);
}
void Ball::triggerHappySmile() {
happySmile = true;
happySmileStartTime = std::time(nullptr);
}
void Ball::draw_lines() const {
int x = center().x - radius();
int y = center().y - radius();
int size = radius() * 2;
if (happySmile && std::time(nullptr) - happySmileStartTime > 0.6) {
happySmile = false;
}
const char* texturePath = happySmile ?
"sources/textures/dovolny_smile.png" :
"sources/textures/smile.png";
Fl_PNG_Image texture(texturePath);
if (texture.w() > 0) {
texture.draw(x, y, size, size);
} else {
fl_color(FL_YELLOW);
fl_pie(x, y, size, size, 0, 360);
}
fl_color(FL_BLACK);
fl_arc(x, y, size, size, 0, 360);
}
void Ball::setPos(int x, int y) {
set_point(0, Point{x, y});
}