Skip to content

Commit

Permalink
Merge pull request #5 from florianhumblot/develop
Browse files Browse the repository at this point in the history
Develop merge to master
  • Loading branch information
florianhumblot authored Jan 25, 2019
2 parents e287549 + 8add365 commit a4fc5d8
Show file tree
Hide file tree
Showing 442 changed files with 3,836 additions and 20 deletions.
48 changes: 47 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
.vs/
Debug/
x64/
*.vcxproj
*.vcxproj.filters
*.user

# Prerequisites
*.d
Expand Down Expand Up @@ -36,4 +39,47 @@ x64/
*.exe
*.out
*.app

Adam/Adam.vcxproj
Adam/Adam.vcxproj.filters
CMakeLists.txt
cmake-build-debug/Makefile
cmake-build-debug/CMakeFiles/TargetDirectories.txt
cmake-build-debug/CMakeFiles/progress.marks
cmake-build-debug/CMakeFiles/Makefile2
cmake-build-debug/CMakeFiles/Makefile.cmake
cmake-build-debug/CMakeFiles/feature_tests.cxx
cmake-build-debug/CMakeFiles/feature_tests.c
cmake-build-debug/CMakeFiles/feature_tests.bin
cmake-build-debug/CMakeFiles/CMakeOutput.log
cmake-build-debug/CMakeFiles/CMakeDirectoryInformation.cmake
cmake-build-debug/CMakeFiles/cmake.check_cache
cmake-build-debug/CMakeFiles/clion-log.txt
cmake-build-debug/CMakeFiles/clion-environment.txt
cmake-build-debug/CMakeFiles/Adam.dir/progress.make
cmake-build-debug/CMakeFiles/Adam.dir/objects1.rsp
cmake-build-debug/CMakeFiles/Adam.dir/linklibs.rsp
cmake-build-debug/CMakeFiles/Adam.dir/link.txt
cmake-build-debug/CMakeFiles/Adam.dir/includes_CXX.rsp
cmake-build-debug/CMakeFiles/Adam.dir/flags.make
cmake-build-debug/CMakeFiles/Adam.dir/DependInfo.cmake
cmake-build-debug/CMakeFiles/Adam.dir/depend.make
cmake-build-debug/CMakeFiles/Adam.dir/cmake_clean.cmake
cmake-build-debug/CMakeFiles/Adam.dir/build.make
cmake-build-debug/CMakeFiles/3.12.2/CompilerIdCXX/CMakeCXXCompilerId.cpp
cmake-build-debug/CMakeFiles/3.12.2/CompilerIdC/CMakeCCompilerId.c
cmake-build-debug/CMakeFiles/3.12.2/CMakeSystem.cmake
cmake-build-debug/CMakeFiles/3.12.2/CMakeRCCompiler.cmake
cmake-build-debug/CMakeFiles/3.12.2/CMakeDetermineCompilerABI_CXX.bin
cmake-build-debug/CMakeFiles/3.12.2/CMakeDetermineCompilerABI_C.bin
cmake-build-debug/CMakeFiles/3.12.2/CMakeCXXCompiler.cmake
cmake-build-debug/CMakeFiles/3.12.2/CMakeCCompiler.cmake
cmake-build-debug/CMakeCache.txt
cmake-build-debug/cmake_install.cmake
cmake-build-debug/Adam.cbp
cmake-build-debug/CMakeFiles/Adam.dir/CXX.includecache
cmake-build-debug/CMakeFiles/Adam.dir/depend.internal
cmake-build-debug/CMakeFiles/Progress/1
cmake-build-debug/CMakeFiles/Progress/2
cmake-build-debug/CMakeFiles/Progress/3
cmake-build-debug/CMakeFiles/Progress/4
cmake-build-debug/CMakeFiles/Progress/count.txt
9 changes: 3 additions & 6 deletions Adam.sln
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.28010.2041
Expand All @@ -15,17 +14,15 @@ Global
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{09BC51D3-F562-4978-B5E7-67120379C21F}.Debug|x64.ActiveCfg = Debug|x64
{09BC51D3-F562-4978-B5E7-67120379C21F}.Debug|x64.Build.0 = Debug|x64
{09BC51D3-F562-4978-B5E7-67120379C21F}.Debug|x86.ActiveCfg = Debug|Win32
{09BC51D3-F562-4978-B5E7-67120379C21F}.Debug|x86.Build.0 = Debug|Win32
{09BC51D3-F562-4978-B5E7-67120379C21F}.Debug|x86.ActiveCfg = Debug|x64
{09BC51D3-F562-4978-B5E7-67120379C21F}.Release|x64.ActiveCfg = Release|x64
{09BC51D3-F562-4978-B5E7-67120379C21F}.Release|x64.Build.0 = Release|x64
{09BC51D3-F562-4978-B5E7-67120379C21F}.Release|x86.ActiveCfg = Release|Win32
{09BC51D3-F562-4978-B5E7-67120379C21F}.Release|x86.Build.0 = Release|Win32
{09BC51D3-F562-4978-B5E7-67120379C21F}.Release|x86.ActiveCfg = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {29189A62-F05C-4CDF-9A6A-D8848D2DE15B}
EndGlobalSection
EndGlobal
EndGlobal
90 changes: 90 additions & 0 deletions Adam/AI.cpp
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;
}


}
18 changes: 18 additions & 0 deletions Adam/AI.hpp
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);

};
38 changes: 38 additions & 0 deletions Adam/Animated.cpp
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;
}
24 changes: 24 additions & 0 deletions Adam/Animated.hpp
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(); }
};

62 changes: 62 additions & 0 deletions Adam/Animation.cpp
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;
}
34 changes: 34 additions & 0 deletions Adam/Animation.h
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);
};

Loading

0 comments on commit a4fc5d8

Please sign in to comment.