-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGame.h
111 lines (94 loc) · 2.7 KB
/
Game.h
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
110
111
//
// Created by samuel on 12/5/21.
//
#ifndef SFML_GAME_GAME_H
#define SFML_GAME_GAME_H
#include "Object.h"
#include "Player.h"
#include "Asteroid.h"
#include "Projectile.h"
#include "Menu.h"
#include "Enemy.h"
#include "Animation.h"
#include <vector>
#include <algorithm>
//! Can be considered a wrapper class or game engine for the Asteroids game. It's responsible for all states of the game, updating, rendering. As well as handling the menu, keyboard inputs.
class Game {
public:
/**
* Default constructor
* @param width Width of the application window(in pixels).
* @param height Height of the application window(in pixels).
*/
Game(const unsigned int width, const unsigned int height);
/**
* Checks if the application window is open.
* @return True if the window is open.
*/
const bool running() const;
//Functions
/**
* Handles all keyboard inputs.
*/
void pollEvents();
/**
* Updates all members, objects belonging to the Game class.
*/
void update();
/**
* Renders all the Game objects to the application window.
*/
void render();
private:
//Members
sf::RenderWindow window;
sf::Event event;
sf::Text score;
int points = 0;
sf::Font textFont;
Menu menu;
//Textures
//Player spaceship;
std::unique_ptr<Player> spaceship;
std::unique_ptr<Enemy> enemy;
sf::Texture tBackground, tExplosion, tAsteroid, tProjectile;
//Sprites
sf::Sprite sBackground;
//Container for objects
std::vector<std::unique_ptr<Object>> objects;
std::vector<Animation> animations;
//Game music
sf::Music gameMusic;
sf::SoundBuffer buffer;
sf::SoundBuffer buffer2;
sf::Sound asteroidDeath;
sf::Sound projectileFired;
std::string Space_Invaders = "sounds/Teminite & MDK - Space Invaders [Monstercat Remake].ogg";
std::string Arcade_Bit_Rush = "sounds/Bit Rush - Arcade 2015 _ Login Screen - League of Legends.ogg";
std::string cigg_pk = "sounds/cigg_pk.ogg";
std::string Hopes_And_Dreams = "sounds/Undertale Ost - 087 - Hopes and Dreams.ogg";
// State checkers
void centerWindowPosition();
void checkObjectCollision();
void checkPlayerCollision();
void startGame();
void clearGame();
//Objects
void generateAsteroids();
void generateProjectile();
void generatePlayer();
void generateBoss();
void updateObjects();
void updateEnemy();
void updateScore();
void updateAnimations();
void drawObjects();
//Player
void updatePlayer();
bool isAnyKeyPressed();
//Initialization
void initTextures();
void initSprites();
void initSounds();
};
#endif //SFML_GAME_GAME_H