Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
a35ca7c
create Hero 2.0
Mirong1707 May 14, 2022
b36e8f9
set animations in statemachine
Mirong1707 May 14, 2022
d9bd2dc
set animations in statemachine
Mirong1707 May 15, 2022
c93a178
?
Mirong1707 May 15, 2022
442ccf5
create Hero 2.0
Mirong1707 May 14, 2022
5859a71
set animations in statemachine
Mirong1707 May 14, 2022
c97f35c
set animations in statemachine
Mirong1707 May 15, 2022
aa62dd7
Merge remote-tracking branch 'origin/105-program-player-and-enemy-beh…
Mirong1707 May 15, 2022
053a755
create Hero 2.0
Mirong1707 May 14, 2022
6ddb7fb
set animations in statemachine
Mirong1707 May 14, 2022
b9f34fa
set animations in statemachine
Mirong1707 May 15, 2022
9437242
create Hero 2.0
Mirong1707 May 14, 2022
773fbda
set animations in statemachine
Mirong1707 May 14, 2022
4aeac70
set animations in statemachine
Mirong1707 May 15, 2022
3bfd4a6
Merge branch '105-program-player-and-enemy-behaviour' of github.com:P…
Mirong1707 May 15, 2022
42a92ea
?
Mirong1707 May 15, 2022
9492389
create Hero 2.0
Mirong1707 May 14, 2022
6def163
set animations in statemachine
Mirong1707 May 14, 2022
c5bcc88
set animations in statemachine
Mirong1707 May 15, 2022
beefc83
create Hero 2.0
Mirong1707 May 14, 2022
dbb1e76
set animations in statemachine
Mirong1707 May 14, 2022
863ee18
set animations in statemachine
Mirong1707 May 15, 2022
8d5043b
create Hero 2.0
Mirong1707 May 14, 2022
c5ed894
set animations in statemachine
Mirong1707 May 14, 2022
b84ebde
set animations in statemachine
Mirong1707 May 15, 2022
6774b46
create Hero 2.0
Mirong1707 May 14, 2022
5e96958
set animations in statemachine
Mirong1707 May 14, 2022
32ecd06
set animations in statemachine
Mirong1707 May 15, 2022
3860f6a
?
Mirong1707 May 15, 2022
dfe2057
Merge branch '105-program-player-and-enemy-behaviour' of github.com:P…
Mirong1707 May 15, 2022
150ae15
Merge remote-tracking branch 'origin/main' into 105-program-player-an…
Mirong1707 May 15, 2022
699b2cb
?
Mirong1707 May 15, 2022
1d865f8
Merge remote-tracking branch 'origin/main' into 105-program-player-an…
Mirong1707 May 15, 2022
ff6b66d
merge main
Mirong1707 May 16, 2022
7ba72f6
set normal jump animations
Mirong1707 May 16, 2022
9a8c217
set normal jump animations
Mirong1707 May 16, 2022
9ea4554
debug
Mirong1707 May 17, 2022
7f893c0
add sensor to physicalEntity
Mirong1707 May 17, 2022
6df869f
finish jump state
Mirong1707 May 17, 2022
6b09d92
merge main
Mirong1707 May 22, 2022
dba4e72
merge main
Mirong1707 May 22, 2022
6fc2b69
add animations
Mirong1707 May 22, 2022
c7f7f64
add animations
Mirong1707 May 22, 2022
df599e4
add animations
Mirong1707 May 22, 2022
e91c0bb
Merge remote-tracking branch 'origin/main' into 105-program-player-an…
Mirong1707 May 22, 2022
34b7507
find bug in anim
Mirong1707 May 22, 2022
458519d
add debug
Mirong1707 May 23, 2022
b63a238
multiple conditions in one transaction
Mirong1707 May 23, 2022
94aee0c
multiple conditions in one transaction + add fall without jump
Mirong1707 May 23, 2022
6624759
make HeroStateMachine
Mirong1707 May 29, 2022
b25cacd
add slime files
Mirong1707 Jun 1, 2022
f07ef06
merge main
Mirong1707 Jun 1, 2022
0b95b65
merge main
Mirong1707 Jun 1, 2022
f2a3d80
merge main
Mirong1707 Jun 1, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ set(
event/management/condition/KeyDownCondition.hpp event/management/condition/KeyDownCondition.cpp
event/management/condition/TimerCondition.hpp event/management/condition/TimerCondition.cpp
event/management/condition/CollisionCondition.hpp event/management/condition/CollisionCondition.cpp
event/WorldUpdate.hpp event/WorldUpdate.cpp)
event/WorldUpdate.hpp event/WorldUpdate.cpp ../game/mobs/hero/Hero.hpp ../game/mobs/hero/Hero.cpp event/management/condition/KeyReleasedCondition.hpp event/management/condition/KeyReleasedCondition.cpp event/management/controller/JumpImpulse.hpp event/management/controller/JumpImpulse.cpp event/management/condition/LastStateCondition.hpp event/management/condition/LastStateCondition.cpp event/management/controller/Movement.hpp event/management/controller/Movement.cpp event/management/controller/StartJump.hpp event/management/controller/StartJump.cpp event/management/controller/FlyUp.hpp event/management/controller/FlyUp.cpp event/management/controller/Fall.hpp event/management/controller/Fall.cpp event/management/controller/GroundMovement.hpp event/management/controller/GroundMovement.cpp event/management/condition/EndAnimationCondition.hpp event/management/condition/EndAnimationCondition.cpp event/management/condition/FallCondition.hpp event/management/condition/FallCondition.cpp event/physics/SensorCollision.hpp event/physics/SensorCollision.cpp event/management/condition/SensorCondition.hpp event/management/condition/SensorCondition.cpp event/management/controller/Attack.cpp event/management/controller/Attack.hpp event/physics/SensorCollisionEnd.hpp event/physics/SensorCollisionEnd.cpp event/management/condition/SensorEndCondition.hpp event/management/condition/SensorEndCondition.cpp event/management/controller/statemachine/HeroStateMachine.hpp event/management/controller/statemachine/HeroStateMachine.cpp)

