mirror of
https://github.com/JoeyDeVries/LearnOpenGL.git
synced 2026-01-02 04:37:54 +08:00
Update Breakout game code.
This commit is contained in:
@@ -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)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user