From 35c21260e4b1f55c78b7bf70b239487b75f06956 Mon Sep 17 00:00:00 2001 From: Aaldert Date: Tue, 21 Jun 2016 12:25:38 +0200 Subject: [PATCH] Hp, Lvl en Xp gameplay toegevoegt --- CrystalPoint.cpp | 9 +++++++++ Enemy.cpp | 2 ++ Enemy.h | 1 + Interface.cpp | 8 ++++---- Player.cpp | 51 +++++++++++++++++++++++++++++++++++++++++++++--- Player.h | 9 +++++++-- World.cpp | 6 +++++- 7 files changed, 76 insertions(+), 10 deletions(-) diff --git a/CrystalPoint.cpp b/CrystalPoint.cpp index f72d400..5c1cdd7 100644 --- a/CrystalPoint.cpp +++ b/CrystalPoint.cpp @@ -72,9 +72,18 @@ void CrystalPoint::update() worldhandler->NextWorld(); if (keyboardState.keys[27]) state = false; + Player* player = Player::getInstance(); + //testing code + if (keyboardState.keys['u']) + player->HpUp(1); + if (keyboardState.keys['i']) + player->HpDown(1); + if (keyboardState.keys['o']) + player->XpUp(1); + player->rotation.y += mouseOffset.x / 10.0f; player->rotation.x += mouseOffset.y / 10.0f; if (player->rotation.x > 90) diff --git a/Enemy.cpp b/Enemy.cpp index 36c3f44..2367b41 100644 --- a/Enemy.cpp +++ b/Enemy.cpp @@ -17,6 +17,7 @@ Enemy::Enemy(const std::string &fileName, target = position; speed = 1; radius = 10; + xp = 10; hasTarget = false; hit_sound_id = CrystalPoint::GetSoundSystem().LoadSound("WAVE/enemy.wav", false); music = CrystalPoint::GetSoundSystem().GetSound(hit_sound_id); @@ -26,6 +27,7 @@ Enemy::Enemy(const std::string &fileName, Enemy::~Enemy() { + if (model) Model::unload(model); } diff --git a/Enemy.h b/Enemy.h index d1376c8..cf2294d 100644 --- a/Enemy.h +++ b/Enemy.h @@ -16,6 +16,7 @@ public: bool hasTarget; Vec3f target; float speed,radius; + int xp; bool attack; void update(float); diff --git a/Interface.cpp b/Interface.cpp index 0f912de..db016ee 100644 --- a/Interface.cpp +++ b/Interface.cpp @@ -60,8 +60,8 @@ void Interface::draw() glVertex2f(250, 965); glColor4f(1.0f, 0.5f, 0.5f, 1.0); - glVertex2f(250 + (player->health / 100 * 500), 965); - glVertex2f(250 + (player->health / 100 * 500), 980); + glVertex2f(250 + (player->health / player->maxHp * 500), 965); + glVertex2f(250 + (player->health / player->maxHp * 500), 980); glEnd(); //XP bar @@ -79,8 +79,8 @@ void Interface::draw() glVertex2f(250, 935); glColor4f(1.0f, 1.0f, 0.5f, 1.0); - glVertex2f(250 + (player->xp / 100 * 500), 935); - glVertex2f(250 + (player->xp / 100 * 500), 950); + glVertex2f(250 + (player->xp / player->maxXp * 500), 935); + glVertex2f(250 + (player->xp / player->maxXp * 500), 950); glEnd(); //Text: level diff --git a/Player.cpp b/Player.cpp index f6de1c3..ac71502 100644 --- a/Player.cpp +++ b/Player.cpp @@ -8,9 +8,11 @@ Player* Player::instance = NULL; Player::Player() { speed = 10; - health = 50; - xp = 75; - level = 10; + maxHp = 100; + health = maxHp; + xp = 0; + maxXp = 100; + level = 1; crystals = 0; } @@ -53,4 +55,47 @@ void Player::setPosition(float angle, float fac, bool height) position.x -= (float)cos((rotation.y + angle) / 180 * M_PI) * fac; position.z -= (float)sin((rotation.y + angle) / 180 * M_PI) * fac; } +} + +void Player::HpDown(int damage) +{ + int newHealth = health - damage; + if (newHealth <= 0) + { + exit(0); + } + health = newHealth; +} + +void Player::HpUp(int hp) +{ + if (health != maxHp) + { + int newHealth = health + hp; + if (newHealth >= maxHp) + { + newHealth = maxHp; + } + health = newHealth; + } +} + +void Player::XpUp(int xpUp) +{ + float newXp = xp + xpUp; + if (newXp >= maxXp) + { + newXp -= maxXp; + levelUp(); + } + xp = newXp; +} + + +void Player::levelUp() +{ + level++; + maxXp += 50; + maxHp += 10; + health = maxHp; } \ No newline at end of file diff --git a/Player.h b/Player.h index 374d1dd..f1fd856 100644 --- a/Player.h +++ b/Player.h @@ -7,6 +7,7 @@ class Player { private: static Player* instance; + void levelUp(); public: Player(); ~Player(); @@ -23,10 +24,14 @@ public: Model* leftWeapon; Model* rightWeapon; - float health; - float xp; + float health, maxHp; + float xp, maxXp; int level; int crystals; float speed; + + void HpUp(int); + void HpDown(int); + void XpUp(int); }; \ No newline at end of file diff --git a/World.cpp b/World.cpp index 5df11dc..2617de1 100644 --- a/World.cpp +++ b/World.cpp @@ -300,8 +300,12 @@ void World::update(float elapsedTime) count++; } - if(remove) + if (remove) + { + player->XpUp(enemies[count]->xp); enemies.erase(enemies.begin() + count); + player->HpUp(10); + } skybox->update(elapsedTime, maxEnemies - enemies.size(), maxEnemies);