add_library(
${LIBRARY_CORE} STATIC
Expand Down
4 changes: 3 additions & 1 deletion core/event/Event.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ namespace mad::core {
LevelPause,
Runner,
WorldUpdate,
EndOfRenderAction
EndOfRenderAction,
SensorCollision,
SensorCollisionEnd,
};

explicit Event(Type new_type);
Expand Down
2 changes: 2 additions & 0 deletions core/event/management/condition/Condition.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ namespace mad::core {
virtual void on_start() = 0;

virtual ~Condition() = default;

bool triggered;
};

}
Expand Down
21 changes: 21 additions & 0 deletions core/event/management/condition/EndAnimationCondition.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include "EndAnimationCondition.hpp"
#include "common/Cast.hpp"
#include "spdlog/spdlog.h"
#include <event/action/EndOfRenderAction.hpp>
mad::core::EndAnimationCondition::EndAnimationCondition(Entity::Id m_entity_id, ImageStorage::TypeAction m_type_action, int *stage) : m_entity_id(m_entity_id), m_type_action(m_type_action), stage(stage){
}
bool mad::core::EndAnimationCondition::is_triggered_by(const mad::core::Event &event) {
auto e = const_cast_to<EndOfRenderAction>(event);
if(m_entity_id == e.get_entity_id() && m_type_action == e.get_type_action()){
(*stage)++;
//SPDLOG_DEBUG("current attack_stage {}", *stage);
}
//SPDLOG_DEBUG("current attack_stage {}", *stage);
return m_entity_id == e.get_entity_id() && m_type_action == e.get_type_action();
}
std::unordered_set<mad::core::Event::Type> mad::core::EndAnimationCondition::triggers() {
return {mad::core::Event::Type::EndOfRenderAction};
}
void mad::core::EndAnimationCondition::on_start() {

}
22 changes: 22 additions & 0 deletions core/event/management/condition/EndAnimationCondition.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#ifndef MAD_ENDANIMATIONCONDITION_HPP
#define MAD_ENDANIMATIONCONDITION_HPP

#include "Condition.hpp"
#include "visual/image/storage/ImageStorage.hpp"
#include "world/entity/Entity.hpp"
namespace mad::core {
struct EndAnimationCondition : Condition {
public:
explicit EndAnimationCondition(Entity::Id m_entity_id, ImageStorage::TypeAction m_type_action, int *stage = new int(0));
bool is_triggered_by(const mad::core::Event &event) override;
std::unordered_set<Event::Type> triggers() override;
void on_start() override;

private:
Entity::Id m_entity_id;
ImageStorage::TypeAction m_type_action;
int* stage;
};
}// namespace mad::core

#endif//MAD_ENDANIMATIONCONDITION_HPP
15 changes: 15 additions & 0 deletions core/event/management/condition/FallCondition.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include "FallCondition.hpp"



