-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStarryBackground.cpp
More file actions
54 lines (43 loc) · 1011 Bytes
/
StarryBackground.cpp
File metadata and controls
54 lines (43 loc) · 1011 Bytes
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
#include "StarryBackground.h"
#include "settings.h"
StarryBackground::StarryBackground(int amount, float size, float maxSpeed) : _starAmount(amount), _maxSpeed(maxSpeed), _maxSize(size)
{
}
int randomNumber2(int minimum, int maximum)
{
int valeur{ 0 };
valeur = std::rand() % maximum;
if (valeur < minimum)
valeur = minimum;
return valeur;
}
int StarryBackground::GetStarAmount()
{
return _stars.size();
}
void StarryBackground::Init()
{
_stars.clear();
for (int i = 0; i < _starAmount; i++)
{
Vec2<float> pos{ float(randomNumber2(0, stg::screenWidth)), float(randomNumber2(0, stg::screenHeight)) };
float speed = randomNumber2(10, int(_maxSpeed)) / 10.0f;
float rayon = randomNumber2(8, int(_maxSize)) / 10.0f;
Star newStar{ pos, speed, rayon };
_stars.push_back(newStar);
}
}
void StarryBackground::Update(Vec2<float> center)
{
for (Star &star : _stars)
{
star.Update(center);
}
}
void StarryBackground::Draw()
{
for (const Star &star : _stars)
{
star.Draw();
}
}