This repository was archived by the owner on Aug 10, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBaseObject.cpp
More file actions
158 lines (154 loc) · 3.89 KB
/
Copy pathBaseObject.cpp
File metadata and controls
158 lines (154 loc) · 3.89 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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#include "BaseObject.h"
Vector Vector::operator = (const Vector& rhs) {
_x = rhs._x;
_y = rhs._y;
return *this;
}
Vector Vector::operator + (const Vector& rhs) const {
return Vector(_x + rhs._x, _y + rhs._y);
}
Vector Vector::operator - (const Vector& rhs) const {
return Vector(_x - rhs._x, _y - rhs._y);
}
Vector Vector::operator * (const double rhs) const {
return Vector(_x * rhs, _y * rhs);
}
Vector Vector::operator / (const double rhs) const {
return Vector(_x / rhs, _y / rhs);
}
Vector Vector::operator += (const Vector& rhs) {
*this = *this + rhs;
return *this;
}
Vector Vector::operator -= (const Vector& rhs) {
*this = *this - rhs;
return *this;
}
Vector Vector::operator *= (const double rhs) {
*this = *this * rhs;
return *this;
}
Vector Vector::operator /= (const double rhs) {
*this = *this / rhs;
return *this;
}
bool Vector::operator == (const Vector& rhs) const {
if(_x == rhs._x && _y == rhs._y) return true;
else return false;
}
bool Vector::operator == (const double rhs) const {
if(_x == rhs && _y == rhs) return true;
else return false;
}
bool Vector::operator != (const Vector& rhs) const {
if(*this == rhs) return false;
else return true;
}
double Vector::x() const { return (_x); }
double Vector::y() const { return (_y); }
void Vector::x(double x) { _x = x; }
void Vector::y(double y) { _y = y; }
void Vector::set(double x, double y) { _x = x, _y = y; }
void Figure::addFigure(string name, vector<IMAGE> imgs, vector<IMAGE> masks, function<bool(void)> tigger) {
if(figures.empty() && !imgs.empty()) {
_width = imgs.front().getwidth();
_height = imgs.front().getheight();
}
figures.push_back(FigureData{name, imgs, masks, tigger});
}
void Figure::clear()
{
figure_cnt = 0;
figures.clear();
_status = "default";
}
void Figure::update(int x, int y) {
for(auto& i : figures)
{
if(i.tigger()) {
if(i.name!="rock0"&&i.name!="rock1")
//cout << i.name << endl;
if(_status != i.name) {
time_tick = steady_clock::now();
figure_cnt = 0;
_status = i.name;
}
//cout << figure_cnt << endl;
//ûÈË·¢ÏÖÎÒдµÄbug
putimage(x, y, &i.masks[figure_cnt % i.images.size()], NOTSRCERASE);
putimage(x, y, &i.images[figure_cnt % i.images.size()], SRCINVERT);
if((steady_clock::now() - time_tick) >= milliseconds(100)) {
figure_cnt = (figure_cnt + 1) % i.images.size();
time_tick = steady_clock::now();
}
return;
}
}
}
void Figure::turn() {
for(auto& i : figures)
{
for(auto& j : i.images) rotateFlip(&j);
for(auto& j : i.masks) rotateFlip(&j);
}
}
string Figure::status()
{
return _status;
}
void Figure::status(string s)
{
_status = s;
}
int Figure::width() {
return _width;
}
int Figure::height() {
return _height;
}
int BaseObject::counter = 0;
int BaseObject::width() {
return _width;
}
int BaseObject::height() {
return _height;
}
int BaseObject::get_id()
{
return id;
}
string BaseObject::type()
{
return _type;
}
void BaseObject::width(int w) {
_width = w;
}
void BaseObject::height(int h) {
_height = h;
}
void BaseObject::type(string t)
{
_type = t;
}
void BaseObject::update(double time) {
if(killed)return;
position += (velocity * time + acceleration * time * time / 2);
//position += velocity * time;
velocity += acceleration * time;
}
void BaseObject::show(Vector& offset) {
figure.update(static_cast<int>(round(position.x()) + offset.x()), static_cast<int>(round(position.y()) + offset.y()));
}
void BaseObject::kill()
{
killed = true;
}
void BaseObject::revive()
{
killed = false;
}
bool BaseObject::is_killed()
{
return killed == true;
}