Maintenance électrique le 12 août, nos services, et y compris Gitlab, seront fortement impactés autour de cette date. Retour à un état normal prévu dans le milieu de la semaine prochaine.

Commit 465b8fb2 authored by pa's avatar pa

Added animations a bit more cleanly

parent d019fb25
#pragma once
#include <SFML/Graphics.hpp>
#include "orbital.hpp"
#include "agent.hpp"
#include "category.hpp"
class Alive : public Agent{
public :
Alive(TextureHolder& Textures, int HP);
enum State{
Normal, HitA, HitB
};
virtual Agent::Type typeOfState();
State getState() const{return mState;}
virtual void act(sf::Time dt);
void moveUp();
void moveLeft();
void moveRight();
void moveDown();
void lock(sf::Time dt);
void unlock();
bool isLocked() const {return mLock;}
void hit();
void hitAnimation(sf::Time dt);
virtual void updateCurrent(sf::Time dt);
void keyBindings();
virtual Category::Category identify() const;
TextureHolder& getTexHolder(){
return mTextures;
}
private :
State mState;
int mHP;
int mHitCount;
sf::Time mHitTime;
bool mLock;
sf::Time mLockTime;
bool mIsQAvailable;
sf::Time mQCD, mQElapse;
TextureHolder& mTextures;
};
......@@ -2,6 +2,6 @@
namespace Category{
enum Category{
SceneNode, SpriteNode, Entity, Agent, Player, Ennemy, Orbital
SceneNode, SpriteNode, Entity, Agent, Alive, Player, Ennemy, Orbital
};
}
......@@ -2,24 +2,24 @@
#include <SFML/Graphics.hpp>
#include "orbital.hpp"
#include "agent.hpp"
#include "alive.hpp"
#include "category.hpp"
class Ennemy : public Agent{
class Ennemy : public Alive{
public :
Ennemy(TextureHolder& Textures);
virtual Agent::Type typeOfState() const;
void q_spell(float sense);
virtual void updateCurrent(sf::Time dt);
virtual void act(sf::Time dt);
virtual Category::Category identify() const;
private :
bool mIsQ,mIsW;
sf::Time mQCD, mQElapse;
TextureHolder& mTextures;
};
......@@ -8,12 +8,15 @@
class Orbital : public Agent{
public :
Orbital(Agent::Type type , SpeedPatern* spP);
Orbital(Agent::Type type , SpeedPatern* spP, bool ally);
virtual void updateCurrent(sf::Time dt);
virtual Category::Category identify() const;
virtual bool getOwner() const{ return mAlly; }
private :
bool mAlly;
SpeedPatern* mSpeedPatern;
sf::Time mLifeSpan;
};
......@@ -2,44 +2,25 @@
#include <SFML/Graphics.hpp>
#include "orbital.hpp"
#include "agent.hpp"
#include "alive.hpp"
#include "category.hpp"
class Player : public Agent{
class Player : public Alive{
public :
Player(TextureHolder& Textures);
void lock();
void q_spell();
void moveUp();
void moveLeft();
void moveRight();
void moveDown();
void lock(sf::Time dt);
void unlock();
bool isLocked() const {return mLock;}
void hit(){ mIsHit = true; mHitCount = 8;}
virtual void updateCurrent(sf::Time dt);
virtual void act(sf::Time dt);
void keyBindings();
virtual Category::Category identify() const;
private :
bool mIsHit; int mHitCount;
sf::Time mHitTime;
bool mLock;
sf::Time mLockTime;
bool mIsQAvailable;
sf::Time mQCD, mQElapse;
TextureHolder& mTextures;
};
res/tower.png

6.66 KB | W: | H:

res/tower.png

181 Bytes | W: | H:

res/tower.png
res/tower.png
res/tower.png
res/tower.png
  • 2-up
  • Swipe
  • Onion skin
#include "../headers/alive.hpp"
Alive::Alive(TextureHolder& textures, int HP) : Agent(Agent::Player), mTextures(textures), mHP(HP),
mState(Normal){
setTexture(mTextures);
}
void Alive::updateCurrent(sf::Time dt){
if(!isLocked()){
act(dt);
Agent::updateCurrent(dt);
setVelocity(0.f,0.f);
}
else{
mLockTime -= dt;
if(mLockTime.asSeconds() <= 0.f)
unlock();
}
hitAnimation(dt);
}
void Alive::act(sf::Time dt){
}
void Alive::lock(sf::Time dt){
mLock = true;
mLockTime = dt;
}
void Alive::unlock(){
mLock = false;
}
Agent::Type Alive::typeOfState(){
switch(mState){
case Normal :
return Agent::Player;
case HitA :
return Agent::PlayerHit;
case HitB :
return Agent::Player;
}
}
void Alive::hit(){
if(mState == Normal){ std::cout << mHP-- << '\n';}
if(mHP <= 0) stageForRemoval();
mState = HitA;
mHitCount = 8;
mHitTime = sf::milliseconds(150.f);
}
void Alive::hitAnimation(sf::Time dt){
switch(mState){
case Normal :
setType(Agent::Player);
setTexture(mTextures);
break;
case HitA : case HitB :
mHitTime -= dt;
if(mHitTime.asSeconds() <= 0.f){
mHitCount--;
mHitTime = sf::milliseconds(100.f);
if(mHitCount == 0) mState = Normal;
else{
if(mState == HitA) mState = HitB;
else mState = HitA;
}
}
break;
}
setType(typeOfState());
setTexture(mTextures);
}
void Alive::moveUp(){
getVelocity() += sf::Vector2f(0.f,-400.f);
}
void Alive::moveDown(){
getVelocity() += sf::Vector2f(0.f,400.f);
}
void Alive::moveLeft(){
getVelocity() += sf::Vector2f(-400.f,0.f);
}
void Alive::moveRight(){
getVelocity() += sf::Vector2f(400.f,0.f);
}
Category::Category Alive::identify() const{
return Category::Alive;
}
#include "../headers/ennemy.hpp"
Ennemy::Ennemy(TextureHolder& textures) : Agent(Agent::Tower), mTextures(textures), mIsQ(true), mIsW(true){
setTexture(mTextures);
mQCD = sf::seconds(1.f);
Ennemy::Ennemy(TextureHolder& textures) : Alive(textures,2), mIsQ(true), mIsW(true){
mQCD = sf::seconds(3.f);
}
Agent::Type Ennemy::typeOfState() const{
switch(getState()){
case Normal :
return Agent::Tower;
case HitA :
return Agent::PlayerHit;
case HitB :
return Agent::Tower;
}
}
void Ennemy::q_spell(float sense){
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::tProjectile,new HellSpeedPatern(positionSetter,sense*49.f,1.007f)));
escortR(new Orbital(Agent::tProjectile,new HellSpeedPatern(positionSetter,sense*49.f,1.007f),false));
escortR->setPosition(positionSetter);
escortR->setTexture(mTextures);
escortR->setTexture(getTexHolder());
attachChild(std::move(escortR));
positionSetter = transform.transformPoint(positionSetter);
}
......@@ -21,6 +32,11 @@ void Ennemy::q_spell(float sense){
void Ennemy::updateCurrent(sf::Time dt){
// Q-SPELL
Alive::updateCurrent(dt);
setVelocity(0.f,0.f);
}
void Ennemy::act(sf::Time dt){
if(!mIsQ){
if (mQElapse < mQCD) mQElapse += dt;
else {mIsQ = true; mIsW = true; mQElapse = sf::Time::Zero;}
......@@ -31,9 +47,6 @@ void Ennemy::updateCurrent(sf::Time dt){
mIsQ = false;
q_spell(1.f);
}
Agent::updateCurrent(dt);
setVelocity(0.f,0.f);
}
......
#include "../headers/orbital.hpp"
#include <iostream>
Orbital::Orbital(Agent::Type type, SpeedPatern* spP)
: Agent(type), mSpeedPatern(spP), mLifeSpan(sf::seconds(15.f)){
Orbital::Orbital(Agent::Type type, SpeedPatern* spP, bool ally)
: Agent(type), mSpeedPatern(spP), mLifeSpan(sf::seconds(15.f)), mAlly(ally){
}
void Orbital::updateCurrent(sf::Time dt){
......
#include "../headers/player.hpp"
Player::Player(TextureHolder& textures) : Agent(Agent::Player), mTextures(textures), mIsQAvailable(true), mIsHit(false){
setTexture(mTextures);
Player::Player(TextureHolder& textures) : Alive(textures,8), mIsQAvailable(true){
mQCD = sf::seconds(8.f);
}
......@@ -13,17 +12,15 @@ void Player::q_spell(){
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)));
escortR(new Orbital(Agent::qProjectile,new RotationSpeedPatern(positionSetter,540.f), true));
escortR->setPosition(positionSetter);
escortR->setTexture(mTextures);
escortR->setTexture(getTexHolder());
attachChild(std::move(escortR));
positionSetter = transform.transformPoint(positionSetter);
}
}
}
void Player::updateCurrent(sf::Time dt){
// Q-SPELL
if(!mIsQAvailable){
......@@ -31,50 +28,13 @@ void Player::updateCurrent(sf::Time dt){
else {mIsQAvailable = true; mQElapse = sf::Time::Zero;}
}
if(!isLocked()){
keyBindings();
Agent::updateCurrent(dt);
setVelocity(0.f,0.f);
}
else{
mLockTime -= dt;
if(mLockTime.asSeconds() <= 0.f)
unlock();
}
if(mIsHit){
mHitTime -= dt;
if(mHitTime.asSeconds() <= 0.f){
mHitCount--;
if(mHitCount < 0){
mIsHit = false;
setType(Agent::Player);
setTexture(mTextures);
}
else if(mHitCount % 2 == 1){
mHitTime = sf::milliseconds(100.f);
setType(Agent::PlayerHit);
setTexture(mTextures);
}
else if(mHitCount % 2 == 0){
mHitTime = sf::milliseconds(100.f);
setType(Agent::Player);
setTexture(mTextures);
}
}
}
}
void Player::lock(sf::Time dt){
mLock = true;
mLockTime = dt;
Alive::updateCurrent(dt);
}
void Player::unlock(){
mLock = false;
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();
......@@ -84,20 +44,6 @@ void Player::keyBindings(){
if(sf::Keyboard::isKeyPressed(sf::Keyboard::A)) q_spell();
}
void Player::moveUp(){
getVelocity() += sf::Vector2f(0.f,-400.f);
}
void Player::moveDown(){
getVelocity() += sf::Vector2f(0.f,400.f);
}
void Player::moveLeft(){
getVelocity() += sf::Vector2f(-400.f,0.f);
}
void Player::moveRight(){
getVelocity() += sf::Vector2f(400.f,0.f);
}
Category::Category Player::identify() const{
return Category::Player;
}
......@@ -70,8 +70,12 @@ bool SceneNode::collidesWith(SceneNode& node) const{
}
void SceneNode::checkNodeCollision(SceneNode& node, std::set<Pair>& target){
if(this != &node && collidesWith(node))
target.insert(std::minmax(this,&node));
if(this != &node && collidesWith(node)){
if(static_cast<int>(node.identify()) < static_cast<int>(identify()))
target.insert(std::make_pair(&node,this));
else
target.insert(std::make_pair(this,&node));
}
for(auto &child : mChildren)
child->checkNodeCollision(node,target);
}
......
......@@ -12,8 +12,6 @@ World::World(sf::RenderWindow& window)
loadTextures();
buildScene();
//mWorldView.setCenter(mSpawnPosition);
}
void World::loadTextures(){
......@@ -77,10 +75,15 @@ void World::checkCollision(){
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::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::Player){
static_cast<Player&>(*pair.second).lock(sf::seconds(0.5f));
static_cast<Player&>(*pair.second).hit();
if(pair.first->identify() == Category::Orbital && pair.second->identify() == Category::Orbital
&& static_cast<Orbital&>(*pair.first).getOwner() != static_cast<Orbital&>(*pair.second).getOwner()){
pair.first->stageForRemoval(); pair.second->stageForRemoval();
}
}
}
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