-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfantasma.cc
More file actions
108 lines (86 loc) · 2.71 KB
/
Copy pathfantasma.cc
File metadata and controls
108 lines (86 loc) · 2.71 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
#include "fantasma.hh"
using namespace std;
using namespace pro2;
// Direccion para el movimiento horizontal
// double direccion = 0.5;
// Variables globales para los sprites
const int width = 6;
const int height = 15;
// Paleta de Colores para moneda
const int _ = -1;
const int h = pro2::white;
const int o = pro2::black;
const int r = pro2::red;
const int s = 0xecc49b;
const int b = 0x5e6ddc;
const int y = pro2::yellow;
const int g = 0xd8d8c8;
const int w = 0x8d573c;
const int v = pro2::green;
const int a = 0x0a6fb6; // azul oscuro
const int c = 0x6ec6e8; // azul claro
const int d = 0xbfefff; // brillo
const vector<vector<int>> Fantasma::sprite_fantasma = {
{_, _, _, _, h, h, h, h, _, _, _, _},
{_, _, _, h, h, h, h, h, h, _, _, _},
{_, _, h, h, h, h, h, h, h, h, _, _},
{_, h, h, h, h, h, h, h, h, h, h, _},
{h, h, h, h, h, h, h, h, h, h, h, h},
{h, h, h, _, h, h, _, h, h, h, h, h},
{h, h, h, _, h, h, _, h, h, h, h, h},
{h, h, h, h, h, _, h, h, h, h, h, h},
{h, h, h, h, h, h, h, h, h, h, h, h},
{h, h, h, h, h, h, h, h, h, h, h, h},
{h, h, h, h, h, h, h, h, h, h, h, h},
{h, h, h, h, h, h, h, h, h, h, h, h},
{_, h, h, h, h, h, h, h, h, h, h, _},
{_, _, h, _, h, _, h, _, h, _, _, _},
{_, _, _, h, _, h, _, h, _, _, _, _},
{_, _, _, _, _, _, _, _, _, _, _, _},
};
Fantasma::Fantasma(Pt pos) {
pos_ = { pos.x , pos.y };
xoffset_ = 0.0;
yoffset_ = 0.0;
}
void Fantasma::update(pro2::Window& window) {
// Movimiento horizontal (eje x)
xoffset_ += direccion;
if (xoffset_ > 30) {
direccion = -0.5;
}
else if (xoffset_ < -30) {
direccion = 0.5;
}
// Movimiento vertical (eje y)
yoffset_ = 30 * sin(0.125 * window.frame_count());
}
void Fantasma::paint(pro2::Window& window, bool paused_) const {
Pt p = { int(pos_.x + xoffset_), int(pos_.y + yoffset_) };
const Pt punto = {p.x - width, p.y - height};
int ciclo = paused_ ? 0 : (window.frame_count() / 15) % 9;
if (ciclo < 8) {
bool mirror = direccion > 0 ? true : false;
paint_sprite(window, punto, sprite_fantasma, mirror);
}
}
Rect Fantasma::get_rect() const {
pro2::Rect r;
r.left = pos_.x + int(xoffset_) - width/2;
r.right = pos_.x + int(xoffset_) + width/2;
r.bottom = pos_.y + int(yoffset_);
r.top = pos_.y + int(yoffset_) - height;
return r;
}
int Fantasma::get_pos_x() const {
return pos_.x;
}
int Fantasma::get_pos_y() const {
return pos_.y;
}
double Fantasma::get_xoffset() const {
return xoffset_;
}
double Fantasma::get_yoffset() const {
return yoffset_;
}