Commit 1c1d2f70 authored by pa's avatar pa

Added a damageable class

parent a434bb42
0 0.5 0.5
6 0.25 0.5
16 0.75 0.5
......@@ -32,7 +32,7 @@ public :
void unlock();
bool isLocked() const {return mLock;}
void hit();
void hit(bool poisonous = false);
void hitAnimation(sf::Time dt);
virtual Category::Category identify() const{return Category::Alive;}
......@@ -49,4 +49,7 @@ private :
bool mLock;
sf::Time mLockTime;
bool mPoisoned;
sf::Time mPoisonTime;
};
......@@ -2,6 +2,6 @@
namespace Category{
enum Category{
SceneNode, SpriteNode, Entity, Agent, Alive, Player, Ennemy, Orbital, Sword, Door, Collectible
SceneNode, SpriteNode, Entity, Agent, Alive, Player, Ennemy, Orbital, Sword, Door, Collectible, Damageable
};
}
#pragma once
#include "entity.hpp"
#include "category.hpp"
class Damageable : public Entity {
public :
Damageable(Agent::Type type, TextureHolder const& tex, int dmg = 1, bool poisonous = false);
virtual Category::Category identify()const{return Category::Damageable;}
bool isPoisonous() const{return mPoisonous;}
int getDMG() const{return mDMG;}
private :
int mDMG;
bool mPoisonous;
};
......@@ -2,20 +2,23 @@
#include <iostream>
#include <SFML/Graphics.hpp>
#include "entity.hpp"
#include "damageable.hpp"
#include "speedPatern.hpp"
#include "category.hpp"
#include "alive.hpp"
class Orbital : public Entity{
class Orbital : public Damageable{
public :
Orbital(Agent::Type type , TextureHolder const& texture, SpeedPatern* spP, Entity::Side ally);
Orbital(Agent::Type type , TextureHolder const& texture, SpeedPatern* spP, Entity::Side ally
, bool poisonous = false);
virtual void updateCurrent(sf::Time dt);
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;
......
......@@ -5,6 +5,7 @@
#include "alive.hpp"
#include "category.hpp"
#include "sword.hpp"
#include "collectible.hpp"
class Player : public Alive{
......@@ -34,4 +35,6 @@ private :
bool mIsWAvailable, mW;
sf::Time mWCD, mWElapse;
int poison_stack; bool unsing_poison;
};
#pragma once
#include <SFML/Graphics.hpp>
#include "agent.hpp"
#include "damageable.hpp"
#include "category.hpp"
#include <iostream>
class Sword : public Agent{
class Sword : public Damageable{
public :
enum State{Increasing, Decreading};
Sword(TextureHolder const& textures);
Sword(TextureHolder const& textures, bool poisonous = false);
virtual void updateCurrent(sf::Time dt);
......
......@@ -5,6 +5,11 @@ Alive::Alive(Agent::Type type, TextureHolder const& textures, int HP, Entity::Si
void Alive::updateCurrent(sf::Time dt){
if(mPoisoned) mPoisonTime -= dt;
if(mPoisoned && mPoisonTime.asSeconds() <= 0.f){
hit();
mPoisonTime = sf::seconds(1.f);
}
if(!isLocked()){
act(dt);
hitAnimation(dt);
......@@ -36,7 +41,9 @@ Agent::Type Alive::typeOfState(){
return Agent::Player;
}
void Alive::hit(){
void Alive::hit(bool poisonous){
if(poisonous && !mPoisoned) mPoisonTime = sf::seconds(1.f);
mPoisoned = mPoisoned || poisonous;
if(!mLock){
--mHP;
lock(sf::milliseconds(500.f));
......@@ -80,8 +87,9 @@ void Alive::moveRight(){
}
void Alive::onCollideWith(SceneNode& collider){
if(collider.identify() == Category::Orbital)
if(static_cast<Orbital&>(collider).getSide() != mSide){
hit();
}
switch(collider.identify()){
case Category::Orbital :
if(static_cast<Orbital&>(collider).getSide() != mSide)
hit(static_cast<Orbital&>(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) {}
#include "../headers/ennemy.hpp"
Ennemy::Ennemy(TextureHolder const& textures) : Alive(Agent::Tower,textures,2,Entity::Ennemy), mIsQ(true), mIsW(true){
Ennemy::Ennemy(TextureHolder const& textures) : Alive(Agent::Tower,textures,12,Entity::Ennemy), mIsQ(true), mIsW(true){
mQCD = sf::seconds(4.f);
markForReset();
}
......@@ -55,6 +55,7 @@ void Ennemy::onCollideWith(SceneNode& collider){
hit();
break;
}
Alive::onCollideWith(collider);
}
......
#include "../headers/orbital.hpp"
Orbital::Orbital(Agent::Type type, TextureHolder const& textures, SpeedPatern* spP, Entity::Side ally)
: Entity(type,textures), mSpeedPatern(spP), mLifeSpan(sf::seconds(15.f)), mSide(ally){
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){
}
void Orbital::updateCurrent(sf::Time dt){
......@@ -13,3 +13,11 @@ void Orbital::updateCurrent(sf::Time dt){
setVelocity(mSpeedPatern->getVelocity());
Entity::updateCurrent(dt);
}
void Orbital::onCollideWith(SceneNode& node){
switch(node.identify()){
case Category::Player: case Category::Ennemy :
stageForRemoval();
break;
}
}
......@@ -14,7 +14,8 @@ Agent::Type Player::typeOfState(){
}
Player::Player(TextureHolder const& textures)
: Alive(Agent::Player,textures,8,Entity::Player), mIsQAvailable(true), mIsWAvailable(true), mW(false){
: Alive(Agent::Player,textures,8,Entity::Player), mIsQAvailable(true), mIsWAvailable(true), mW(false),
poison_stack(0){
mQCD = sf::seconds(8.f);
mWCD = sf::seconds(1.f);
}
......@@ -27,7 +28,7 @@ void Player::q_spell(){
sf::Transform transform; transform.rotate(120.f);
for(int i = 0 ; i < 3 ; ++i){
Orbital* orb = new Orbital(Agent::qProjectile, getTexHolder(), new
RotationSpeedPatern(positionSetter,540.f), Entity::Player);
RotationSpeedPatern(positionSetter,540.f), Entity::Player,unsing_poison);
orb->setPosition(positionSetter);
attachChild(orb);
positionSetter = transform.transformPoint(positionSetter);
......@@ -39,7 +40,7 @@ void Player::w_spell(int dir){
if(mIsWAvailable && mW){
mIsWAvailable = false;
Sword* sword = new Sword(getTexHolder());
Sword* sword = new Sword(getTexHolder(),unsing_poison); unsing_poison = false;
sword->rotate(dir*90.f);
attachChild(sword);
}
......@@ -74,12 +75,22 @@ void Player::keyBindings(){
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Q)) w_spell(2);
if(sf::Keyboard::isKeyPressed(sf::Keyboard::S)) w_spell(1);
if(sf::Keyboard::isKeyPressed(sf::Keyboard::D)) w_spell(0);
if(sf::Keyboard::isKeyPressed(sf::Keyboard::E) && !unsing_poison && poison_stack > 0){
unsing_poison = true; --poison_stack;
}
}
void Player::onCollideWith(SceneNode& collider){
switch(collider.identify()){
case Category::Collectible :
giveSword();
switch(static_cast<Collectible&>(collider).getType()){
case Collectible::Sword :
giveSword();
break;
case Collectible::Poison :
++poison_stack;
break;
}
break;
}
Alive::onCollideWith(collider);
......
......@@ -25,6 +25,7 @@ void Room::loadTextures(){
mTextures.load(Textures::Sword_5, pathOfID(Textures::Sword_5));
mTextures.load(Textures::SwordFloor, pathOfID(Textures::SwordFloor));
mTextures.load(Textures::Doors, pathOfID(Textures::Doors));
mTextures.load(Textures::Poison, pathOfID(Textures::Poison));
}
......@@ -53,7 +54,8 @@ void Room::buildScene(std::string path){
mSceneLayers[Air]->attachChild(ennemy);
break;
}
case Agent::SwordFloor :{
case Agent::Poison :{
case Agent::SwordFloor :
Collectible* sword(new Collectible(mTextures,Collectible::typeIn(rType)));
sword->setPosition(alpha_x*x,alpha_y*y);
mSceneLayers[Air]->attachChild(sword);
......
#include "../headers/sword.hpp"
Sword::Sword(TextureHolder const& mTextures)
: Agent(Agent::Sword_1, mTextures), mAnimationTime(sf::milliseconds(80.f)), mIsIncreasing(true){
Sword::Sword(TextureHolder const& mTextures, bool poisonous)
: Damageable(Agent::Sword_1, mTextures,1,poisonous),
mAnimationTime(sf::milliseconds(80.f)), mIsIncreasing(true){
getSprite().setOrigin(20.f,20.f);
}
......
......@@ -10,7 +10,6 @@ void RessourceHolder<Ressource,Identifier>::load(Identifier id, const std::strin
throw std::runtime_error("RessourceHolder::load - Failed to load " + filename);
auto inserted = mRessourceMap.insert(std::make_pair(id, std::move(res)));
//if(!inserted.second) throw std::logic_error("TextureHolder::load - Failed to insert " + filename);
return;
}
......
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