Update Breakout game code.

This commit is contained in:
Joey de Vries
2020-05-26 17:01:45 +02:00
parent fb5d791d7f
commit 1385c8a239
9 changed files with 16 additions and 8 deletions

View File

@@ -9,7 +9,7 @@
#include "game.h"
Game::Game(unsigned int width, unsigned int height)
: State(GAME_MENU), Keys(), Width(width), Height(height)
: State(GAME_ACTIVE), Keys(), Width(width), Height(height)
{
}

View File

@@ -16,7 +16,7 @@ SpriteRenderer *Renderer;
Game::Game(unsigned int width, unsigned int height)
: State(GAME_MENU), Keys(), Width(width), Height(height)
: State(GAME_ACTIVE), Keys(), Width(width), Height(height)
{
}

View File

@@ -16,7 +16,7 @@ SpriteRenderer *Renderer;
GameObject *Player;
Game::Game(unsigned int width, unsigned int height)
: State(GAME_MENU), Keys(), Width(width), Height(height)
: State(GAME_ACTIVE), Keys(), Width(width), Height(height)
{
}

View File

@@ -12,6 +12,8 @@
#include <glad/glad.h>
#include <GLFW/glfw3.h>
#include "game_level.h"
// Represents the current state of the game
enum GameState {
GAME_ACTIVE,
@@ -34,6 +36,8 @@ public:
GameState State;
bool Keys[1024];
unsigned int Width, Height;
std::vector<GameLevel> Levels;
unsigned int Level;
// constructor/destructor
Game(unsigned int width, unsigned int height);
~Game();

View File

@@ -18,7 +18,7 @@ GameObject *Player;
BallObject *Ball;
Game::Game(unsigned int width, unsigned int height)
: State(GAME_MENU), Keys(), Width(width), Height(height)
: State(GAME_ACTIVE), Keys(), Width(width), Height(height)
{
}

View File

@@ -20,7 +20,7 @@ BallObject *Ball;
ParticleGenerator *Particles;
Game::Game(unsigned int width, unsigned int height)
: State(GAME_MENU), Keys(), Width(width), Height(height)
: State(GAME_ACTIVE), Keys(), Width(width), Height(height)
{
}

View File

@@ -24,7 +24,7 @@ PostProcessor *Effects;
float ShakeTime = 0.0f;
Game::Game(unsigned int width, unsigned int height)
: State(GAME_MENU), Keys(), Width(width), Height(height)
: State(GAME_ACTIVE), Keys(), Width(width), Height(height)
{
}

View File

@@ -26,7 +26,7 @@ PostProcessor *Effects;
float ShakeTime = 0.0f;
Game::Game(unsigned int width, unsigned int height)
: State(GAME_MENU), Keys(), Width(width), Height(height)
: State(GAME_ACTIVE), Keys(), Width(width), Height(height)
{
}
@@ -95,6 +95,8 @@ void Game::Update(float dt)
this->DoCollisions();
// update particles
Particles->Update(dt, *Ball, 2, glm::vec2(Ball->Radius / 2.0f));
// update PowerUps
this->UpdatePowerUps(dt);
// reduce shake time
if (ShakeTime > 0.0f)
{

View File

@@ -30,7 +30,7 @@ ISoundEngine *SoundEngine = createIrrKlangDevice();
float ShakeTime = 0.0f;
Game::Game(unsigned int width, unsigned int height)
: State(GAME_MENU), Keys(), Width(width), Height(height)
: State(GAME_ACTIVE), Keys(), Width(width), Height(height)
{
}
@@ -102,6 +102,8 @@ void Game::Update(float dt)
this->DoCollisions();
// update particles
Particles->Update(dt, *Ball, 2, glm::vec2(Ball->Radius / 2.0f));
// update PowerUps
this->UpdatePowerUps(dt);
// reduce shake time
if (ShakeTime > 0.0f)
{