Commit 774676cd authored by pa's avatar pa

Added dagger

parent 64888910
0 0.5 0.5
6 0.25 0.5
16 0.75 0.5
18 0.5 0.25
22 0.5 0.25
19 0.5 0.75
......@@ -12,7 +12,7 @@ class Agent : public SceneNode{
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, Void, Coin, Key, LockedDoors, UltraLockedDoors
Doors, HP_full, HP_down, Poison, Void, Coin, Key, LockedDoors, UltraLockedDoors, Dagger
};
static Textures::ID toTextureID(Type type);
......
......@@ -36,7 +36,7 @@ public :
void unlock();
bool isLocked() const {return mLock;}
void hit(bool poisonous = false);
void hit(bool poisonous = false, int dmg = 1);
void hitAnimation(sf::Time dt);
virtual Category::Category identify() const{return Category::Alive;}
......
......@@ -10,7 +10,7 @@
class Orbital : public Damageable{
public :
Orbital(Agent::Type type , TextureHolder const& texture, SpeedPatern* spP, Entity::Side ally
, bool poisonous = false);
, bool poisonous = false, int dmg = 1);
virtual void updateCurrent(sf::Time dt);
virtual Category::Category identify() const{return Category::Orbital;}
......
......@@ -17,6 +17,7 @@ public :
void q_spell();
void w_spell(int dir);
void e_spell(int dir);
void giveSword(){mW = true;}
......@@ -30,6 +31,7 @@ public :
int getPoisonStack() const{return poison_stack;}
int getCoins() const{return coin_stack;}
int getKeys() const{return key_stack;}
int getDaggers() const{return dagger_stack;}
virtual void onCollideWith(SceneNode& collider);
......@@ -41,6 +43,7 @@ private :
sf::Time mWCD, mWElapse;
int poison_stack; bool unsing_poison;
int key_stack; bool unsing_key;
int coin_stack; bool unsing_coin;
int key_stack;
int coin_stack;
int dagger_stack; bool unsing_dagger;
};
......@@ -10,7 +10,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, Void, Coin , Key, LockedDoors, UltraLockedDoors
Doors, HP_full, HP_down, Void, Coin , Key, LockedDoors, UltraLockedDoors, Dagger
};
}
......
res/dagger.png

456 Bytes