bool mad::core::FallCondition::is_triggered_by(const mad::core::Event &event) {
return m_entity->get_linear_velocity().get_y() >= vel;
}
std::unordered_set<mad::core::Event::Type> mad::core::FallCondition::triggers() {
return {mad::core::Event::Type::WorldUpdate};
}
void mad::core::FallCondition::on_start() {
}
mad::core::FallCondition::FallCondition(std::shared_ptr<mad::core::LocalWorld> world, mad::core::Entity::Id entity_id, float vel) : m_world(world), m_entity_id(entity_id), vel(vel) {
m_entity = cast_to_or_null<PhysicalEntity>(m_world->get_storage().get_entity(m_entity_id));
}
25 changes: 25 additions & 0 deletions core/event/management/condition/FallCondition.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#ifndef MAD_FALLCONDITION_HPP
#define MAD_FALLCONDITION_HPP

#include "Condition.hpp"
#include "visual/image/storage/ImageStorage.hpp"
#include "world/LocalWorld.hpp"
#include "world/entity/Entity.hpp"
#include "world/entity/PhysicalEntity.hpp"
namespace mad::core {
struct FallCondition : Condition {
public:
explicit FallCondition(std::shared_ptr<mad::core::LocalWorld> world, Entity::Id entity_id, float vel);
bool is_triggered_by(const mad::core::Event &event) override;
std::unordered_set<Event::Type> triggers() override;
void on_start() override;

private:
std::shared_ptr<mad::core::LocalWorld> m_world;
Entity::Id m_entity_id;
PhysicalEntity *m_entity;
float vel;
};
}// namespace mad::core

#endif//MAD_FALLCONDITION_HPP
15 changes: 15 additions & 0 deletions core/event/management/condition/KeyReleasedCondition.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include "KeyReleasedCondition.hpp"
#include <common/Cast.hpp>
#include <event/system/KeyReleased.hpp>
std::unordered_set<mad::core::Event::Type> mad::core::KeyReleasedCondition::triggers() {
return {mad::core::Event::Type::KeyReleased};
}
bool mad::core::KeyReleasedCondition::is_triggered_by(const mad::core::Event &event) {
const auto &keystroke = const_cast_to<KeyReleased>(event);
return keystroke.key_id == m_key_id;
}

mad::core::KeyReleasedCondition::KeyReleasedCondition(const int m_key_id) : m_key_id(m_key_id){
}
void mad::core::KeyReleasedCondition::on_start() {
}
18 changes: 18 additions & 0 deletions core/event/management/condition/KeyReleasedCondition.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#ifndef MAD_KEYRELEASEDCONDITION_HPP
#define MAD_KEYRELEASEDCONDITION_HPP

#include "Condition.hpp"
namespace mad::core {
struct KeyReleasedCondition : Condition {
public:
explicit KeyReleasedCondition(int m_key_id);
bool is_triggered_by(const mad::core::Event &event) override;
std::unordered_set<Event::Type> triggers() override;
void on_start() override;

private:
const int m_key_id;
};
}// namespace mad::core

#endif//MAD_KEYRELEASEDCONDITION_HPP
13 changes: 13 additions & 0 deletions core/event/management/condition/LastStateCondition.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include "LastStateCondition.hpp"

bool mad::core::LastStateCondition::is_triggered_by(const mad::core::Event &event) {
return m_to_state_id == m_machine->get_previous_state_id();
}
std::unordered_set<mad::core::Event::Type> mad::core::LastStateCondition::triggers() {
return {mad::core::Event::Type::KeyPressed, mad::core::Event::Type::Collision, mad::core::Event::Type::KeyHeld, mad::core::Event::Type::KeyReleased, mad::core::Event::Type::LevelPause, mad::core::Event::Type::Menu, mad::core::Event::Type::Movement, mad::core::Event::Type::Runner, mad::core::Event::Type::Visual, mad::core::Event::Type::WindowClose};
}
void mad::core::LastStateCondition::on_start() {
}
mad::core::LastStateCondition::LastStateCondition(std::shared_ptr<StateMachine> m_machine, mad::core::StateMachine::StateId m_to_state_id) : m_machine(m_machine), m_to_state_id(m_to_state_id){

}
20 changes: 20 additions & 0 deletions core/event/management/condition/LastStateCondition.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#ifndef MAD_LASTSTATECONDITION_HPP
#define MAD_LASTSTATECONDITION_HPP

#include "Condition.hpp"
#include "event/management/controller/statemachine/StateMachine.hpp"
namespace mad::core {
struct LastStateCondition : Condition {
public:
LastStateCondition(std::shared_ptr<StateMachine> m_machine, StateMachine::StateId m_to_state_id);
bool is_triggered_by(const mad::core::Event &event) override;
std::unordered_set<Event::Type> triggers() override;
void on_start() override;

private:
std::shared_ptr<StateMachine> m_machine;
StateMachine::StateId m_to_state_id;
};
}// namespace mad::core

