Commit 19e6692d authored by pa's avatar pa

Added lock to doors

parent 04ff12af
......@@ -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
Doors, HP_full, HP_down, Poison, Void, Coin, Key, LockedDoors
};
static Textures::ID toTextureID(Type type);
......
......@@ -6,14 +6,18 @@
class Door : public Agent{
public :
enum Dir{UP, RIGHT, DOWN, LEFT};
static Agent::Type ofLockLevel(int ll);
public :
Door(TextureHolder const& mTextures, Door::Dir dir);
Door(TextureHolder const& mTextures, Door::Dir dir, int locked=0);
Dir getDir() const{return mDir;}
virtual Category::Category identify() const{return Category::Door;}
int lockLevel() const{return mLockLevel;}
private:
Dir mDir;
int mLockLevel;
};
......@@ -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
Doors, HP_full, HP_down, Void, Coin , Key, LockedDoors
};
}
......
......@@ -43,6 +43,8 @@ Textures::ID Agent::toTextureID(Agent::Type type){
return Textures::ID::Key;
case Coin :
return Textures::ID::Coin;
case LockedDoors :
return Textures::ID::LockedDoors;
default :
throw std::logic_error("Agent::toTextureID, non-exhaustive pattern-matching");
}
......
#include "../headers/door.hpp"
Agent::Type Door::ofLockLevel(int ll){
switch(ll){
case 0 : return Agent::Doors;
case 1 : return Agent::LockedDoors;
}
}
Door::Door(TextureHolder const& mTextures, Dir dir)
: Agent(Agent::Doors, mTextures), mDir(dir){
Door::Door(TextureHolder const& mTextures, Dir dir, int lock)
: Agent(ofLockLevel(lock),mTextures), mDir(dir), mLockLevel(lock){
rotate(90.f*static_cast<int>(dir));
}
......@@ -28,6 +28,7 @@ void Room::loadTextures(){
mTextures.load(Textures::Poison, pathOfID(Textures::Poison));
mTextures.load(Textures::Coin, pathOfID(Textures::Coin));
mTextures.load(Textures::Key, pathOfID(Textures::Key));
mTextures.load(Textures::LockedDoors, pathOfID(Textures::LockedDoors));
}
......@@ -119,7 +120,7 @@ float Room::getDoorPlacement_Y(Door::Dir dir){
void Room::addDoor(Door::Dir dir){
float x = mBounds.width, y = mBounds.height;
Door* door(new Door(mTextures,dir));
Door* door(new Door(mTextures,dir,1));
door->setPosition(getDoorPlacement_X(dir)*x,getDoorPlacement_Y(dir)*y);
mSceneLayers[Background]->attachChild(door);
}
......
......@@ -93,9 +93,12 @@ std::string pathOfID(Textures::ID id){
case Textures::Key:
str = "res/key.png";
break;
case Textures:: Coin:
case Textures::Coin:
str = "res/coin.png";
break;
case Textures::LockedDoors:
str = "res/ldoor.png";
break;
default :
throw std::logic_error("TextureHolder::pathOfID, Non-exhaustive pattern-matching");
}
......
......@@ -62,15 +62,18 @@ void World::checkCollision(){
}
for(auto &pair : stack){
if(pair.first->identify() == Category::Player && pair.second->identify() == Category::Door){
mPlayer = static_cast<Player*>(mRoom->detachPlayer(*mPlayer));
Room* room = static_cast<Room*>(mSceneGraph.detachChild(*mRoom));
mCarte.checkOut(room);
mCarte.move(static_cast<Door&>(*pair.second).getDir());
mRoom->reset();
mRoom = mCarte.checkIn();
mRoom->spawnAt(static_cast<Door&>(*pair.second).getDir());
mRoom->attachPlayer(mPlayer);
mSceneGraph.attachChild(mRoom);
if(static_cast<Door&>(*pair.second).lockLevel() <= static_cast<Player&>(*pair.first).getKeys()){
std::cout << static_cast<Door&>(*pair.second).lockLevel() << ' ' << static_cast<Player&>(*pair.first).getKeys() << '\n';
mPlayer = static_cast<Player*>(mRoom->detachPlayer(*mPlayer));
Room* room = static_cast<Room*>(mSceneGraph.detachChild(*mRoom));
mCarte.checkOut(room);
mCarte.move(static_cast<Door&>(*pair.second).getDir());
mRoom->reset();
mRoom = mCarte.checkIn();
mRoom->spawnAt(static_cast<Door&>(*pair.second).getDir());
mRoom->attachPlayer(mPlayer);
mSceneGraph.attachChild(mRoom);
}
}
}
}
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