Commit 04ff12af authored by pa's avatar pa

HUD support of key and coin

parent 2796c116
0 0.5 0.5
6 0.25 0.5
16 0.75 0.5
18 0.5 0.25
19 0.5 0.75
......@@ -8,8 +8,12 @@
class HUD{
public :
struct Meter{
int cv; int mv; Agent::Type upType,downType;
};
struct HUD_data{
int HP; int HP_max; int poison_stack; int poison_stack_max;
Meter* meters;
int size;
};
HUD(sf::RenderWindow& window, HUD_data* data);
......@@ -27,7 +31,6 @@ class HUD{
TextureHolder mTextures;
SceneNode mRoot;
SpriteNode** mHPs;
SpriteNode** mPoisonStack;
SpriteNode*** mContent;
HUD_data* mData;
};
......@@ -11,9 +11,10 @@ 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, Void
SwordFloor, Sword_0, Sword_1, Sword_2, Sword_3, Sword_4, Sword_5,
Doors, HP_full, HP_down, Poison, Void, Coin, Key
};
Textures::ID toTextureID(Type type);
static Textures::ID toTextureID(Type type);
public :
Agent(Type type, TextureHolder const& textures);
......
......@@ -8,7 +8,7 @@
class Collectible : public Agent{
public :
enum Type {Sword, Poison, Health, Dagger};
enum Type {Sword, Poison, Coin, Key, Health, Dagger};
static Agent::Type typeOf(Type type);
static Type typeIn(Agent::Type type);
......
......@@ -28,6 +28,8 @@ public :
virtual Category::Category identify() const{ return Category::Player;}
int getPoisonStack() const{return poison_stack;}
int getCoins() const{return coin_stack;}
int getKeys() const{return key_stack;}
virtual void onCollideWith(SceneNode& collider);
......@@ -39,4 +41,6 @@ private :
sf::Time mWCD, mWElapse;
int poison_stack; bool unsing_poison;
int key_stack; bool unsing_key;
int coin_stack; bool unsing_coin;
};
......@@ -9,7 +9,8 @@
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
SwordFloor, Sword_0, Sword_1, Sword_2, Sword_3, Sword_4, Sword_5,
Doors, HP_full, HP_down, Void, Coin ,Key
};
}
......
res/key.png

244 Bytes

res/void.png

184 Bytes | W: | H:

res/void.png

182 Bytes | W: | H:

res/void.png
res/void.png
res/void.png
res/void.png
  • 2-up
  • Swipe
  • Onion skin