#endif//MAD_LASTSTATECONDITION_HPP
14 changes: 14 additions & 0 deletions core/event/management/condition/SensorCondition.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include "SensorCondition.hpp"
#include "common/Cast.hpp"
#include "event/physics/SensorCollision.hpp"
mad::core::SensorCondition::SensorCondition(Entity::Id m_entity_id) : m_entity_id(m_entity_id){
}
bool mad::core::SensorCondition::is_triggered_by(const mad::core::Event &event) {
const auto &e = const_cast_to<SensorCollision>(event);
return e.m_id == m_entity_id;
}
std::unordered_set<mad::core::Event::Type> mad::core::SensorCondition::triggers() {
return {mad::core::Event::Type::SensorCollision};
}
void mad::core::SensorCondition::on_start() {
}
19 changes: 19 additions & 0 deletions core/event/management/condition/SensorCondition.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#ifndef MAD_SENSORCONDITION_HPP
#define MAD_SENSORCONDITION_HPP
#include "Condition.hpp"
#include "world/entity/Entity.hpp"
namespace mad::core {
struct SensorCondition : Condition {
public:
explicit SensorCondition(Entity::Id m_entity_id);
bool is_triggered_by(const mad::core::Event &event) override;
std::unordered_set<Event::Type> triggers() override;
void on_start() override;

private:
Entity::Id m_entity_id;
};
}// namespace mad::core


#endif//MAD_SENSORCONDITION_HPP
24 changes: 24 additions & 0 deletions core/event/management/condition/SensorEndCondition.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@

#include "SensorEndCondition.hpp"
#include "common/Cast.hpp"
#include "event/physics/SensorCollisionEnd.hpp"
#include <SFML/System/Time.hpp>

mad::core::SensorEndCondition::SensorEndCondition(Entity::Id m_entity_id, float delta_time) : m_entity_id(m_entity_id), m_dt(delta_time){
}
bool mad::core::SensorEndCondition::is_triggered_by(const mad::core::Event &event) {
if(event.type == Event::Type::SensorCollisionEnd){
const auto &e = const_cast_to<SensorCollisionEnd>(event);
if(e.m_id == m_entity_id){
sf::Time time = clock.getElapsedTime();
timerStart = time.asSeconds();
}
}
return clock.getElapsedTime().asSeconds() - timerStart < m_dt;

}
std::unordered_set<mad::core::Event::Type> mad::core::SensorEndCondition::triggers() {
return {mad::core::Event::Type::SensorCollisionEnd, mad::core::Event::Type::WorldUpdate};
}
void mad::core::SensorEndCondition::on_start() {
}
23 changes: 23 additions & 0 deletions core/event/management/condition/SensorEndCondition.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#ifndef MAD_SENSORENDCONDITION_HPP
#define MAD_SENSORENDCONDITION_HPP

#include "Condition.hpp"
#include "world/entity/Entity.hpp"
#include <SFML/System/Clock.hpp>
namespace mad::core {
struct SensorEndCondition : Condition {
public:
explicit SensorEndCondition(Entity::Id m_entity_id, float delta_time);
bool is_triggered_by(const mad::core::Event &event) override;
std::unordered_set<Event::Type> triggers() override;
void on_start() override;

private:
Entity::Id m_entity_id;
sf::Clock clock;
float timerStart;
float m_dt;
};
}// namespace mad::core

