-
Notifications
You must be signed in to change notification settings - Fork 0
/
Stars.cpp
66 lines (60 loc) · 1.31 KB
/
Stars.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
#include <iostream>
#include "Stars.h"
#include "Surface.h"
void Galaxy::draw()
{
for (int i = 0; i < SIZE; ++i)
{
if (stars[i].y() >= H - 51)
{
stars[i].y(0);
stars[i].x(rand() % W);
}
stars[i].move();
surface_.put_rect(stars[i].x(), stars[i].y(), stars[i].w(), stars[i].h(),
stars[i].r(), stars[i].g(), stars[i].b());
}
}
void Galaxy::build()
{
for (int i = 0; i < SIZE; ++i)
{
Stars star;
star.x(rand() % W);
star.y(rand() % (H - 51));
star.type(rand() % 3 + 1);
if (star.type() == 1)
{
star.w(1);
star.h(1);
star.speed(1);
star.r(150);
star.g(150);
star.b(150);
}
else if (star.type() == 2)
{
star.w(2);
star.h(2);
star.speed(2);
star.r(175);
star.g(175);
star.b(175);
}
else if (star.type() == 3)
{
star.w(2);
star.h(2);
star.speed(4);
star.r(180);
star.g(180);
star.b(255);
}
stars.push_back(star);
}
stars.shrink_to_fit();
}
void Stars::move()
{
y_ += speed_;
}