forked from SpaceGameTeam/FarOut
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPrototypeScene.cpp
More file actions
109 lines (82 loc) · 3.4 KB
/
PrototypeScene.cpp
File metadata and controls
109 lines (82 loc) · 3.4 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
// Implements the demo scene
#include "PrototypeScene.h"
#include <string>
//Background stuff
Background::Background() {
// These should be adjusted to use system-wide constants when those are implemented
int x = 1920;
int y = 1080;
int universeSize = 1000;
texture.loadFromFile("Assets/pixelated_halo_starfield_by_necro_skeletal_d56he85.png");
texture.setRepeated(true);
sprite.setTextureRect(sf::IntRect(0, 0, universeSize * x, universeSize * y));
sprite.setTexture(texture, false);
setPosition(-(universeSize * x / 2), -(universeSize * y / 2));
}
void Background::update(sf::Time dt) {}
void Background::draw(sf::RenderTarget& target, sf::RenderStates states)const {
states.transform *= getTransform();
target.draw(sprite, states);
}
//Scene stuff
// Some of the data members are dynamically allocated because constructors with arguments were written
PrototypeScene::PrototypeScene() {
alien = new AlienShip();
sun = new Star(30, sf::Color(219, 57, 5), 3, sf::Color(255, 154, 1), sf::Vector2f(-700, 200));
planetarySystemObjects = new Planet*[SYSTEMOBJECTS];
planetarySystemObjects[0] = new Planet(5, 100, sf::Color::Green, 0.5);
planetarySystemObjects[1] = new Planet(8, 140, sf::Color::Blue, 0.05);
planetarySystemObjects[2] = new Planet(10, 180, sf::Color::Magenta, 0.25);
planetarySystemObjects[3] = new Planet(4, 200, sf::Color::Yellow, 0.04);
planetarySystemObjects[4] = new Planet(50, 350, sf::Color::Cyan, 0.045);
planetarySystemObjects[5] = new Planet(25, 460, sf::Color::Green, 0.09);
planetarySystemObjects[6] = new Planet(10, 500, sf::Color::Blue, 0.03);
planetarySystemObjects[7] = new Planet(10, 540, sf::Color::Yellow, 0.2);
planetarySystemObjects[8] = new Planet(3, 600, sf::Color::Yellow, 0.15);
planetarySystemObjects[9] = new Planet(2, 15, sf::Color::White, 0.5);
planetarySystemObjects[10] = new Planet(2, 10, sf::Color::White, 0.15);
planetarySystemObjects[11] = new Planet(2, 30, sf::Color::White, 0.6);
planetarySystemObjects[12] = new Planet(1, 17, sf::Color::White, 0.9);
view.setSize(System.getData("DesktopX"), System.getData("DesktopY"));
}
// Destruct the alien, sun, and planets
PrototypeScene::~PrototypeScene() {
delete alien;
delete sun;
for(int i = 0; i < SYSTEMOBJECTS; ++i) {
delete planetarySystemObjects[i];
}
}
// Update data members that get updated
void PrototypeScene::update(sf::Time dt) {
bg.update(dt);
ship.update(dt);
alien->update(dt, ship.getPosition());
asteroid.update(dt);
sun->update(dt);
sf::Vector2f center = sun->getPosition();
for (int i = 0; i < 9; ++i) {
planetarySystemObjects[i]->update(dt, center);
}
planetarySystemObjects[9]->update(dt, planetarySystemObjects[6]->getPosition());
planetarySystemObjects[10]->update(dt, planetarySystemObjects[3]->getPosition());
planetarySystemObjects[11]->update(dt, planetarySystemObjects[8]->getPosition());
planetarySystemObjects[12]->update(dt, planetarySystemObjects[11]->getPosition());
view.setCenter(ship.getPosition());
}
// Draw all the objects in the scene
void PrototypeScene::draw(sf::RenderWindow& window) {
window.setView(view);
window.draw(bg);
window.draw(ship);
window.draw(*alien);
window.draw(*sun);
for (int i = 0; i < SYSTEMOBJECTS; ++i) {
window.draw(*planetarySystemObjects[i]);
}
window.draw(asteroid);
}
// Here so the system class can call something to know where the ship is for window.setCenter()
sf::Vector2f PrototypeScene::getCenter(){
return ship.getPosition();
}