#endif//MAD_SENSORENDCONDITION_HPP
50 changes: 50 additions & 0 deletions core/event/management/controller/Attack.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
#include "Attack.hpp"
mad::core::Attack::Attack(std::shared_ptr<mad::core::LocalWorld> world, mad::core::Entity::Id entity_id, mad::core::Movement::Direction dir, int* attack_stage, float velocity) : Movement(world, entity_id, dir, velocity), attack_stage(attack_stage){
Move_animation = ImageStorage::TypeAction::Attack_1_beg;
Idle_animation = ImageStorage::TypeAction::Attack_1_beg;
}
void mad::core::Attack::control() {
Movement::control();
if((*attack_stage) % 6 == 0){
if(Move_animation != ImageStorage::TypeAction::Attack_1_beg){
SPDLOG_DEBUG("changed to Attack_1_beg");
}
Move_animation = ImageStorage::TypeAction::Attack_1_beg;
Idle_animation = ImageStorage::TypeAction::Attack_1_beg;
}
if((*attack_stage) % 6 == 1){
if(Move_animation != ImageStorage::TypeAction::Attack_1_end){
SPDLOG_DEBUG("changed to Attack_1_end");
}
Move_animation = ImageStorage::TypeAction::Attack_1_end;
Idle_animation = ImageStorage::TypeAction::Attack_1_end;
}
if((*attack_stage) % 6 == 2){
if(Move_animation != ImageStorage::TypeAction::Attack_2_beg){
SPDLOG_DEBUG("changed to Attack_2_beg");
}
Move_animation = ImageStorage::TypeAction::Attack_2_beg;
Idle_animation = ImageStorage::TypeAction::Attack_2_beg;
}
if((*attack_stage) % 6 == 3){
if(Move_animation != ImageStorage::TypeAction::Attack_2_end){
SPDLOG_DEBUG("changed to Attack_2_end");
}
Move_animation = ImageStorage::TypeAction::Attack_2_end;
Idle_animation = ImageStorage::TypeAction::Attack_2_end;
}
if((*attack_stage) % 6 == 4){
if(Move_animation != ImageStorage::TypeAction::Attack_3_beg){
SPDLOG_DEBUG("changed to Attack_3_beg");
}
Move_animation = ImageStorage::TypeAction::Attack_3_beg;
Idle_animation = ImageStorage::TypeAction::Attack_3_beg;
}
if((*attack_stage) % 6 == 5){
if(Move_animation != ImageStorage::TypeAction::Attack_3_end){
SPDLOG_DEBUG("changed to Attack_3_end");
}
Move_animation = ImageStorage::TypeAction::Attack_3_end;
Idle_animation = ImageStorage::TypeAction::Attack_3_end;
}
}
19 changes: 19 additions & 0 deletions core/event/management/controller/Attack.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#ifndef MAD_ATTACK_HPP
#define MAD_ATTACK_HPP

#include "Movement.hpp"
#include "world/LocalWorld.hpp"
#include "world/World.hpp"

namespace mad::core {

class Attack : public Movement {
public:
Attack(std::shared_ptr<mad::core::LocalWorld> world, Entity::Id entity_id, Direction dir, int* attack_stage, float velocity = 0);
void control() override;
int *attack_stage;
};

}

#endif//MAD_ATTACK_HPP
6 changes: 6 additions & 0 deletions core/event/management/controller/Fall.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include "Fall.hpp"

mad::core::Fall::Fall(std::shared_ptr<mad::core::LocalWorld> world, Entity::Id entity_id, Direction dir, float velocity) : Movement(world, entity_id, dir, velocity) {
Move_animation = ImageStorage::TypeAction::Fall;
Idle_animation = ImageStorage::TypeAction::Fall;
}
17 changes: 17 additions & 0 deletions core/event/management/controller/Fall.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#ifndef MAD_FALL_HPP
#define MAD_FALL_HPP

#include "Movement.hpp"
#include "world/LocalWorld.hpp"
#include "world/World.hpp"

namespace mad::core {

class Fall : public Movement {
public:
Fall(std::shared_ptr<mad::core::LocalWorld> world, Entity::Id entity_id, Direction dir, float velocity = 0);
};

}

#endif//MAD_FALL_HPP
6 changes: 6 additions & 0 deletions core/event/management/controller/FlyUp.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include "FlyUp.hpp"

mad::core::FlyUp::FlyUp(std::shared_ptr<mad::core::LocalWorld> world, Entity::Id entity_id, Direction dir, float velocity) : Movement(world, entity_id, dir, velocity) {
Move_animation = ImageStorage::TypeAction::Fly_up;
Idle_animation = ImageStorage::TypeAction::Fly_up;
}
18 changes: 18 additions & 0 deletions core/event/management/controller/FlyUp.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#ifndef MAD_FLYUP_HPP
#define MAD_FLYUP_HPP


#include "Movement.hpp"
#include "world/LocalWorld.hpp"
#include "world/World.hpp"

namespace mad::core {

class FlyUp : public Movement {
public:
FlyUp(std::shared_ptr<mad::core::LocalWorld> world, Entity::Id entity_id, Direction dir, float velocity = 0);
};

}

#endif//MAD_FLYUP_HPP
7 changes: 7 additions & 0 deletions core/event/management/controller/GroundMovement.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

#include "GroundMovement.hpp"

mad::core::GroundMovement::GroundMovement(std::shared_ptr<mad::core::LocalWorld> world, Entity::Id entity_id, Direction dir, float velocity) : Movement(world, entity_id, dir, velocity) {
Move_animation = ImageStorage::TypeAction::Run;
Idle_animation = ImageStorage::TypeAction::Idle;
}
Loading