Commit 31e02a18 authored by pa's avatar pa

Added Merchant features

parent cb9fae54
0 0.5 0.5
23 0.5 0.25
14 0.25 0.75
14 0.75 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, Dagger
Doors, HP_full, HP_down, Poison, Void, Coin, Key, LockedDoors, UltraLockedDoors, Dagger, Merchant
};
static Textures::ID toTextureID(Type type);
......
......@@ -19,6 +19,7 @@ public :
Alive(Agent::Type type, TextureHolder const& Textures, int HP, Entity::Side side);
int getHP() const{return mHP;}
void heal(){++mHP;}
State getState() const{return mState;}
virtual void updateCurrent(sf::Time dt);
......
#pragma once
class World;
#include <sstream>
#include <stack>
#include "room.hpp"
......@@ -11,7 +13,8 @@ public :
typedef Room* RPtr;
typedef std::vector<std::vector<int>> IMap;
typedef std::vector<RPtr> Map;
Carte(TextureHolder &textures, sf::IntRect& bounds, float r, float alpha, float inDepth, int n);
Carte(TextureHolder &textures, sf::IntRect& bounds, float r, float alpha, float inDepth, int n,
World* world=nullptr);
void move(Door::Dir dir){
mX += xOfDir(dir); mY += yOfDir(dir);
......@@ -32,5 +35,6 @@ private :
private :
IMap mDoors;
Map mCarte;
World* mWorld;
int mX,mY, mWidth;
};
......@@ -22,3 +22,4 @@ class Collectible : public Agent{
private :
Type mType;
};
......@@ -16,7 +16,7 @@
class Room : public SceneNode{
public:
Room(TextureHolder& textures, sf::IntRect& bounds, int depth);
Room(TextureHolder& textures, sf::IntRect& bounds, int depth, World* world = nullptr);
virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const;
......@@ -47,4 +47,5 @@ private:
sf::IntRect& mBounds;
int mDepth;
World* mWorld;
};
......@@ -45,6 +45,7 @@ public :
virtual void onCollideWith(SceneNode& collider);
World* getContext() const {return mWorld;}
void setContext(World *world){mWorld = world;}
private :
std::vector<Ptr> mChildren;
......
......@@ -15,6 +15,17 @@ private :
sf::Vector2f mBase;
};
class HomingSpeedPatern : public SpeedPatern {
public :
HomingSpeedPatern(sf::Vector2f base, SceneNode* target, float inertia);
void setSource(SceneNode* nd){mSource = nd;}
virtual void step(sf::Time dt);
private :
SceneNode *mSource, *mTarget;
float mInertia;
};
class RotationSpeedPatern : public SpeedPatern{
public :
......
......@@ -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, Dagger
Doors, HP_full, HP_down, Void, Coin , Key, LockedDoors, UltraLockedDoors, Dagger, Merchant
};
}
......
......@@ -29,6 +29,7 @@ public:
void spawnPlayer(Room* room);
int getPlayerHP() const;
Player* getPlayer() const{return mPlayer;}
HUD::HUD_data* getHUDLocator(){return mData;}
......
......@@ -49,6 +49,8 @@ Textures::ID Agent::toTextureID(Agent::Type type){
return Textures::ID::UltraLockedDoors;
case Dagger :
return Textures::ID::Dagger;
case Merchant :
return Textures::ID::Merchant;
default :
throw std::logic_error("Agent::toTextureID, non-exhaustive pattern-matching");
}
......
......@@ -2,13 +2,12 @@
#include <iostream>
#include "../headers/utilitary.hpp"
#define NO_FILE 4
#define NO_FILE 5
Carte::Carte(TextureHolder& textures, sf::IntRect& bounds, float r, float alpha, float inDepth, int n)
: mCarte(n*n), mWidth(n),
mDoors(n,std::vector<int>(n,0)),
mX(n/2),mY(n/2){
Carte::Carte(TextureHolder& textures, sf::IntRect& bounds, float r, float alpha, float inDepth, int n, World* world)
: mCarte(n*n), mWidth(n), mDoors(n,std::vector<int>(n,0)),
mX(n/2),mY(n/2), mWorld(world){
firstPass(textures, bounds, r, alpha, inDepth);
}
......@@ -71,7 +70,7 @@ void Carte::firstPass(TextureHolder& textures, sf::IntRect& bounds, float r, flo
for(int j = 0 ; j < mWidth ; ++j){
if(mDoors[i][j]>0){
mDoors[i][j] -= terminaison;
Room *room = new Room(textures, bounds, std::min(depths[i][j],static_cast<int>(Door::DeadEnd)-1));
Room *room = new Room(textures, bounds, std::min(depths[i][j],static_cast<int>(Door::DeadEnd)-1), mWorld);
std::ostringstream osstr; osstr << "data/room_" << random_int(NO_FILE) << ".dat";
room->buildScene(osstr.str());
for(int k = 0 ; k < 4 ; ++k){
......@@ -84,7 +83,7 @@ void Carte::firstPass(TextureHolder& textures, sf::IntRect& bounds, float r, flo
}
int i = mWidth/2,j = mWidth/2;
delete mCarte[i*mWidth+j];
mCarte[i*mWidth+j] = new Room(textures,bounds,0);
mCarte[i*mWidth+j] = new Room(textures,bounds,0, mWorld);
mCarte[i*mWidth+j]->buildScene("data/room_0.dat");
for(int k = 0 ; k < 4 ; ++k){
if((mDoors[i][j] & (1 << k)))
......
#include "../headers/collectible.hpp"
#include "../headers/player.hpp"
Agent::Type Collectible::typeOf(Collectible::Type type){
switch(type){
......@@ -7,6 +9,7 @@ Agent::Type Collectible::typeOf(Collectible::Type type){
case Key : return Agent::Key;
case Coin : return Agent::Coin;
case Dagger : return Agent::Dagger;
case Health : return Agent::HP_full;
default : return Agent::SwordFloor;
}
}
......@@ -18,17 +21,24 @@ Collectible::Type Collectible::typeIn(Agent::Type type){
case Agent::Key : return Key;
case Agent::Coin : return Coin;
case Agent::Dagger : return Dagger;
case Agent::HP_full : return Health;
default : return Collectible::Sword;
}
}
Collectible::Collectible(TextureHolder const& tex, Collectible::Type type) : Agent(typeOf(type),tex), mType(type) {}
void Collectible::onCollideWith(SceneNode& collider){
switch(collider.identify()){
case Category::Player :
stageForRemoval();
break;
if(getType() != Collectible::Health)
switch(collider.identify()){
case Category::Player :
stageForRemoval();
break;
}
else{
switch(collider.identify()){
case Category::Player :
break;
}
}
}
#include "../headers/ennemy.hpp"
#include "../headers/world.hpp"
Ennemy::Ennemy(TextureHolder const& textures) : Alive(Agent::Tower,textures,5,Entity::Ennemy),
mIsQ(true), mIsW(true){
......@@ -19,14 +20,21 @@ Agent::Type Ennemy::typeOfState(){
void Ennemy::q_spell(float sense){
sf::Vector2f positionSetter(75.f,0.f);
sf::Vector2f positionSetter(75.f,0.f), iSpeed(200.f,0.f);
sf::Transform transform; transform.rotate(120.f);
for(int i = 0 ; i < 3 ; ++i){
Orbital* orb = new Orbital(Agent::tProjectile, getTexHolder(),
new HellSpeedPatern(positionSetter,sense*94.f,1.005f),Entity::Ennemy);
// Orbital* orb = new Orbital(Agent::tProjectile, getTexHolder(),
// new HellSpeedPatern(positionSetter,sense*94.f,1.005f),Entity::Ennemy);
// orb->setPosition(positionSetter);
//SpeedPatern *sp = new HellSpeedPatern(iSpeed,
// getContext()->getPlayer(),1.8f);
SpeedPatern *sp = new HellSpeedPatern(positionSetter,sense*94.f,1.005f);
Orbital *orb = new Orbital(Agent::tProjectile,getTexHolder(),sp,Entity::Ennemy);
//sp->setSource(orb);
orb->setPosition(positionSetter);
attachChild(orb);
positionSetter = transform.transformPoint(positionSetter);
iSpeed = transform.transformPoint(iSpeed);
}
}
......
......@@ -17,7 +17,8 @@ void Orbital::updateCurrent(sf::Time dt){
void Orbital::onCollideWith(SceneNode& node){
switch(node.identify()){
case Category::Orbital :
if(getType() == Agent::Dagger || static_cast<Agent&>(node).getType() == Agent::Dagger)
if(getType() == Agent::Dagger || static_cast<Agent&>(node).getType() == Agent::Dagger
|| getSide() == static_cast<Orbital&>(node).getSide())
return;
case Category::Player: case Category::Ennemy :
stageForRemoval();
......
......@@ -112,6 +112,8 @@ void Player::onCollideWith(SceneNode& collider){
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;
}
break;
}
......
#include "../headers/room.hpp"
Room::Room(TextureHolder& textures, sf::IntRect& bounds, int depth)
: mTextures(textures), mBounds(bounds), mSpawnPosition(bounds.width/2.f,bounds.height/2.f), mDepth(depth){
Room::Room(TextureHolder& textures, sf::IntRect& bounds, int depth, World* world)
: mTextures(textures), mBounds(bounds), mSpawnPosition(bounds.width/2.f,bounds.height/2.f),
mDepth(depth), mWorld(world){
for(int i = 0 ; i < LayerCount ; ++i)
mSceneLayers[i] = nullptr;
......@@ -30,6 +31,8 @@ void Room::loadTextures(){
mTextures.load(Textures::LockedDoors, pathOfID(Textures::LockedDoors));
mTextures.load(Textures::UltraLockedDoors, pathOfID(Textures::UltraLockedDoors));
mTextures.load(Textures::Dagger, pathOfID(Textures::Dagger));
mTextures.load(Textures::Merchant, pathOfID(Textures::Merchant));
mTextures.load(Textures::HP_full, pathOfID(Textures::HP_full));
}
......@@ -53,12 +56,20 @@ void Room::buildScene(std::string path){
}
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 :
......
......@@ -11,6 +11,18 @@ sf::Vector2f SpeedPatern::getVelocity() const{
}
HomingSpeedPatern::HomingSpeedPatern(sf::Vector2f mBase, SceneNode* target, float inertia)
: SpeedPatern(mBase), mTarget(target), mInertia(inertia){}
void HomingSpeedPatern::step(sf::Time dt){
sf::Vector2f dir = mTarget->getWorldPosition() - mSource->getWorldPosition();
float angle = 180.f *(atan2(getVelocity().y, getVelocity().x) - atan2(dir.y,dir.x))/3.14f;
if(angle >= 180.f) angle-=360.f;
if(angle <= -180.f) angle += 360.f;
rotate(-mInertia*angle*dt.asSeconds());
SpeedPatern::step(dt);
}
RotationSpeedPatern::RotationSpeedPatern(sf::Vector2f base, float rpm)
: SpeedPatern(base), mRPM(rpm){
rotate(90.f);
......
......@@ -105,6 +105,9 @@ std::string pathOfID(Textures::ID id){
case Textures::Dagger:
str = "res/dagger.png";
break;
case Textures::Merchant:
str = "res/merchant.png";
break;
default :
throw std::logic_error("TextureHolder::pathOfID, Non-exhaustive pattern-matching");
}
......
......@@ -4,7 +4,7 @@
World::World(sf::RenderWindow& window)
: mWindow(window), mWorldView(window.getDefaultView()),
mWorldBounds(0.f,0.f,mWorldView.getSize().x,mWorldView.getSize().y),
mCarte(mTextures,mWorldBounds,0.9f,0.9f,0.4f,20){
mCarte(mTextures,mWorldBounds,0.9f,0.9f,0.4f,20,this){
mRoom = mCarte.checkIn();
spawnPlayer(mRoom);
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