Commit 00b48a13 authored by pa's avatar pa

Added a to buy collectibles and cleaned a few things

Signed-off-by: pa's avatarpa <pa@crans.org>
parent f5976903
......@@ -13,13 +13,17 @@ class Collectible : public Agent{
static Type typeIn(Agent::Type type);
public :
Collectible(TextureHolder const& tex, Type type);
Collectible(TextureHolder const& tex, Type type, bool buyable = false, int price = 0);
Type getType(){return mType;}
virtual Category::Category identify() const{return Category::Collectible;}
virtual void onCollideWith(SceneNode& collider);
bool isBuyable() const {return mBuyable;}
int cost() const {return mPrice;}
private :
Type mType;
bool mBuyable; int mPrice;
};
......@@ -21,17 +21,17 @@ Carte::~Carte(){
int Carte::xOfDir(Door::Dir dir){
switch(dir){
case Door::UP: case Door::DOWN: return 0;
case Door::RIGHT: return 1;
case Door::LEFT: return -1;
default : return 0;
}
}
int Carte::yOfDir(Door::Dir dir){
switch(dir){
case Door::LEFT: case Door::RIGHT: return 0;
case Door::DOWN: return 1;
case Door::UP: return -1;
default: return 0;
}
}
......@@ -41,6 +41,7 @@ Door::Dir Carte::invDir(Door::Dir dir){
case Door::RIGHT: return Door::LEFT;
case Door::DOWN: return Door::UP;
case Door::UP: return Door::DOWN;
default :return Door::RIGHT;
}
}
......
......@@ -26,19 +26,14 @@ Collectible::Type Collectible::typeIn(Agent::Type type){
}
}
Collectible::Collectible(TextureHolder const& tex, Collectible::Type type) : Agent(typeOf(type),tex), mType(type) {}
Collectible::Collectible(TextureHolder const& tex, Collectible::Type type,
bool buyable, int price) : Agent(typeOf(type),tex), mType(type), mBuyable(buyable), mPrice(price) {}
void Collectible::onCollideWith(SceneNode& collider){
if(getType() != Collectible::Health)
if(!isBuyable())
switch(collider.identify()){
case Category::Player :
stageForRemoval();
break;
}
else{
switch(collider.identify()){
case Category::Player :
break;
}
}
}
......@@ -5,6 +5,7 @@ Agent::Type Door::ofLockLevel(int ll){
case 0 : return Agent::Doors;
case 1 : return Agent::LockedDoors;
case 2 : return Agent::UltraLockedDoors;
default : return Agent::UltraLockedDoors;
}
}
......
......@@ -15,6 +15,8 @@ Agent::Type Ennemy::typeOfState(){
return Agent::PlayerHit;
case Alive::HitB :
return Agent::Tower;
default :
return Agent::Tower;
}
}
......
......@@ -10,13 +10,15 @@ Agent::Type Player::typeOfState(){
return Agent::PlayerHit;
case Alive::HitB :
return Agent::Player;
default :
return Agent::Player;
}
}
Player::Player(TextureHolder const& textures)
: Alive(Agent::Player,textures,8,Entity::Player), mIsQAvailable(true), mIsWAvailable(true), mW(false),
unsing_poison(false), unsing_dagger(false),
poison_stack(0), coin_stack(0), key_stack(0), dagger_stack(0){
poison_stack(0), coin_stack(4), key_stack(0), dagger_stack(0){
mQCD = sf::seconds(8.f);
mWCD = sf::seconds(1.f);
}
......@@ -106,14 +108,19 @@ void Player::keyBindings(){
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::Dagger : ++dagger_stack; break;
case Collectible::Health :
if(coin_stack >= 2 && getHP() < 8){coin_stack -=2; heal();} break;
if(!static_cast<Collectible&>(collider).isBuyable()
|| static_cast<Collectible&>(collider).cost() <= coin_stack){
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::Dagger : ++dagger_stack; break;
case Collectible::Health : heal(); break;
}
if (static_cast<Collectible&>(collider).cost() <= coin_stack){
coin_stack -= static_cast<Collectible&>(collider).cost(); collider.stageForRemoval();
}
}
break;
}
......
......@@ -54,30 +54,35 @@ void Room::buildScene(std::string path){
mSceneLayers[Background]->attachChild(sprite);
break;
}
case Agent::Tower :{
Ennemy* ennemy(new Ennemy(mTextures));
ennemy->setContext(mWorld);
ennemy->setPosition(alpha_x*x,alpha_y*y);
mSceneLayers[Air]->attachChild(ennemy);
break;
}
case Agent::Merchant : {
Agent *agent(new Agent(Agent::Merchant,mTextures));
agent->setPosition(alpha_x*x,alpha_y*y);
mSceneLayers[Air]->attachChild(agent);
break;
}
case Agent::Coin :{
case Agent::Poison :
case Agent::HP_full :
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);
break;
}
case Agent::Tower :{
Ennemy* ennemy(new Ennemy(mTextures));
ennemy->setContext(mWorld);
ennemy->setPosition(alpha_x*x,alpha_y*y);
mSceneLayers[Air]->attachChild(ennemy);
break;
}
case Agent::Merchant : {
Agent *agent(new Agent(Agent::Merchant,mTextures));
agent->setPosition(alpha_x*x,alpha_y*y);
mSceneLayers[Air]->attachChild(agent);
break;
}
case Agent::HP_full :{
Collectible* sword(new Collectible(mTextures,Collectible::typeIn(rType),true,2));
sword->setPosition(alpha_x*x,alpha_y*y);
mSceneLayers[Air]->attachChild(sword);
break;
}
case Agent::Coin :{
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);
break;
}
}
}
}
......@@ -109,23 +114,23 @@ void Room::draw(sf::RenderTarget& target, sf::RenderStates states) const{
float Room::getDoorPlacement_X(Door::Dir dir){
switch(dir){
case Door::UP : case Door::DOWN :
return 0.5f;
case Door::LEFT :
return 0.01f;
case Door::RIGHT :
return 0.99f;
default :
return 0.5f;
}
}
float Room::getDoorPlacement_Y(Door::Dir dir){
switch(dir){
case Door::LEFT : case Door::RIGHT :
return 0.5f;
case Door::UP :
return 0.02f;
case Door::DOWN :
return 0.98f;
default :
return 0.5f;
}
}
......
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