Commit 2796c116 authored by pa's avatar pa

Added poison interface support

parent 1c1d2f70
......@@ -9,7 +9,7 @@
class HUD{
public :
struct HUD_data{
int HP; int HP_max;
int HP; int HP_max; int poison_stack; int poison_stack_max;
};
HUD(sf::RenderWindow& window, HUD_data* data);
......@@ -28,5 +28,6 @@ class HUD{
SceneNode mRoot;
SpriteNode** mHPs;
SpriteNode** mPoisonStack;
HUD_data* mData;
};
......@@ -11,7 +11,7 @@ class Agent : public SceneNode{
public :
enum Type{
Floor, qProjectile, tProjectile, Player, PlayerHit, Tower,
SwordFloor, Sword_0, Sword_1, Sword_2, Sword_3, Sword_4, Sword_5, Doors, HP_full, HP_down, Poison
SwordFloor, Sword_0, Sword_1, Sword_2, Sword_3, Sword_4, Sword_5, Doors, HP_full, HP_down, Poison, Void
};
Textures::ID toTextureID(Type type);
......
......@@ -6,13 +6,15 @@
class Damageable : public Entity {
public :
Damageable(Agent::Type type, TextureHolder const& tex, int dmg = 1, bool poisonous = false);
Damageable(Agent::Type type, TextureHolder const& tex, Entity::Side side, int dmg = 1, bool poisonous = false);
virtual Category::Category identify()const{return Category::Damageable;}
Entity::Side getSide() const{return mSide;}
bool isPoisonous() const{return mPoisonous;}
int getDMG() const{return mDMG;}
private :
Entity::Side mSide;
int mDMG;
bool mPoisonous;
};
......@@ -15,12 +15,9 @@ public :
virtual Category::Category identify() const{return Category::Orbital;}
virtual Entity::Side getSide() const{ return Entity::None; }
virtual void onCollideWith(SceneNode& node);
private :
Entity::Side mSide;
SpeedPatern* mSpeedPatern;
sf::Time mLifeSpan;
};
......@@ -27,6 +27,8 @@ public :
virtual Category::Category identify() const{ return Category::Player;}
int getPoisonStack() const{return poison_stack;}
virtual void onCollideWith(SceneNode& collider);
private :
......
......@@ -9,7 +9,7 @@
namespace Textures{
enum ID{
Floor, qProjectile, tProjectile, Player, PlayerHit, Tower, Poison,
SwordFloor, Sword_0, Sword_1, Sword_2, Sword_3, Sword_4, Sword_5, Doors, HP_full, HP_down
SwordFloor, Sword_0, Sword_1, Sword_2, Sword_3, Sword_4, Sword_5, Doors, HP_full, HP_down, Void
};
}
......
res/void.png

184 Bytes

......@@ -12,12 +12,20 @@ HUD::HUD(sf::RenderWindow& window, HUD::HUD_data* data)
mRoot.attachChild(mHPs[i]);
mHPs[i]->move(32*i+16,16);
}
mPoisonStack = new SpriteNode*[mData->poison_stack_max];
for(int i = 0 ; i < mData->poison_stack_max; ++i){
mPoisonStack[i] = new SpriteNode(Agent::Poison,mTextures);
mRoot.attachChild(mPoisonStack[i]);
mPoisonStack[i]->move(16*i+8,32+8);
}
}
void HUD::loadTextures(){
mTextures.load(Textures::HP_full, pathOfID(Textures::HP_full));
mTextures.load(Textures::HP_down, pathOfID(Textures::HP_down));
mTextures.load(Textures::Poison, pathOfID(Textures::Poison));
mTextures.load(Textures::Void, pathOfID(Textures::Void));
}
void HUD::draw(){
......@@ -25,11 +33,11 @@ void HUD::draw(){
}
void HUD::update(sf::Time dt){
for(int i = 0; i < mData->HP; ++i){
mHPs[i]->setType(Agent::HP_full);
for(int i = 0; i < mData->poison_stack; ++i){
mPoisonStack[i]->setType(Agent::Poison);
}
for(int i = mData->HP ; i < mData->HP_max; ++i){
mHPs[i]->setType(Agent::HP_down);
for(int i = mData->poison_stack ; i < mData->poison_stack_max; ++i){
mPoisonStack[i]->setType(Agent::Void);
}
mRoot.update(dt);
}
......
......@@ -37,6 +37,8 @@ Textures::ID Agent::toTextureID(Agent::Type type){
return Textures::ID::HP_full;
case HP_down :
return Textures::ID::HP_down;
case Void :
return Textures::ID::Void;
default :
throw std::logic_error("Agent::toTextureID, non-exhaustive pattern-matching");
}
......
......@@ -88,8 +88,8 @@ void Alive::moveRight(){
void Alive::onCollideWith(SceneNode& collider){
switch(collider.identify()){
case Category::Orbital :
if(static_cast<Orbital&>(collider).getSide() != mSide)
hit(static_cast<Orbital&>(collider).isPoisonous());
case Category::Orbital : case Category::Sword :
if(static_cast<Damageable&>(collider).getSide() != mSide)
hit(static_cast<Damageable&>(collider).isPoisonous());
}
}
#include "../headers/damageable.hpp"
Damageable::Damageable(Agent::Type type, TextureHolder const& tex, int dmg, bool poisonous)
: Entity(type,tex), mDMG(dmg), mPoisonous(poisonous) {}
Damageable::Damageable(Agent::Type type, TextureHolder const& tex, Entity::Side side, int dmg, bool poisonous)
: Entity(type,tex), mSide(side), mDMG(dmg), mPoisonous(poisonous) {}
#include "../headers/orbital.hpp"
Orbital::Orbital(Agent::Type type, TextureHolder const& textures, SpeedPatern* spP, Entity::Side ally, bool poisonous)
: Damageable(type,textures,1,poisonous), mSpeedPatern(spP), mLifeSpan(sf::seconds(15.f)), mSide(ally){
: Damageable(type,textures,ally,1,poisonous), mSpeedPatern(spP), mLifeSpan(sf::seconds(15.f)){
}
void Orbital::updateCurrent(sf::Time dt){
......
......@@ -2,7 +2,7 @@
Sword::Sword(TextureHolder const& mTextures, bool poisonous)
: Damageable(Agent::Sword_1, mTextures,1,poisonous),
: Damageable(Agent::Sword_1, mTextures, Entity::Player, 1,poisonous),
mAnimationTime(sf::milliseconds(80.f)), mIsIncreasing(true){
getSprite().setOrigin(20.f,20.f);
}
......
......@@ -87,6 +87,9 @@ std::string pathOfID(Textures::ID id){
case Textures::HP_down:
str = "res/hp_down.png";
break;
case Textures::Void:
str = "res/void.png";
break;
default :
throw std::logic_error("TextureHolder::pathOfID, Non-exhaustive pattern-matching");
}
......
......@@ -10,10 +10,12 @@ World::World(sf::RenderWindow& window)
mSceneGraph.attachChild(mRoom);
mData = new HUD::HUD_data;
mData->HP = mData->HP_max = getPlayerHP();
mData->poison_stack_max = 10; mData->poison_stack = 0;
}
void World::fillData(){
mData->HP = getPlayerHP();
mData->poison_stack = mPlayer->getPoisonStack();
}
void World::spawnPlayer(Room* room){
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment