From 392afec39c11bbf00a942674b043758cb645f917 Mon Sep 17 00:00:00 2001 From: Felix Ableitner Date: Sun, 18 Aug 2013 13:27:32 +0200 Subject: [PATCH] Added automatic respawn on player death, enemies firing after death. --- source/Game.cpp | 18 +++++++++++++----- source/Game.h | 1 + source/abstract/Character.cpp | 3 +++ 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/source/Game.cpp b/source/Game.cpp index 77531d9..5c8540e 100644 --- a/source/Game.cpp +++ b/source/Game.cpp @@ -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(new Player(mWorld, mPathfinder, - mGenerator.getPlayerSpawn())); - mPlayer->setLeftGadget(std::shared_ptr(new Heal())); - mPlayer->setRightGadget(std::shared_ptr(new Shield())); - mWorld.insertCharacter(mPlayer); + initPlayer(); mHealth = window.add(); 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); diff --git a/source/Game.h b/source/Game.h index d7f4c89..2540da9 100644 --- a/source/Game.h +++ b/source/Game.h @@ -38,6 +38,7 @@ private: Vector2 convertCoordinates(int x, int y); void updateGui(); + void initPlayer(); private: static const int FPS_GOAL; diff --git a/source/abstract/Character.cpp b/source/abstract/Character.cpp index f027e9e..4b4e306 100644 --- a/source/abstract/Character.cpp +++ b/source/abstract/Character.cpp @@ -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);