Levels
This commit is contained in:
54
src/game.cpp
54
src/game.cpp
@@ -15,6 +15,14 @@ Game::Game(unsigned int width, unsigned int height)
|
||||
|
||||
}
|
||||
|
||||
// Initial size of the player paddle
|
||||
const glm::vec2 PLAYER_SIZE (100.0f, 20.0f);
|
||||
// Initial velocity of the player paddle
|
||||
const float PLAYER_VELOCITY(500.0f);
|
||||
GameObject* player;
|
||||
|
||||
|
||||
|
||||
void Game::Init()
|
||||
{
|
||||
// Load shaders
|
||||
@@ -27,12 +35,44 @@ void Game::Init()
|
||||
Renderer = new SpriteRenderer(ResourceManager::GetShader("sprite"));
|
||||
// load textures
|
||||
ResourceManager::LoadTexture("textures/awesomeface.png", true, "face");
|
||||
ResourceManager::LoadTexture("textures/background.jpg", false, "background");
|
||||
ResourceManager::LoadTexture("textures/block.png", false, "block");
|
||||
ResourceManager::LoadTexture("textures/block_solid.png", false, "block_solid");
|
||||
ResourceManager::LoadTexture("textures/paddle.png", true, "paddle");
|
||||
// Load levels
|
||||
GameLevel one; one.Load("levels/one.lvl", this->Width, this->Height / 2);
|
||||
GameLevel two; two.Load("levels/two.lvl", this->Width, this->Height / 2);
|
||||
GameLevel three; three.Load("levels/three.lvl", this->Width, this->Height / 2);
|
||||
GameLevel four; four.Load("levels/four.lvl", this->Width, this->Height / 2);
|
||||
this->Levels.push_back(one);
|
||||
this->Levels.push_back(two);
|
||||
this->Levels.push_back(three);
|
||||
this->Levels.push_back(four);
|
||||
this->Level = 0;
|
||||
|
||||
glm::vec2 playerPos = glm::vec2(this->Width /2 - PLAYER_SIZE.x /2.0f,
|
||||
this->Height - PLAYER_SIZE.y);
|
||||
player = new GameObject(playerPos, PLAYER_SIZE, ResourceManager::GetTexture("paddle"));
|
||||
|
||||
}
|
||||
|
||||
|
||||
void Game::ProcessInput(float dt)
|
||||
{
|
||||
|
||||
if(this->State == GAME_ACTIVE)
|
||||
{
|
||||
float velocity = PLAYER_VELOCITY * dt;
|
||||
if( this->Keys[GLFW_KEY_A])
|
||||
{
|
||||
if(player->Position.x >= 0.0f)
|
||||
player->Position.x -= velocity;
|
||||
}
|
||||
if( this->Keys[GLFW_KEY_D])
|
||||
{
|
||||
if(player->Position.x <= this->Width - player->Size.x)
|
||||
player->Position.x += velocity;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -43,5 +83,15 @@ void Game::Update(float dt)
|
||||
|
||||
void Game::Render()
|
||||
{
|
||||
Renderer->DrawSprite(ResourceManager::GetTexture("face"), glm::vec2(200.0f, 200.0f), glm::vec2(300.0f, 400.0f), 45.0f, glm::vec3(0.0f, 1.0f,0.0f));
|
||||
if(this->State == GAME_ACTIVE)
|
||||
{
|
||||
// draw background
|
||||
Renderer->DrawSprite(ResourceManager::GetTexture("background"),
|
||||
glm::vec2(0.0f, 0.0f), glm::vec2(this->Width, this->Height), 0.0f);
|
||||
|
||||
// draw level
|
||||
this->Levels[this->Level].Draw(*Renderer);
|
||||
|
||||
player->Draw(*Renderer);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user