|
|
@@ -12,6 +12,8 @@
|
|
|
#include "Actor.h"
|
|
|
#include "SpriteComponent.h"
|
|
|
#include "Ship.h"
|
|
|
+#include "Asteroid.h"
|
|
|
+#include "Random.h"
|
|
|
|
|
|
Game::Game()
|
|
|
:mWindow(nullptr)
|
|
|
@@ -50,6 +52,8 @@ bool Game::Initialize()
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
+ Random::Init();
|
|
|
+
|
|
|
LoadData();
|
|
|
|
|
|
mTicksCount = SDL_GetTicks();
|
|
|
@@ -80,14 +84,18 @@ void Game::ProcessInput()
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- const Uint8* state = SDL_GetKeyboardState(NULL);
|
|
|
- if (state[SDL_SCANCODE_ESCAPE])
|
|
|
+ const Uint8* keyState = SDL_GetKeyboardState(NULL);
|
|
|
+ if (keyState[SDL_SCANCODE_ESCAPE])
|
|
|
{
|
|
|
mIsRunning = false;
|
|
|
}
|
|
|
|
|
|
- // Process ship input
|
|
|
- mShip->ProcessKeyboard(state);
|
|
|
+ mUpdatingActors = true;
|
|
|
+ for (auto actor : mActors)
|
|
|
+ {
|
|
|
+ actor->ProcessInput(keyState);
|
|
|
+ }
|
|
|
+ mUpdatingActors = false;
|
|
|
}
|
|
|
|
|
|
void Game::UpdateGame()
|
|
|
@@ -138,7 +146,7 @@ void Game::UpdateGame()
|
|
|
|
|
|
void Game::GenerateOutput()
|
|
|
{
|
|
|
- SDL_SetRenderDrawColor(mRenderer, 0, 0, 0, 255);
|
|
|
+ SDL_SetRenderDrawColor(mRenderer, 220, 220, 220, 255);
|
|
|
SDL_RenderClear(mRenderer);
|
|
|
|
|
|
// Draw all sprite components
|
|
|
@@ -154,7 +162,15 @@ void Game::LoadData()
|
|
|
{
|
|
|
// Create player's ship
|
|
|
mShip = new Ship(this);
|
|
|
- mShip->SetPosition(Vector2(100.0f, 384.0f));
|
|
|
+ mShip->SetPosition(Vector2(512.0f, 384.0f));
|
|
|
+ mShip->SetRotation(Math::PiOver2);
|
|
|
+
|
|
|
+ // Create asteroids
|
|
|
+ const int numAsteroids = 20;
|
|
|
+ for (int i = 0; i < numAsteroids; i++)
|
|
|
+ {
|
|
|
+ new Asteroid(this);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
void Game::UnloadData()
|
|
|
@@ -207,6 +223,21 @@ SDL_Texture* Game::GetTexture(const std::string& fileName)
|
|
|
return tex;
|
|
|
}
|
|
|
|
|
|
+void Game::AddAsteroid(Asteroid* ast)
|
|
|
+{
|
|
|
+ mAsteroids.emplace_back(ast);
|
|
|
+}
|
|
|
+
|
|
|
+void Game::RemoveAsteroid(Asteroid* ast)
|
|
|
+{
|
|
|
+ auto iter = std::find(mAsteroids.begin(),
|
|
|
+ mAsteroids.end(), ast);
|
|
|
+ if (iter != mAsteroids.end())
|
|
|
+ {
|
|
|
+ mAsteroids.erase(iter);
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
void Game::Shutdown()
|
|
|
{
|
|
|
UnloadData();
|