Hp, Lvl en Xp gameplay toegevoegt
This commit is contained in:
@@ -72,9 +72,18 @@ void CrystalPoint::update()
|
|||||||
worldhandler->NextWorld();
|
worldhandler->NextWorld();
|
||||||
if (keyboardState.keys[27])
|
if (keyboardState.keys[27])
|
||||||
state = false;
|
state = false;
|
||||||
|
|
||||||
|
|
||||||
Player* player = Player::getInstance();
|
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.y += mouseOffset.x / 10.0f;
|
||||||
player->rotation.x += mouseOffset.y / 10.0f;
|
player->rotation.x += mouseOffset.y / 10.0f;
|
||||||
if (player->rotation.x > 90)
|
if (player->rotation.x > 90)
|
||||||
|
|||||||
@@ -17,6 +17,7 @@ Enemy::Enemy(const std::string &fileName,
|
|||||||
target = position;
|
target = position;
|
||||||
speed = 1;
|
speed = 1;
|
||||||
radius = 10;
|
radius = 10;
|
||||||
|
xp = 10;
|
||||||
hasTarget = false;
|
hasTarget = false;
|
||||||
hit_sound_id = CrystalPoint::GetSoundSystem().LoadSound("WAVE/enemy.wav", false);
|
hit_sound_id = CrystalPoint::GetSoundSystem().LoadSound("WAVE/enemy.wav", false);
|
||||||
music = CrystalPoint::GetSoundSystem().GetSound(hit_sound_id);
|
music = CrystalPoint::GetSoundSystem().GetSound(hit_sound_id);
|
||||||
@@ -26,6 +27,7 @@ Enemy::Enemy(const std::string &fileName,
|
|||||||
|
|
||||||
Enemy::~Enemy()
|
Enemy::~Enemy()
|
||||||
{
|
{
|
||||||
|
|
||||||
if (model)
|
if (model)
|
||||||
Model::unload(model);
|
Model::unload(model);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ public:
|
|||||||
bool hasTarget;
|
bool hasTarget;
|
||||||
Vec3f target;
|
Vec3f target;
|
||||||
float speed,radius;
|
float speed,radius;
|
||||||
|
int xp;
|
||||||
bool attack;
|
bool attack;
|
||||||
|
|
||||||
void update(float);
|
void update(float);
|
||||||
|
|||||||
+4
-4
@@ -60,8 +60,8 @@ void Interface::draw()
|
|||||||
glVertex2f(250, 965);
|
glVertex2f(250, 965);
|
||||||
|
|
||||||
glColor4f(1.0f, 0.5f, 0.5f, 1.0);
|
glColor4f(1.0f, 0.5f, 0.5f, 1.0);
|
||||||
glVertex2f(250 + (player->health / 100 * 500), 965);
|
glVertex2f(250 + (player->health / player->maxHp * 500), 965);
|
||||||
glVertex2f(250 + (player->health / 100 * 500), 980);
|
glVertex2f(250 + (player->health / player->maxHp * 500), 980);
|
||||||
glEnd();
|
glEnd();
|
||||||
|
|
||||||
//XP bar
|
//XP bar
|
||||||
@@ -79,8 +79,8 @@ void Interface::draw()
|
|||||||
glVertex2f(250, 935);
|
glVertex2f(250, 935);
|
||||||
|
|
||||||
glColor4f(1.0f, 1.0f, 0.5f, 1.0);
|
glColor4f(1.0f, 1.0f, 0.5f, 1.0);
|
||||||
glVertex2f(250 + (player->xp / 100 * 500), 935);
|
glVertex2f(250 + (player->xp / player->maxXp * 500), 935);
|
||||||
glVertex2f(250 + (player->xp / 100 * 500), 950);
|
glVertex2f(250 + (player->xp / player->maxXp * 500), 950);
|
||||||
glEnd();
|
glEnd();
|
||||||
|
|
||||||
//Text: level
|
//Text: level
|
||||||
|
|||||||
+48
-3
@@ -8,9 +8,11 @@ Player* Player::instance = NULL;
|
|||||||
Player::Player()
|
Player::Player()
|
||||||
{
|
{
|
||||||
speed = 10;
|
speed = 10;
|
||||||
health = 50;
|
maxHp = 100;
|
||||||
xp = 75;
|
health = maxHp;
|
||||||
level = 10;
|
xp = 0;
|
||||||
|
maxXp = 100;
|
||||||
|
level = 1;
|
||||||
crystals = 0;
|
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.x -= (float)cos((rotation.y + angle) / 180 * M_PI) * fac;
|
||||||
position.z -= (float)sin((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;
|
||||||
}
|
}
|
||||||
@@ -7,6 +7,7 @@ class Player
|
|||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
static Player* instance;
|
static Player* instance;
|
||||||
|
void levelUp();
|
||||||
public:
|
public:
|
||||||
Player();
|
Player();
|
||||||
~Player();
|
~Player();
|
||||||
@@ -23,10 +24,14 @@ public:
|
|||||||
Model* leftWeapon;
|
Model* leftWeapon;
|
||||||
Model* rightWeapon;
|
Model* rightWeapon;
|
||||||
|
|
||||||
float health;
|
float health, maxHp;
|
||||||
float xp;
|
float xp, maxXp;
|
||||||
int level;
|
int level;
|
||||||
int crystals;
|
int crystals;
|
||||||
|
|
||||||
float speed;
|
float speed;
|
||||||
|
|
||||||
|
void HpUp(int);
|
||||||
|
void HpDown(int);
|
||||||
|
void XpUp(int);
|
||||||
};
|
};
|
||||||
@@ -300,8 +300,12 @@ void World::update(float elapsedTime)
|
|||||||
count++;
|
count++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(remove)
|
if (remove)
|
||||||
|
{
|
||||||
|
player->XpUp(enemies[count]->xp);
|
||||||
enemies.erase(enemies.begin() + count);
|
enemies.erase(enemies.begin() + count);
|
||||||
|
player->HpUp(10);
|
||||||
|
}
|
||||||
|
|
||||||
skybox->update(elapsedTime, maxEnemies - enemies.size(), maxEnemies);
|
skybox->update(elapsedTime, maxEnemies - enemies.size(), maxEnemies);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user