Added automatic respawn on player death, enemies firing after death.

This commit is contained in:
Felix Ableitner 2013-08-18 13:27:32 +02:00
parent 28b086fdc4
commit 392afec39c
3 changed files with 17 additions and 5 deletions

View file

@ -18,6 +18,14 @@
const int Game::FPS_GOAL = 60;
void Game::initPlayer() {
mPlayer = std::shared_ptr < Player
> (new Player(mWorld, mPathfinder, mGenerator.getPlayerSpawn()));
mPlayer->setLeftGadget(std::shared_ptr < Gadget > (new Heal()));
mPlayer->setRightGadget(std::shared_ptr < Gadget > (new Shield()));
mWorld.insertCharacter(mPlayer);
}
/**
* Initializes game, including window and objects (sprites).
*/
@ -31,11 +39,7 @@ Game::Game(tgui::Window& window) :
mWindow.setKeyRepeatEnabled(false);
mGenerator.generateCurrentAreaIfNeeded(Vector2f());
mPlayer = std::shared_ptr<Player>(new Player(mWorld, mPathfinder,
mGenerator.getPlayerSpawn()));
mPlayer->setLeftGadget(std::shared_ptr<Gadget>(new Heal()));
mPlayer->setRightGadget(std::shared_ptr<Gadget>(new Shield()));
mWorld.insertCharacter(mPlayer);
initPlayer();
mHealth = window.add<tgui::Label>();
mHealth->setTextSize(20);
@ -69,6 +73,10 @@ Game::loop() {
elapsed = 0;
mWorld.think(elapsed);
if (mPlayer->getHealth() == 0) {
mWorld.remove(mPlayer);
initPlayer();
}
mWorld.step(elapsed);

View file

@ -38,6 +38,7 @@ private:
Vector2<float> convertCoordinates(int x, int y);
void updateGui();
void initPlayer();
private:
static const int FPS_GOAL;

View file

@ -72,6 +72,9 @@ Character::onDamage(int damage) {
*/
void
Character::onThink(int elapsed) {
if (mCurrentHealth == 0)
return;
mActiveWeapon->onThink(elapsed);
if (mLeftGadget)
mLeftGadget->onThink(elapsed);