Random item is dropped on death.

This commit is contained in:
Felix Ableitner 2013-08-29 21:53:14 +02:00
parent 7bb08ed447
commit 6b1e8d906f
3 changed files with 24 additions and 5 deletions

View file

@ -31,6 +31,7 @@ Game::Game(tgui::Window& window) :
mPaused(false) { mPaused(false) {
mWindow.setFramerateLimit(FPS_GOAL); mWindow.setFramerateLimit(FPS_GOAL);
mWindow.setKeyRepeatEnabled(false); mWindow.setKeyRepeatEnabled(false);
srand(time(nullptr));
mGenerator.generateCurrentAreaIfNeeded(Vector2f()); mGenerator.generateCurrentAreaIfNeeded(Vector2f());
initPlayer(); initPlayer();

View file

@ -91,17 +91,34 @@ Character::getFaction() const {
return mFaction; return mFaction;
} }
void Character::dropItem(std::shared_ptr<Item> item) {
mWorld.insert(item);
item->drop(getPosition());
}
/** /**
* Called when health reaches zero. Drops corpse and item. * Called when health reaches zero, drops corpse and a random item.
*/ */
void void
Character::onDeath() { Character::onDeath() {
mWorld.insert(std::shared_ptr<Sprite>(new Corpse(getPosition()))); mWorld.insert(std::shared_ptr<Sprite>(new Corpse(getPosition())));
mWorld.insert(mActiveWeapon); switch (rand() % 3) {
mActiveWeapon->drop(getPosition()); case 0:
// To avoid the weapon continuing to fire after pickup. dropItem(mFirstWeapon);
mActiveWeapon->releaseTrigger(); break;
case 1:
dropItem(mSecondWeapon);
break;
case 2:
if (mLeftGadget.get() != nullptr)
dropItem(mLeftGadget);
else if (mRightGadget.get() != nullptr)
dropItem(mRightGadget);
}
// To avoid weapons continuing to fire after drop and pickup.
mFirstWeapon->releaseTrigger();
mSecondWeapon->releaseTrigger();
} }

View file

@ -73,6 +73,7 @@ protected:
private: private:
void move(); void move();
void dropItem(std::shared_ptr<Item> item);
private: private:
friend class Shield; friend class Shield;