-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBackground.cpp
More file actions
77 lines (66 loc) · 1.47 KB
/
Background.cpp
File metadata and controls
77 lines (66 loc) · 1.47 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
#include "include/Background.hpp"
#include "include/Cloud.hpp"
Background::Background(sf::Texture *texture)
{
Cloud *cloud;
cloud = new Cloud(100, -40, texture);
cloud->dirX = -1;
cloud->velX = 0.08;
clouds.push_back(cloud);
cloud = new Cloud(300, 150, texture);
cloud->dirX = -1;
cloud->velX = 0.10;
cloud->spritePosY = 160;
clouds.push_back(cloud);
cloud = new Cloud(200, 320, texture);
cloud->dirX = -1;
cloud->velX = 0.14;
clouds.push_back(cloud);
cloud = new Cloud(400, 480, texture);
cloud->dirX = -1;
cloud->velX = 0.12;
cloud->spritePosY = 320;
clouds.push_back(cloud);
cloud = new Cloud(150, 660, texture);
cloud->dirX = -1;
cloud->velX = 0.16;
clouds.push_back(cloud);
cloud = new Cloud(650, 330, texture);
cloud->dirX = -1;
cloud->velX = 0.16;
cloud->spritePosY = 320;
clouds.push_back(cloud);
}
void Background::Background::Update()
{
for (Cloud *cloud : clouds)
{
cloud->Update();
}
}
void Background::Background::MoveUp(float dy)
{
for (Cloud *cloud : clouds)
{
cloud->posY = cloud->posY - (dy / 2);
if (cloud->posY > 800)
{
cloud->posY = -200;
}
}
}
void Background::Render(sf::RenderWindow &window)
{
for (Cloud *cloud : clouds)
{
cloud->Render(window);
}
}
Background::~Background()
{
for (Cloud *cloud : clouds)
{
delete cloud;
}
clouds.clear();
}