Merge pull request #22 from CrystalPointA4/feature/gameplay
Feature/gameplay
This commit is contained in:
@@ -71,9 +71,20 @@ void CrystalPoint::update()
|
||||
worldhandler->PreviousWorld();
|
||||
if (keyboardState.special[GLUT_KEY_RIGHT] && !prevKeyboardState.special[GLUT_KEY_RIGHT])
|
||||
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)
|
||||
|
||||
@@ -18,6 +18,7 @@ Enemy::Enemy(const std::string &fileName,
|
||||
target = position;
|
||||
speed = 1;
|
||||
radius = 10;
|
||||
xp = 10;
|
||||
hasTarget = false;
|
||||
hit_sound_id = CrystalPoint::GetSoundSystem().LoadSound(fileMusic.c_str(), false);
|
||||
music = CrystalPoint::GetSoundSystem().GetSound(hit_sound_id);
|
||||
@@ -27,6 +28,7 @@ Enemy::Enemy(const std::string &fileName,
|
||||
|
||||
Enemy::~Enemy()
|
||||
{
|
||||
|
||||
if (model)
|
||||
Model::unload(model);
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@ public:
|
||||
bool hasTarget;
|
||||
Vec3f target;
|
||||
float speed,radius;
|
||||
int xp;
|
||||
bool attack;
|
||||
|
||||
void update(float);
|
||||
|
||||
+4
-4
@@ -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
|
||||
|
||||
+48
-3
@@ -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;
|
||||
}
|
||||
@@ -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);
|
||||
};
|
||||
Reference in New Issue
Block a user