......@@ -5,39 +5,39 @@
HUD::HUD(sf::RenderWindow& window, HUD::HUD_data* data)
: mWindow(window), mView(window.getDefaultView()),
mBounds(0.f,0.f,mView.getSize().x,mView.getSize().y), mData(data){
loadTextures();
mHPs = new SpriteNode*[mData->HP_max];
for(int i = 0 ; i < mData->HP_max; ++i){
mHPs[i] = new SpriteNode(Agent::HP_full,mTextures);
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);
}
loadTextures();
mContent = new SpriteNode**[mData->size];
for(int i = 0 ; i < mData->size ; ++i){
mContent[i] = new SpriteNode*[mData->meters[i].mv];
for(int j = 0 ; j < mData->meters[i].mv ; ++j){
mContent[i][j] = new SpriteNode(mData->meters[i].upType, mTextures);
mRoot.attachChild(mContent[i][j]);
mContent[i][j]->move(32*j+16,32*i+16);
}
}
}
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));
for(int i = 0 ; i < mData->size ; ++i){
mTextures.load(Agent::toTextureID(mData->meters[i].upType),
pathOfID(Agent::toTextureID(mData->meters[i].upType)));
mTextures.load(Agent::toTextureID(mData->meters[i].downType),
pathOfID(Agent::toTextureID(mData->meters[i].downType)));
}
}
void HUD::draw(){
mWindow.draw(mRoot);
}
void HUD::update(sf::Time dt){
for(int i = 0; i < mData->poison_stack; ++i){
mPoisonStack[i]->setType(Agent::Poison);
}
for(int i = mData->poison_stack ; i < mData->poison_stack_max; ++i){
mPoisonStack[i]->setType(Agent::Void);
for(int i = 0 ; i < mData->size ; ++i){
for(int j = 0 ; j < mData->meters[i].cv ; ++j)
mContent[i][j]->setType(mData->meters[i].upType);
for(int j = mData->meters[i].cv ; j < mData->meters[i].mv ; ++j)
mContent[i][j]->setType(mData->meters[i].downType);
}
mRoot.update(dt);
}
......
......@@ -39,6 +39,10 @@ Textures::ID Agent::toTextureID(Agent::Type type){
return Textures::ID::HP_down;
case Void :
return Textures::ID::Void;
case Key :
return Textures::ID::Key;
case Coin :
return Textures::ID::Coin;
default :
throw std::logic_error("Agent::toTextureID, non-exhaustive pattern-matching");
}
......
#include "../headers/alive.hpp"
Alive::Alive(Agent::Type type, TextureHolder const& textures, int HP, Entity::Side side)
:Entity(type,textures), mHP(HP), mState(Normal), mSide(side){}
:Entity(type,textures), mHP(HP), mState(Normal), mSide(side), mPoisoned(false){}
void Alive::updateCurrent(sf::Time dt){
......
......@@ -4,6 +4,8 @@ Agent::Type Collectible::typeOf(Collectible::Type type){
switch(type){
case Poison : return Agent::Poison;
case Sword : return Agent::SwordFloor;
case Key : return Agent::Key;
case Coin : return Agent::Coin;
default : return Agent::SwordFloor;
}
}
......@@ -12,6 +14,8 @@ Collectible::Type Collectible::typeIn(Agent::Type type){
switch(type){
case Agent::Poison : return Poison;
case Agent::SwordFloor : return Sword;
case Agent::Key : return Key;
case Agent::Coin : return Coin;
default : return Collectible::Sword;
}
}
......
......@@ -26,6 +26,8 @@ void Game::processEvents(){
break;
}
}
if(sf::Keyboard::isKeyPressed(sf::Keyboard::LControl)
&& sf::Keyboard::isKeyPressed(sf::Keyboard::Q)) mWindow.close();
}
void Game::update(sf::Time deltaTime){
......
......@@ -15,7 +15,7 @@ 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){
poison_stack(0), coin_stack(0), key_stack(0){
mQCD = sf::seconds(8.f);
mWCD = sf::seconds(1.f);
}
......@@ -90,6 +90,12 @@ void Player::onCollideWith(SceneNode& collider){
case Collectible::Poison :
++poison_stack;
break;
case Collectible::Coin :
++ coin_stack;
break;
case Collectible::Key :
++key_stack;
break;
}
break;
}
......
......@@ -26,6 +26,8 @@ void Room::loadTextures(){
mTextures.load(Textures::SwordFloor, pathOfID(Textures::SwordFloor));
mTextures.load(Textures::Doors, pathOfID(Textures::Doors));
mTextures.load(Textures::Poison, pathOfID(Textures::Poison));
mTextures.load(Textures::Coin, pathOfID(Textures::Coin));
mTextures.load(Textures::Key, pathOfID(Textures::Key));
}
......@@ -54,8 +56,10 @@ void Room::buildScene(std::string path){
mSceneLayers[Air]->attachChild(ennemy);
break;
}
case Agent::Poison :{
case Agent::Coin :{
case Agent::Poison :
case Agent::SwordFloor :
case Agent::Key :
Collectible* sword(new Collectible(mTextures,Collectible::typeIn(rType)));
sword->setPosition(alpha_x*x,alpha_y*y);
mSceneLayers[Air]->attachChild(sword);
......
......@@ -90,6 +90,12 @@ std::string pathOfID(Textures::ID id){
case Textures::Void:
str = "res/void.png";
break;
case Textures::Key:
str = "res/key.png";
break;
case Textures:: Coin:
str = "res/coin.png";
break;
default :
throw std::logic_error("TextureHolder::pathOfID, Non-exhaustive pattern-matching");
}
......
......@@ -8,14 +8,25 @@ World::World(sf::RenderWindow& window)
mRoom = mCarte.checkIn();
spawnPlayer(mRoom);
mSceneGraph.attachChild(mRoom);
mData = new HUD::HUD_data;
mData->HP = mData->HP_max = getPlayerHP();
mData->poison_stack_max = 10; mData->poison_stack = 0;
mData->size = 4;
mData->meters = new HUD::Meter[mData->size];
mData->meters[0].cv = mData->meters[0].mv = getPlayerHP();
mData->meters[0].upType = Agent::HP_full; mData->meters[0].downType = Agent::HP_down;
mData->meters[1].mv = 10; mData->meters[1].cv = 0;
mData->meters[1].upType = Agent::Poison; mData->meters[1].downType = Agent::Void;
mData->meters[2].mv = 10; mData->meters[2].cv = 0;
mData->meters[2].upType = Agent::Coin; mData->meters[2].downType = Agent::Void;
mData->meters[3].mv = 10; mData->meters[3].cv = 0;
mData->meters[3].upType = Agent::Key; mData->meters[3].downType = Agent::Void;
}
void World::fillData(){
mData->HP = getPlayerHP();
mData->poison_stack = mPlayer->getPoisonStack();
mData->meters[0].cv = getPlayerHP();
mData->meters[1].cv = mPlayer->getPoisonStack();
mData->meters[2].cv = mPlayer->getCoins();
mData->meters[3].cv = mPlayer->getKeys();
}
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