-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from florianhumblot/develop
Develop merge to master
- Loading branch information
Showing
442 changed files
with
3,836 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
#include "pch.h" | ||
#include "AI.hpp" | ||
|
||
|
||
void AI::shouldFollow_followDirection(Enemy * p1, Character * p2) { | ||
|
||
//Check if p1 and p2 are close to each other | ||
// if so, make enemy move towarts the player | ||
if ((p1->getPosition() - p2->getPosition()).x <= 200 && (p1->getPosition() - p2->getPosition()).x > 10) { | ||
if (p1->currentAnimation.isDone() || p1->getCurrentAnimation() == std::string("WALKright")) { | ||
if (!p1->fight(p2)) { | ||
if (p1->getCurrentAnimation() != "WALKright") { | ||
p1->setAnimation("WALKright", Animation::intervals::walk); | ||
p1->setTexture(p1->currentAnimation.nextFrame()); | ||
} | ||
|
||
p1->updateFollowPosition(-1); | ||
} | ||
|
||
p1->setScale(sf::Vector2f(-0.2, 0.2)); | ||
} | ||
|
||
return; | ||
} | ||
else if ((p1->getPosition() - p2->getPosition()).x >= -200 && (p1->getPosition() - p2->getPosition()).x < 10) { | ||
if (p1->currentAnimation.isDone() || p1->getCurrentAnimation() == std::string("WALKright")) { | ||
if (!p1->fight(p2)) { | ||
if (p1->getCurrentAnimation() != "WALKright") { | ||
p1->setAnimation("WALKright", Animation::intervals::walk); | ||
p1->setTexture(p1->currentAnimation.nextFrame()); | ||
} | ||
|
||
p1->updateFollowPosition(1); | ||
} | ||
p1->setScale(sf::Vector2f(0.2, 0.2)); | ||
} | ||
|
||
return; | ||
} | ||
else { | ||
// if they are not close to eachother | ||
// make sure the enemy's velocity is zero | ||
if (p1->getCurrentAnimation() != std::string("IDLEright")) { | ||
p1->setAnimation("IDLEright", Animation::intervals::idle); | ||
p1->setTexture(p1->currentAnimation.nextFrame()); | ||
p1->updateFollowPosition(0); | ||
} | ||
|
||
} | ||
|
||
} | ||
|
||
void AI::walkRandomly(npc * p1) { | ||
p1->updateState(); | ||
int dir = p1->getDirection(); | ||
|
||
if (p1->isWalking()) { | ||
if (p1->getCurrentAnimation() != "WALKright") { | ||
p1->setAnimation("WALKright", Animation::intervals::walk); | ||
p1->setTexture(p1->currentAnimation.nextFrame()); | ||
|
||
} | ||
if (p1->originPosition.x - p1->getPosition().x > 100) { | ||
p1->setScale(sf::Vector2f(0.2, 0.2)); | ||
p1->current_direction = movable::direction::RIGHT; | ||
|
||
} else if (p1->originPosition.x - p1->getPosition().x < -100) { | ||
p1->setScale(sf::Vector2f(-0.2, 0.2)); | ||
p1->current_direction = movable::direction::LEFT; | ||
|
||
} | ||
|
||
if (p1->getVelocity().x == 0 && p1->lastDirection != 0) { | ||
p1->walkTheOtherWay(); | ||
p1->setVelocity(sf::Vector2f(0, -9)); | ||
} p1->setVelocity(sf::Vector2f(dir, p1->getVelocity().y)); | ||
p1->lastDirection = 1; | ||
|
||
} | ||
else { | ||
if (p1->getCurrentAnimation() != "IDLEright") { | ||
p1->setAnimation("IDLEright", Animation::intervals::idle); | ||
p1->setTexture(p1->currentAnimation.nextFrame()); | ||
} | ||
p1->setVelocity(sf::Vector2f(0,p1->getVelocity().y)); | ||
p1->lastDirection = 0; | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#pragma once | ||
#include "Movable.h" | ||
#include "Enemy.hpp" | ||
#include "npc.hpp" | ||
#include "Character.h" | ||
|
||
|
||
class AI { | ||
|
||
public: | ||
AI() { | ||
|
||
} | ||
|
||
void shouldFollow_followDirection(Enemy * p1, Character * p2); | ||
void walkRandomly(npc * p1); | ||
|
||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
#include "pch.h" | ||
#include "Animated.hpp" | ||
|
||
Animateable::Animateable(std::map<std::string, Animation> & animations): | ||
animations(animations) | ||
{ | ||
currentAnimation = animations.begin()->second; | ||
} | ||
|
||
Animation Animateable::getAnimation(std::string animation) { | ||
return animations[animation]; | ||
} | ||
|
||
bool Animateable::updateAnimation() | ||
{ | ||
if (timer.getElapsedTime().asMilliseconds() > animation_interval) | ||
{ | ||
currentAnimation.nextFrame(); | ||
timer.restart(); | ||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
std::string Animateable::getCurrentAnimation() { | ||
return currentAnimation.name; | ||
} | ||
|
||
void Animateable::setAnimation(std::string animation, int interval) { | ||
animation_interval = interval; | ||
currentAnimation = animations[animation]; | ||
} | ||
|
||
void Animateable::setAnimationMap(std::map<std::string, Animation> newAnimations) | ||
{ | ||
animations = newAnimations; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#pragma once | ||
#include "pch.h" | ||
#include "Animation.h" | ||
class Animateable { | ||
protected: | ||
std::map<std::string, Animation> animations; | ||
public: | ||
Animation currentAnimation; | ||
int animation_interval = 0; | ||
sf::Clock timer; | ||
|
||
void setAnimation(std::string animation, int interval); | ||
void setAnimationMap(std::map<std::string, Animation> newAnimations); | ||
|
||
Animateable() {} | ||
~Animateable() {} | ||
Animateable(std::map<std::string, Animation> & animations); | ||
|
||
Animation getAnimation(std::string animation); | ||
std::string getCurrentAnimation(); | ||
bool updateAnimation(); | ||
bool currentAnimationIsDone() { return currentAnimation.isDone(); } | ||
}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#include "pch.h" | ||
#include "Animation.h" | ||
#include <iostream> | ||
Animation::~Animation() | ||
{ | ||
} | ||
|
||
void Animation::addFrame(const std::string & location) | ||
{ | ||
sf::Texture t; | ||
textures.emplace_back(t); | ||
Collision::CreateTextureAndBitmask(textures.back(), location); | ||
} | ||
|
||
void Animation::addFrame(sf::Texture & texture) | ||
{ | ||
textures.emplace_back(texture); | ||
} | ||
|
||
sf::Texture & Animation::nextFrame() | ||
{ | ||
if (current_frame == textures.size() -1) { | ||
current_frame = -1; | ||
animation_done = true; | ||
} | ||
if (animation_done && name == "DYINGright") { | ||
return textures.back(); | ||
} | ||
return textures[++current_frame]; | ||
} | ||
|
||
sf::Texture & Animation::getCurrentFrame() | ||
{ | ||
if (current_frame == textures.size()) { | ||
return textures.back(); | ||
} | ||
else { | ||
return textures[(current_frame == -1 ) ? 0 : current_frame]; | ||
} | ||
} | ||
|
||
|
||
void Animation::reset_animation() | ||
{ | ||
animation_done = false; | ||
current_frame = -1; | ||
} | ||
void Animation::print() { | ||
std::cout << name << " "; | ||
} | ||
|
||
bool Animation::operator==(Animation &rhs) { | ||
return this->name == rhs.name; | ||
} | ||
|
||
bool Animation::operator!=(Animation &rhs) { | ||
return this->name != rhs.name; | ||
} | ||
|
||
bool Animation::operator!=(Animation rhs) { | ||
return this->name != rhs.name; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#pragma once | ||
#include "Collision.h" | ||
class Animation | ||
{ | ||
private: | ||
bool animation_done; | ||
int current_frame; | ||
public: | ||
|
||
enum intervals | ||
{ | ||
idle = 50, | ||
walk = 10, | ||
attack = 50, | ||
dying = 50, | ||
}; | ||
|
||
std::string name = "default"; | ||
std::vector<sf::Texture> textures; | ||
Animation() :animation_done(false), current_frame(0), textures() {}; | ||
Animation(std::string name) :name(name), animation_done(false), current_frame(0), textures() {}; | ||
~Animation(); | ||
void addFrame(const std::string & location); | ||
void addFrame(sf::Texture & texture); | ||
sf::Texture & nextFrame(); | ||
sf::Texture & getCurrentFrame(); | ||
void reset_animation(); | ||
bool isDone() { return animation_done; } | ||
void print(); | ||
bool operator==(Animation & rhs); | ||
bool operator!=(Animation & rhs); | ||
bool operator!=(Animation rhs); | ||
}; | ||
|
Oops, something went wrong.