-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWorld.hpp
92 lines (69 loc) · 1.7 KB
/
World.hpp
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
#ifndef WORLD_HPP
#define WORLD_HPP
#include "ResourceHolder.hpp"
#include "ResourceIdentifier.hpp"
#include "SceneNode.hpp"
#include "SpriteNode.hpp"
#include "Aircraft.hpp"
#include "CommandQueue.hpp"
#include <SFML/System/NonCopyable.hpp>
#include <SFML/Graphics/View.hpp>
#include <SFML/Graphics/Texture.hpp>
#include <array>
class World : private sf::NonCopyable
{
public:
explicit World(sf::RenderWindow &window, FontHolder &fonts);
void update(sf::Time dt);
void draw();
CommandQueue & getCommandQueue();
bool hasAlivePlayer() const;
bool hasPlayerReachedEnd() const;
private:
void loadTextures();
void buildScene();
void adaptPlayerVelocity();
void adaptPlayerPosition();
sf::FloatRect getViewBounds() const;
sf::FloatRect getBattlefieldBounds() const;
void spawnEnemies();
void addEnemies();
void addEnemy(Aircraft::Type type, float x, float y);
void guideMissiles();
void destroyEntitiesOutsideView();
void handleCollisions();
private:
enum Layer
{
Background,
Air,
LayerCount,
};
struct SpawnPoint
{
SpawnPoint(Aircraft::Type type, float x, float y)
: type(type)
, x(x)
, y(y)
{}
Aircraft::Type type;
float x;
float y;
};
private:
sf::RenderWindow &mWindow;
sf::View mWorldView;
TextureHolder mTextures;
FontHolder &mFonts;
SceneNode mSceneGraph;
std::array<SceneNode *, LayerCount> mSceneLayers;
sf::FloatRect mWorldBounds;
sf::Vector2f mSpawnPosition;
float mScrollSpeed;
Aircraft *mPlayerAircraft;
CommandQueue mCommandQueue;
std::vector<SpawnPoint> mEnemySpawnPoints;
std::vector<Aircraft *> mActiveEnemies;
};
bool matchesCategories(SceneNode::Pair &colliders, Category::Type type1, Category::Type type2);
#endif