Commit 28997f47 authored by pa's avatar pa

Changed the class hierarchy and fixed some bugs

parent 064f1d84
#pragma once
#include <iostream>
#include <SFML/Graphics.hpp>
#include "textureHolder.hpp"
#include "sceneNode.hpp"
......@@ -22,8 +23,6 @@ class Agent : public SceneNode{
sf::Sprite& getSprite(){ return mSprite;}
const TextureHolder& getTexHolder() const{return mTextures;}
void setTexture();
sf::Texture& getTexture();
virtual void updateCurrent(sf::Time dt);
......@@ -32,6 +31,8 @@ class Agent : public SceneNode{
virtual Category::Category identify() const{return Category::Agent;}
private :
void setTexture();
virtual void drawCurrent(sf::RenderTarget& target, sf::RenderStates states) const;
Type mType;
......
......@@ -2,12 +2,12 @@
#include <SFML/Graphics.hpp>
#include "orbital.hpp"
#include "agent.hpp"
#include "entity.hpp"
#include "category.hpp"
class Alive : public Agent{
class Alive : public Entity{
public :
enum State{
Normal, HitA, HitB
......
......@@ -11,7 +11,7 @@ class Ennemy : public Alive{
public :
Ennemy(TextureHolder const& Textures);
virtual Agent::Type typeOfState() const;
virtual Agent::Type typeOfState();
void q_spell(float sense);
virtual void updateCurrent(sf::Time dt);
......
#pragma once
#include <SFML/Graphics.hpp>
#include "sceneNode.hpp"
#include "agent.hpp"
#include "category.hpp"
class Entity : public Agent{
public:
Entity(Agent::Type type, TextureHolder const& textures);
void setVelocity(sf::Vector2f velocity);
void setVelocity(float x, float y);
......
......@@ -2,16 +2,16 @@
#include <iostream>
#include <SFML/Graphics.hpp>
#include "agent.hpp"
#include "entity.hpp"
#include "speedPatern.hpp"
#include "category.hpp"
class Orbital : public Agent{
class Orbital : public Entity{
public :
Orbital(Agent::Type type , TextureHolder const& texture, SpeedPatern* spP, bool ally);
virtual void updateCurrent(sf::Time dt);
virtual Category::Category identify() const;
virtual Category::Category identify() const{return Category::Orbital;}
virtual bool getOwner() const{ return mAlly; }
......
......@@ -8,10 +8,14 @@
class Player : public Alive{
public :
virtual Agent::Type typeOfState();
public :
Player(TextureHolder const& Textures);
void q_spell();
void w_spell();
virtual void updateCurrent(sf::Time dt);
virtual void act(sf::Time dt);
......@@ -23,4 +27,7 @@ public :
private :
bool mIsQAvailable;
sf::Time mQCD, mQElapse;
bool mIsWAvailable;
sf::Time mWCD, mWElapse;
};
......@@ -3,7 +3,7 @@
#include <SFML/Graphics.hpp>
#include "agent.hpp"
#include "category.hpp"
#include <iostream>
class Sword : public Agent{
public :
......
......@@ -18,7 +18,6 @@ template <typename Ressource, typename Identifier> class RessourceHolder {
public:
void load(Identifier id, const std::string& filename);
Ressource& get(Identifier id);
const Ressource& get(Identifier id) const;
......
res/sword_0.png

314 Bytes | W: | H:

res/sword_0.png

337 Bytes | W: | H:

res/sword_0.png
res/sword_0.png
res/sword_0.png
res/sword_0.png
  • 2-up
  • Swipe
  • Onion skin
res/sword_1.png

382 Bytes | W: | H:

res/sword_1.png

395 Bytes | W: | H:

res/sword_1.png
res/sword_1.png
res/sword_1.png
res/sword_1.png
  • 2-up
  • Swipe
  • Onion skin
res/sword_2.png

425 Bytes | W: | H:

res/sword_2.png

411 Bytes | W: | H:

res/sword_2.png
res/sword_2.png
res/sword_2.png
res/sword_2.png
  • 2-up
  • Swipe
  • Onion skin
res/sword_3.png

440 Bytes | W: | H:

res/sword_3.png

424 Bytes | W: | H:

res/sword_3.png
res/sword_3.png
res/sword_3.png
res/sword_3.png
  • 2-up
  • Swipe
  • Onion skin
res/sword_4.png

416 Bytes | W: | H:

res/sword_4.png

424 Bytes | W: | H:

res/sword_4.png
res/sword_4.png
res/sword_4.png
res/sword_4.png
  • 2-up
  • Swipe
  • Onion skin
#include "../headers/player.hpp"
Player::Player(TextureHolder const& textures) : Alive(Agent::Player,textures,8), mIsQAvailable(true){
mQCD = sf::seconds(8.f);
}
void Player::q_spell(){
if(mIsQAvailable){
mIsQAvailable = false;
std::unique_ptr<Sword> sword(new Sword(getTexHolder()));
attachChild(std::move(sword));
// sf::Vector2f positionSetter(75.f,0.f);
// sf::Transform transform; transform.rotate(120.f);
// for(int i = 0 ; i < 3 ; ++i){
// std::unique_ptr<Orbital>
// escortR(new Orbital(Agent::qProjectile,new RotationSpeedPatern(positionSetter,540.f), true));
// escortR->setPosition(positionSetter);
// escortR->setTexture(getTexHolder());
// attachChild(std::move(escortR));
// positionSetter = transform.transformPoint(positionSetter);
// }
}
}
void Player::updateCurrent(sf::Time dt){
// Q-SPELL
if(!mIsQAvailable){
if (mQElapse < mQCD) mQElapse += dt;
else {mIsQAvailable = true; mQElapse = sf::Time::Zero;}
}
Alive::updateCurrent(dt);
}
void Player::act(sf::Time dt){
keyBindings();
}
void Player::keyBindings(){
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Left)) moveLeft();
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Right)) moveRight();
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Up)) moveUp();
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Down)) moveDown();
if(sf::Keyboard::isKeyPressed(sf::Keyboard::A)) q_spell();
}
Category::Category Player::identify() const{
return Category::Player;
}
......@@ -39,14 +39,9 @@ void Agent::setTexture(){
mSprite.getLocalBounds().height/2.f);
}
sf::Texture Agent::getTexture(){
return mTextures.get(toTextureID(mType));
}
void Agent::updateCurrent(sf::Time dt){
SceneNode::updateCurrent(dt);
setTexture();
}
void Agent::drawCurrent(sf::RenderTarget& target, sf::RenderStates states) const{
......@@ -57,10 +52,6 @@ sf::FloatRect Agent::getBounds() const{
return getWorldTransform().transformRect(mSprite.getGlobalBounds());
}
Category::Category Agent::identify() const{
return Category::Agent;
}
void Agent::setType(Type type){
mType = type;
}
#include "../headers/alive.hpp"
Alive::Alive(Agent::Type type, TextureHolder const& textures, int HP)
:Agent(type,textures), mHP(HP), mState(Normal){}
:Entity(type,textures), mHP(HP), mState(Normal){}
void Alive::updateCurrent(sf::Time dt){
if(!isLocked()){
act(dt);
Agent::updateCurrent(dt);
setVelocity(0.f,0.f);
}
hitAnimation(dt);
setType(typeOfState());
Entity::updateCurrent(dt);
setVelocity(0.f,0.f);}
else{
mLockTime -= dt;
if(mLockTime.asSeconds() <= 0.f)
unlock();
hitAnimation(dt);
setType(typeOfState());
Entity::updateCurrent(dt);
}
hitAnimation(dt);
}
void Alive::act(sf::Time dt){
}
void Alive::act(sf::Time dt){}
void Alive::lock(sf::Time dt){
mLock = true;
......@@ -32,29 +33,24 @@ void Alive::unlock(){
}
Agent::Type Alive::typeOfState(){
switch(mState){
case Normal :
return Agent::Player;
case HitA :
return Agent::PlayerHit;
case HitB :
return Agent::Player;
}
return Agent::Player;
}
void Alive::hit(){
if(mState == Normal){ std::cout << mHP-- << '\n';}
if(!mLock) --mHP;
lock(sf::milliseconds(500.f));
if(mHP <= 0) stageForRemoval();
mState = HitA;
mHitCount = 8;
mHitTime = sf::milliseconds(150.f);
hitAnimation(sf::seconds(0.f));
}
void Alive::hitAnimation(sf::Time dt){
std::cout << mState<< '\n';
switch(mState){
case Normal :
setType(Agent::Player);
setTexture();
break;
case HitA : case HitB :
......@@ -70,8 +66,6 @@ void Alive::hitAnimation(sf::Time dt){
}
break;
}
setType(typeOfState());
setTexture();
}
void Alive::moveUp(){
......@@ -86,7 +80,3 @@ void Alive::moveLeft(){
void Alive::moveRight(){
getVelocity() += sf::Vector2f(400.f,0.f);
}
Category::Category Alive::identify() const{
return Category::Alive;
}
......@@ -4,13 +4,13 @@ Ennemy::Ennemy(TextureHolder const& textures) : Alive(Agent::Tower,textures,2),
mQCD = sf::seconds(3.f);
}
Agent::Type Ennemy::typeOfState() const{
Agent::Type Ennemy::typeOfState(){
switch(getState()){
case Normal :
case Alive::Normal :
return Agent::Tower;
case HitA :
case Alive::HitA :
return Agent::PlayerHit;
case HitB :
case Alive::HitB :
return Agent::Tower;
}
}
......
#include <SFML/Graphics.hpp>
#include "../headers/entity.hpp"
Entity::Entity(Agent::Type type, TextureHolder const& textures) : Agent(type,textures) {}
void Entity::setVelocity(sf::Vector2f velocity){
mVelocity = velocity;
}
......@@ -16,4 +18,5 @@ sf::Vector2f& Entity::getVelocity(){
void Entity::updateCurrent(sf::Time dt){
move(mVelocity * dt.asSeconds());
Agent::updateCurrent(dt);
}
#include "../headers/game.hpp"
Game::Game() : mWindow(sf::VideoMode(1920, 1080), "Tests"), mWorld(mWindow){
Game::Game() : mWindow(sf::VideoMode(640, 480), "Tests"), mWorld(mWindow){
TimePerFrame = sf::seconds(1.f/60.f);
}
......
......@@ -2,7 +2,7 @@
#include <iostream>
Orbital::Orbital(Agent::Type type, TextureHolder const& textures, SpeedPatern* spP, bool ally)
: Agent(type,textures), mSpeedPatern(spP), mLifeSpan(sf::seconds(15.f)), mAlly(ally){
: Entity(type,textures), mSpeedPatern(spP), mLifeSpan(sf::seconds(15.f)), mAlly(ally){
}
void Orbital::updateCurrent(sf::Time dt){
......@@ -12,9 +12,5 @@ void Orbital::updateCurrent(sf::Time dt){
}
mSpeedPatern->step(dt);
setVelocity(mSpeedPatern->getVelocity());
Agent::updateCurrent(dt);
}
Category::Category Orbital::identify() const{
return Category::Orbital;
Entity::updateCurrent(dt);
}
#include "../headers/player.hpp"
Player::Player(TextureHolder const& textures) : Alive(Agent::Player,textures,8), mIsQAvailable(true){
Agent::Type Player::typeOfState(){
switch(getState()){
case Alive::Normal :
return Agent::Player;
case Alive::HitA :
return Agent::PlayerHit;
case Alive::HitB :
return Agent::Player;
}
}
Player::Player(TextureHolder const& textures)
: Alive(Agent::Player,textures,8), mIsQAvailable(true), mIsWAvailable(true){
mQCD = sf::seconds(8.f);
mWCD = sf::seconds(3.f);
}
void Player::q_spell(){
if(mIsQAvailable){
mIsQAvailable = false;
std::unique_ptr<Sword> sword(new Sword(getTexHolder()));
attachChild(std::move(sword));
sf::Vector2f positionSetter(75.f,0.f);
sf::Transform transform; transform.rotate(120.f);
for(int i = 0 ; i < 3 ; ++i){
std::unique_ptr<Orbital>
escortR(new Orbital(Agent::qProjectile, getTexHolder(), new RotationSpeedPatern(positionSetter,540.f), true));
escortR->setPosition(positionSetter);
attachChild(std::move(escortR));
positionSetter = transform.transformPoint(positionSetter);
}
}
}
void Player::w_spell(){
if(mIsWAvailable){
mIsWAvailable = false;
// sf::Vector2f positionSetter(75.f,0.f);
// sf::Transform transform; transform.rotate(120.f);
// for(int i = 0 ; i < 3 ; ++i){
// std::unique_ptr<Orbital>
// escortR(new Orbital(Agent::qProjectile,new RotationSpeedPatern(positionSetter,540.f), true));
// escortR->setPosition(positionSetter);
// escortR->setTexture(getTexHolder());
// attachChild(std::move(escortR));
// positionSetter = transform.transformPoint(positionSetter);
// }
std::unique_ptr<Sword> sword(new Sword(getTexHolder()));
attachChild(std::move(sword));
}
}
......@@ -31,6 +50,10 @@ void Player::updateCurrent(sf::Time dt){
if (mQElapse < mQCD) mQElapse += dt;
else {mIsQAvailable = true; mQElapse = sf::Time::Zero;}
}
if(!mIsWAvailable){
if (mWElapse < mWCD) mWElapse += dt;
else {mIsWAvailable = true; mWElapse = sf::Time::Zero;}
}
Alive::updateCurrent(dt);
}
......@@ -46,8 +69,5 @@ void Player::keyBindings(){
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Down)) moveDown();
if(sf::Keyboard::isKeyPressed(sf::Keyboard::A)) q_spell();
}
Category::Category Player::identify() const{
return Category::Player;
if(sf::Keyboard::isKeyPressed(sf::Keyboard::Z)) w_spell();
}
......@@ -2,18 +2,9 @@
SpriteNode::SpriteNode(Agent::Type type, TextureHolder const& textures)
: Agent(type,textures){
getTexture().setRepeated(true);
}
: Agent(type,textures){}
SpriteNode::SpriteNode(Agent::Type type, TextureHolder const& textures, const sf::IntRect& rect)
: Agent(type,textures){
getSprite().setTextureRect(rect);
getTexture().setRepeated(true);
}
SpriteNode::SpriteNode(Type type, const sf::IntRect& rect)
: mType(type), mSprite(){
getSprite.setTextureRect(rect);
}
......@@ -2,7 +2,7 @@
Sword::Sword(TextureHolder const& mTextures)
: Agent(Agent::Sword_0, mTextures), mAnimationTime(sf::milliseconds(150.f)), mIsIncreasing(true){
: Agent(Agent::Sword_1, mTextures), mAnimationTime(sf::milliseconds(150.f)), mIsIncreasing(true){
getSprite().setOrigin(20.f,20.f);
}
......@@ -14,20 +14,20 @@ void Sword::nextType(){
case Agent::Sword_5 :
mIsIncreasing = false;
setType(Agent::Sword_4);
mAnimationTime = sf::milliseconds(500.f);
mAnimationTime = sf::milliseconds(150.f);
break;
default :
setType(static_cast<Agent::Type> (static_cast<int>(getType())+(mIsIncreasing? 1 : -1)));
mAnimationTime = sf::milliseconds(150.f);
break;
}
setTexture();
}
void Sword::updateCurrent(sf::Time dt){
Agent::updateCurrent(dt);
mAnimationTime -= dt;
if(mAnimationTime.asSeconds() <= 0.f)
nextType();
Agent::updateCurrent(dt);
getSprite().setOrigin(20.f,20.f);
}
......@@ -16,7 +16,7 @@ void RessourceHolder<Ressource,Identifier>::load(Identifier id, const std::strin
}
template<typename Ressource, typename Identifier>
Ressource& RessourceHolder<Ressource,Identifier>::get(Identifier id){
const Ressource& RessourceHolder<Ressource,Identifier>::get(Identifier id) const{
auto found = mRessourceMap.find(id);
if(found == mRessourceMap.end()) throw std::logic_error("TextureHolder::get - Failed to get");
......@@ -25,6 +25,7 @@ Ressource& RessourceHolder<Ressource,Identifier>::get(Identifier id){
}
std::string pathOfID(Textures::ID id){
std::string str;
switch(id){
......
......@@ -79,12 +79,13 @@ void World::checkCollision(){
for(auto &pair : stack){
if(pair.first->identify() == Category::Player && pair.second->identify() == Category::Orbital){
static_cast<Player&>(*pair.first).lock(sf::seconds(0.5f));
static_cast<Player&>(*pair.first).hit();
pair.second->stageForRemoval();
}
if(pair.first->identify() == Category::Ennemy && pair.second->identify() == Category::Sword){
static_cast<Player&>(*pair.first).hit();
}
if(pair.first->identify() == Category::Ennemy && pair.second->identify() == Category::Orbital){
static_cast<Player&>(*pair.first).lock(sf::seconds(0.5f));
static_cast<Player&>(*pair.first).hit();
}
if(pair.first->identify() == Category::Orbital && pair.second->identify() == Category::Orbital
......
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