-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStar.cpp
64 lines (54 loc) · 1.09 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
#include "Star.h"
bool Star::sScroll = false;
void Star::Scroll(bool b)
{
sScroll = b;
}
Star::Star(int layer)
: Texture("stars.png", 0,0,4,4)
{
mTimer = Timer::Instance();
int starColor = rand() % 4;
mClipRect.x = starColor * 4;
Pos(Vector2(rand() % Graphics::Instance()->SCREEN_WIDTH, rand() % Graphics::Instance()->SCREEN_HEIGHT));
mFlickerTimer = 0.0f;
mFlickerSpeed = 0.15f + ((float)rand() / RAND_MAX) * 0.45f;
float invLayer = 1.0f / layer;
Scale(VEC2_ONE * invLayer);
mScrollSpeed = 4.0f / layer;
}
Star::~Star()
{
mTimer = NULL;
}
void Star::ScrollStar()
{
Translate(VEC2_UP * mScrollSpeed, world);
Vector2 pos = Pos(local);
if (pos.y > Graphics::Instance()->SCREEN_HEIGHT)
{
pos.y = 0.0f;
pos.x = rand() % Graphics::Instance()->SCREEN_WIDTH;
Pos(pos);
}
}
void Star::Update()
{
mFlickerTimer += mTimer->DeltaTime();
if (mFlickerTimer >= mFlickerSpeed)
{
mVisible = !mVisible;
mFlickerTimer = 0.0f;
}
if (sScroll)
{
ScrollStar();
}
}
void Star::Render()
{
if (mVisible)
{
Texture::Render();
}
}