1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
|
#ifndef MONSTER_H
#define MONSTER_H
#include <SFML/Graphics.hpp>
#include <SFML/System.hpp>
#include <string>
#include "Player.h"
class Monster
{
private:
int xpgiven;
int damage;
int maxhp;
int curhp;
int defense;
sf::Font MonsterFont;
sf::String MonsterSprite;
float height;
float width;
float ypos;
float xpos;
bool alive;
public:
Monster(sf::Unicode::Text sprite, int damage, int maxhp, int xpgiven, int defense, float xpos, float ypos, bool running)
{
xpgiven = xpgiven;
damage = damage;
maxhp = maxhp;
curhp = maxhp;
defense = defense;
if (!MonsterFont.LoadFromFile("Lucida Console.ttf", 12))
{
running = false;
}
MonsterSprite.SetFont(MonsterFont);
MonsterSprite.SetSize(12);
MonsterSprite.SetText(sprite);
MonsterSprite.SetColor(sf::Color(192, 192, 192));
MonsterSprite.SetPosition(xpos, ypos);
height = 20.0;
width = 13.0;
xpos = xpos;
ypos = ypos;
alive = true;
}
int getxpgiven() {return xpgiven;}
int getdamage() {return damage;}
int getmaxhp() {return maxhp;}
int getcurhp() {return curhp;}
float getxpos() {return xpos;}
float getypos() {return ypos;}
float getheight() {return height;}
float getwidth() {return width;}
bool checklife() {return alive;}
void attackplayer(Player& hero, bool checkup, bool checkdown, bool checkleft, bool checkright)
{
if (checkup == true || checkdown == true || checkleft == true || checkright == true)
{
hero.damage(damage);
}
}
void statcheck()
{
if (curhp > maxhp)
{
curhp = maxhp;
}
}
bool death()
{
if (curhp <= 0)
{
MonsterSprite.SetText(" ");
alive = false;
return true;
}
}
void takedamage(int nValue)
{
curhp -= nValue - defense;
death();
statcheck();
}
void heal(int nValue)
{
curhp += nValue;
death();
statcheck();
}
void damagereduction(int nValue)
{
damage -= nValue;
}
};
#endif
|