-
Notifications
You must be signed in to change notification settings - Fork 0
/
sprite.hpp
53 lines (45 loc) · 1.27 KB
/
sprite.hpp
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
#pragma once
#include "pos.hpp"
class sprite {
public:
pos Pos{};
pos Motion{};
double Direction = 0; // 0:Right PI/2:Down PI:Left 3PI/2:Up
pos Size{};
pos Move() {
this->Pos.AddPos(this->Motion.GetX(), this->Motion.GetY());
return this->Pos;
}
double SetDrectionFromPos(pos Pos) {
this->Direction = std::atan2(Pos.GetY(), Pos.GetX());
return this->Direction;
}
pos GetPosFromDirection(double Radius = 1.0) {
return pos(
Radius * std::cos(this->Direction),
Radius * std::sin(this->Direction)
);
}
pos GetCenterPos() {
return pos(
this->Pos.GetX() + this->Size.GetX() / 2,
this->Pos.GetY() + this->Size.GetY() / 2
);
}
enum direction {
UP, DOWN, LEFT, RIGHT
};
double GetSidePos(enum direction Direction) {
switch (Direction) {
case this->UP:
return this->Pos.GetY();
case this->DOWN:
return this->Pos.GetY() + this->Size.GetY();
case this->LEFT:
return this->Pos.GetX();
case this->RIGHT:
return this->Pos.GetX() + this->Size.GetX();
}
return 0;
}
};