......@@ -47,6 +47,8 @@ Textures::ID Agent::toTextureID(Agent::Type type){
return Textures::ID::LockedDoors;
case UltraLockedDoors :
return Textures::ID::UltraLockedDoors;
case Dagger :
return Textures::ID::Dagger;
default :
throw std::logic_error("Agent::toTextureID, non-exhaustive pattern-matching");
}
......
......@@ -45,11 +45,11 @@ Agent::Type Alive::typeOfState(){
return Agent::Player;
}
void Alive::hit(bool poisonous){
void Alive::hit(bool poisonous, int dmg){
if(poisonous && !mPoisoned) mPoisonTime = sf::seconds(1.f);
mPoisoned = mPoisoned || poisonous;
if(!mLock){
--mHP;
mHP -= dmg;
lock(sf::milliseconds(900.f));
if(mHP <= 0){loot(); stageForRemoval();}
mState = HitA;
......@@ -94,7 +94,8 @@ void Alive::onCollideWith(SceneNode& collider){
switch(collider.identify()){
case Category::Orbital : case Category::Sword :
if(static_cast<Damageable&>(collider).getSide() != mSide)
hit(static_cast<Damageable&>(collider).isPoisonous());
hit(static_cast<Damageable&>(collider).isPoisonous(),
static_cast<Damageable&>(collider).getDMG());
break;
case Category::Ennemy : case Category::Player :
hit(false);
......@@ -105,6 +106,7 @@ void Alive::onCollideWith(SceneNode& collider){
void Alive::loot(){
float rf = random_float();
if(rf <= 0.1) drop(Collectible::Key);
else if(rf <= 0.5) drop(Collectible::Dagger);
else if(rf <= 0.9) drop(Collectible::Poison);
else drop(Collectible::Coin);
}
......
......@@ -6,6 +6,7 @@ Agent::Type Collectible::typeOf(Collectible::Type type){
case Sword : return Agent::SwordFloor;
case Key : return Agent::Key;
case Coin : return Agent::Coin;
case Dagger : return Agent::Dagger;
default : return Agent::SwordFloor;
}
}
......@@ -16,6 +17,7 @@ Collectible::Type Collectible::typeIn(Agent::Type type){
case Agent::SwordFloor : return Sword;
case Agent::Key : return Key;
case Agent::Coin : return Coin;
case Agent::Dagger : return Dagger;
default : return Collectible::Sword;
}
}
......
#include "../headers/orbital.hpp"
Orbital::Orbital(Agent::Type type, TextureHolder const& textures, SpeedPatern* spP, Entity::Side ally, bool poisonous)
: Damageable(type,textures,ally,1,poisonous), mSpeedPatern(spP), mLifeSpan(sf::seconds(15.f)){
Orbital::Orbital(Agent::Type type, TextureHolder const& textures, SpeedPatern* spP, Entity::Side ally, bool poisonous, int dmg)
: Damageable(type,textures,ally,dmg,poisonous), mSpeedPatern(spP), mLifeSpan(sf::seconds(15.f)){
}
void Orbital::updateCurrent(sf::Time dt){
......@@ -16,7 +16,10 @@ void Orbital::updateCurrent(sf::Time dt){
void Orbital::onCollideWith(SceneNode& node){
switch(node.identify()){
case Category::Player: case Category::Ennemy : case Category::Orbital :
case Category::Orbital :
if(getType() == Agent::Dagger || static_cast<Agent&>(node).getType() == Agent::Dagger)
return;
case Category::Player: case Category::Ennemy :
stageForRemoval();
break;
}
......
......@@ -15,7 +15,8 @@ Agent::Type Player::typeOfState(){
Player::Player(TextureHolder const& textures)
: Alive(Agent::Player,textures,8,Entity::Player), mIsQAvailable(true), mIsWAvailable(true), mW(false),
poison_stack(0), coin_stack(0), key_stack(0){
unsing_poison(false), unsing_dagger(false),
poison_stack(0), coin_stack(0), key_stack(0), dagger_stack(0){
mQCD = sf::seconds(8.f);
mWCD = sf::seconds(1.f);
}
......@@ -46,6 +47,22 @@ void Player::w_spell(int dir){
}
}
void Player::e_spell(int dir){
if(mIsWAvailable){
unsing_dagger = false;
mIsWAvailable = false;
sf::Vector2f base(400.f,0.f);
SpeedPatern *sp = new SpeedPatern(base); sp->rotate(dir*90.f);
Orbital* dagger = new Orbital(Agent::Dagger, getTexHolder(),sp, Entity::Player,unsing_poison, 3);
unsing_poison = false;
dagger->rotate(dir*90.f);
getParent()->attachChild(dagger);
dagger->move(getWorldPosition().x + (dir == 0 ? 1 : -1) * (dir %2 == 0 ? 50 : 0),
getWorldPosition().y + (dir == 3 ? -1 : 1) * (dir %2 == 1 ? 50 : 0));
}
}
void Player::updateCurrent(sf::Time dt){
// Q-SPELL
if(!mIsQAvailable){
......@@ -56,7 +73,6 @@ void Player::updateCurrent(sf::Time dt){
if (mWElapse < mWCD) mWElapse += dt;
else {mIsWAvailable = true; mWElapse = sf::Time::Zero;}
}
Alive::updateCurrent(dt);
}
......@@ -71,31 +87,31 @@ void Player::keyBindings(){
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Down)) moveDown();
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Space)) q_spell();
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Z)) w_spell(3);
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::Z)){
if(unsing_dagger) e_spell(3); else w_spell(3);}
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Q)){
if(unsing_dagger) e_spell(2); else w_spell(2);}
if(sf::Keyboard::isKeyPressed(sf::Keyboard::S)){
if(unsing_dagger) e_spell(1); else w_spell(1);}
if(sf::Keyboard::isKeyPressed(sf::Keyboard::D)){
if(unsing_dagger) e_spell(0); else w_spell(0);}
if(sf::Keyboard::isKeyPressed(sf::Keyboard::E) && !unsing_poison && poison_stack > 0){
unsing_poison = true; --poison_stack;
}
if(sf::Keyboard::isKeyPressed(sf::Keyboard::A) && !unsing_dagger && dagger_stack > 0){
unsing_dagger = true; --dagger_stack;
}
}
void Player::onCollideWith(SceneNode& collider){
switch(collider.identify()){
case Category::Collectible :
switch(static_cast<Collectible&>(collider).getType()){
case Collectible::Sword :
giveSword();
break;
case Collectible::Poison :
++poison_stack;
break;
case Collectible::Coin :
++ coin_stack;
break;
case Collectible::Key :
++key_stack;
break;
case Collectible::Sword : giveSword(); break;
case Collectible::Poison : ++poison_stack; break;
case Collectible::Coin : ++coin_stack; break;
case Collectible::Key : ++key_stack; break;
case Collectible::Dagger : ++dagger_stack; break;
}
break;
}
......
......@@ -29,7 +29,7 @@ void Room::loadTextures(){
mTextures.load(Textures::Key, pathOfID(Textures::Key));
mTextures.load(Textures::LockedDoors, pathOfID(Textures::LockedDoors));
mTextures.load(Textures::UltraLockedDoors, pathOfID(Textures::UltraLockedDoors));
mTextures.load(Textures::Dagger, pathOfID(Textures::Dagger));
}
......@@ -61,6 +61,7 @@ void Room::buildScene(std::string path){
case Agent::Poison :
case Agent::SwordFloor :
case Agent::Key :
case Agent::Dagger :
Collectible* sword(new Collectible(mTextures,Collectible::typeIn(rType)));
sword->setPosition(alpha_x*x,alpha_y*y);
mSceneLayers[Air]->attachChild(sword);
......
......@@ -102,6 +102,9 @@ std::string pathOfID(Textures::ID id){
case Textures::UltraLockedDoors:
str = "res/uldoor.png";
break;
case Textures::Dagger:
str = "res/dagger.png";
break;
default :
throw std::logic_error("TextureHolder::pathOfID, Non-exhaustive pattern-matching");
}
......
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