Added automatic respawn on player death, enemies firing after death.
This commit is contained in:
parent
28b086fdc4
commit
392afec39c
3 changed files with 17 additions and 5 deletions
|
@ -18,6 +18,14 @@
|
||||||
|
|
||||||
const int Game::FPS_GOAL = 60;
|
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).
|
* Initializes game, including window and objects (sprites).
|
||||||
*/
|
*/
|
||||||
|
@ -31,11 +39,7 @@ Game::Game(tgui::Window& window) :
|
||||||
mWindow.setKeyRepeatEnabled(false);
|
mWindow.setKeyRepeatEnabled(false);
|
||||||
|
|
||||||
mGenerator.generateCurrentAreaIfNeeded(Vector2f());
|
mGenerator.generateCurrentAreaIfNeeded(Vector2f());
|
||||||
mPlayer = std::shared_ptr<Player>(new Player(mWorld, mPathfinder,
|
initPlayer();
|
||||||
mGenerator.getPlayerSpawn()));
|
|
||||||
mPlayer->setLeftGadget(std::shared_ptr<Gadget>(new Heal()));
|
|
||||||
mPlayer->setRightGadget(std::shared_ptr<Gadget>(new Shield()));
|
|
||||||
mWorld.insertCharacter(mPlayer);
|
|
||||||
|
|
||||||
mHealth = window.add<tgui::Label>();
|
mHealth = window.add<tgui::Label>();
|
||||||
mHealth->setTextSize(20);
|
mHealth->setTextSize(20);
|
||||||
|
@ -69,6 +73,10 @@ Game::loop() {
|
||||||
elapsed = 0;
|
elapsed = 0;
|
||||||
|
|
||||||
mWorld.think(elapsed);
|
mWorld.think(elapsed);
|
||||||
|
if (mPlayer->getHealth() == 0) {
|
||||||
|
mWorld.remove(mPlayer);
|
||||||
|
initPlayer();
|
||||||
|
}
|
||||||
|
|
||||||
mWorld.step(elapsed);
|
mWorld.step(elapsed);
|
||||||
|
|
||||||
|
|
|
@ -38,6 +38,7 @@ private:
|
||||||
|
|
||||||
Vector2<float> convertCoordinates(int x, int y);
|
Vector2<float> convertCoordinates(int x, int y);
|
||||||
void updateGui();
|
void updateGui();
|
||||||
|
void initPlayer();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static const int FPS_GOAL;
|
static const int FPS_GOAL;
|
||||||
|
|
|
@ -72,6 +72,9 @@ Character::onDamage(int damage) {
|
||||||
*/
|
*/
|
||||||
void
|
void
|
||||||
Character::onThink(int elapsed) {
|
Character::onThink(int elapsed) {
|
||||||
|
if (mCurrentHealth == 0)
|
||||||
|
return;
|
||||||
|
|
||||||
mActiveWeapon->onThink(elapsed);
|
mActiveWeapon->onThink(elapsed);
|
||||||
if (mLeftGadget)
|
if (mLeftGadget)
|
||||||
mLeftGadget->onThink(elapsed);
|
mLeftGadget->onThink(elapsed);
|
||||||
|
|
Reference in a new issue