mirror of
https://github.com/JoeyDeVries/LearnOpenGL.git
synced 2026-01-03 23:33:23 +08:00
Update Breakout game code.
This commit is contained in:
@@ -9,7 +9,7 @@
|
|||||||
#include "game.h"
|
#include "game.h"
|
||||||
|
|
||||||
Game::Game(unsigned int width, unsigned int height)
|
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)
|
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;
|
GameObject *Player;
|
||||||
|
|
||||||
Game::Game(unsigned int width, unsigned int height)
|
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 <glad/glad.h>
|
||||||
#include <GLFW/glfw3.h>
|
#include <GLFW/glfw3.h>
|
||||||
|
|
||||||
|
#include "game_level.h"
|
||||||
|
|
||||||
// Represents the current state of the game
|
// Represents the current state of the game
|
||||||
enum GameState {
|
enum GameState {
|
||||||
GAME_ACTIVE,
|
GAME_ACTIVE,
|
||||||
@@ -34,6 +36,8 @@ public:
|
|||||||
GameState State;
|
GameState State;
|
||||||
bool Keys[1024];
|
bool Keys[1024];
|
||||||
unsigned int Width, Height;
|
unsigned int Width, Height;
|
||||||
|
std::vector<GameLevel> Levels;
|
||||||
|
unsigned int Level;
|
||||||
// constructor/destructor
|
// constructor/destructor
|
||||||
Game(unsigned int width, unsigned int height);
|
Game(unsigned int width, unsigned int height);
|
||||||
~Game();
|
~Game();
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ GameObject *Player;
|
|||||||
BallObject *Ball;
|
BallObject *Ball;
|
||||||
|
|
||||||
Game::Game(unsigned int width, unsigned int height)
|
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;
|
ParticleGenerator *Particles;
|
||||||
|
|
||||||
Game::Game(unsigned int width, unsigned int height)
|
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;
|
float ShakeTime = 0.0f;
|
||||||
|
|
||||||
Game::Game(unsigned int width, unsigned int height)
|
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;
|
float ShakeTime = 0.0f;
|
||||||
|
|
||||||
Game::Game(unsigned int width, unsigned int height)
|
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();
|
this->DoCollisions();
|
||||||
// update particles
|
// update particles
|
||||||
Particles->Update(dt, *Ball, 2, glm::vec2(Ball->Radius / 2.0f));
|
Particles->Update(dt, *Ball, 2, glm::vec2(Ball->Radius / 2.0f));
|
||||||
|
// update PowerUps
|
||||||
|
this->UpdatePowerUps(dt);
|
||||||
// reduce shake time
|
// reduce shake time
|
||||||
if (ShakeTime > 0.0f)
|
if (ShakeTime > 0.0f)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ ISoundEngine *SoundEngine = createIrrKlangDevice();
|
|||||||
float ShakeTime = 0.0f;
|
float ShakeTime = 0.0f;
|
||||||
|
|
||||||
Game::Game(unsigned int width, unsigned int height)
|
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();
|
this->DoCollisions();
|
||||||
// update particles
|
// update particles
|
||||||
Particles->Update(dt, *Ball, 2, glm::vec2(Ball->Radius / 2.0f));
|
Particles->Update(dt, *Ball, 2, glm::vec2(Ball->Radius / 2.0f));
|
||||||
|
// update PowerUps
|
||||||
|
this->UpdatePowerUps(dt);
|
||||||
// reduce shake time
|
// reduce shake time
|
||||||
if (ShakeTime > 0.0f)
|
if (ShakeTime > 0.0f)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user