-
Notifications
You must be signed in to change notification settings - Fork 0
/
Star.cpp
87 lines (68 loc) · 1.97 KB
/
Star.cpp
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
#include "Star.h"
Star::Star()
{
pX = 0;
pY = 0;
lastpX = 0;
lastpY = 0;
velX = 0;
velY = 0;
accelX = 0;
accelY = 0;
dumping = 0;
for (int j = 0; j < SPRITE_SIZE; ++j)
{
for (int i = 0; i < SPRITE_SIZE; ++i)
{
this->sprite[j][i].r = 0;
this->sprite[j][i].g = 0;
this->sprite[j][i].b = 0;
this->sprite[j][i].a = 255;
}
}
}
Star::~Star(){}
void Star::Move()
{
if((isnormal(accelX) || accelX == 0)
&& (isnormal(accelY) || accelY == 0))
{
velX += accelX*(1.f-dumping);
velY += accelY*(1.f-dumping);
if((isnormal(pX) || pX == 0)
&& (isnormal(pY) || pY == 0))
{
lastpX = pX;
lastpY = pY;
pX += velX;
pY += velY;
}
}
}
void Star::SetColor(unsigned char red, unsigned char green, unsigned char blue)
{
this->red = red;
this->green = green;
this->blue = blue;
// Sets color in an arbitrary way.
this->sprite[0][0] = {red, green, blue, 255};
this->sprite[1][0] = {red, 255, 255, 255};
this->sprite[2][0] = {red, green, blue, 255};
this->sprite[0][1] = {255, green, 255, 255};
// this->sprite[1][1] = {red, green, blue, 255};
this->sprite[1][1] = {255, 255, 255, 255};
this->sprite[2][1] = {255, 255, blue, 255};
this->sprite[0][2] = {red, green, blue, 255};
this->sprite[1][2] = {255, 255, 255, 255};
this->sprite[2][2] = {red, green, blue, 255};
/* // Sets color raw.
this->sprite[0][0] = {red, green, blue, 255};
this->sprite[1][0] = {red, green, blue, 255};
this->sprite[2][0] = {red, green, blue, 255};
this->sprite[0][1] = {red, green, blue, 255};
this->sprite[1][1] = {red, green, blue, 255};
this->sprite[2][1] = {red, green, blue, 255};
this->sprite[0][2] = {red, green, blue, 255};
this->sprite[1][2] = {red, green, blue, 255};
this->sprite[2][2] = {red, green, blue, 255};*/
}