diff --git a/core/CMakeLists.txt b/core/CMakeLists.txt index 1d87b87..c250f77 100644 --- a/core/CMakeLists.txt +++ b/core/CMakeLists.txt @@ -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 diff --git a/core/event/Event.hpp b/core/event/Event.hpp index c6d231a..b8ba690 100644 --- a/core/event/Event.hpp +++ b/core/event/Event.hpp @@ -17,7 +17,9 @@ namespace mad::core { LevelPause, Runner, WorldUpdate, - EndOfRenderAction + EndOfRenderAction, + SensorCollision, + SensorCollisionEnd, }; explicit Event(Type new_type); diff --git a/core/event/management/condition/Condition.hpp b/core/event/management/condition/Condition.hpp index 8a5fa05..dd3904b 100644 --- a/core/event/management/condition/Condition.hpp +++ b/core/event/management/condition/Condition.hpp @@ -18,6 +18,8 @@ namespace mad::core { virtual void on_start() = 0; virtual ~Condition() = default; + + bool triggered; }; } diff --git a/core/event/management/condition/EndAnimationCondition.cpp b/core/event/management/condition/EndAnimationCondition.cpp new file mode 100644 index 0000000..a7f09eb --- /dev/null +++ b/core/event/management/condition/EndAnimationCondition.cpp @@ -0,0 +1,21 @@ +#include "EndAnimationCondition.hpp" +#include "common/Cast.hpp" +#include "spdlog/spdlog.h" +#include +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(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::EndAnimationCondition::triggers() { + return {mad::core::Event::Type::EndOfRenderAction}; +} +void mad::core::EndAnimationCondition::on_start() { + +} diff --git a/core/event/management/condition/EndAnimationCondition.hpp b/core/event/management/condition/EndAnimationCondition.hpp new file mode 100644 index 0000000..0b9514c --- /dev/null +++ b/core/event/management/condition/EndAnimationCondition.hpp @@ -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 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 diff --git a/core/event/management/condition/FallCondition.cpp b/core/event/management/condition/FallCondition.cpp new file mode 100644 index 0000000..ce13ed6 --- /dev/null +++ b/core/event/management/condition/FallCondition.cpp @@ -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::FallCondition::triggers() { + return {mad::core::Event::Type::WorldUpdate}; +} +void mad::core::FallCondition::on_start() { +} +mad::core::FallCondition::FallCondition(std::shared_ptr 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(m_world->get_storage().get_entity(m_entity_id)); +} diff --git a/core/event/management/condition/FallCondition.hpp b/core/event/management/condition/FallCondition.hpp new file mode 100644 index 0000000..2c54d13 --- /dev/null +++ b/core/event/management/condition/FallCondition.hpp @@ -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 world, Entity::Id entity_id, float vel); + bool is_triggered_by(const mad::core::Event &event) override; + std::unordered_set triggers() override; + void on_start() override; + + private: + std::shared_ptr m_world; + Entity::Id m_entity_id; + PhysicalEntity *m_entity; + float vel; + }; +}// namespace mad::core + +#endif//MAD_FALLCONDITION_HPP diff --git a/core/event/management/condition/KeyReleasedCondition.cpp b/core/event/management/condition/KeyReleasedCondition.cpp new file mode 100644 index 0000000..fd9df64 --- /dev/null +++ b/core/event/management/condition/KeyReleasedCondition.cpp @@ -0,0 +1,15 @@ +#include "KeyReleasedCondition.hpp" +#include +#include +std::unordered_set 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(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() { +} diff --git a/core/event/management/condition/KeyReleasedCondition.hpp b/core/event/management/condition/KeyReleasedCondition.hpp new file mode 100644 index 0000000..ec846c9 --- /dev/null +++ b/core/event/management/condition/KeyReleasedCondition.hpp @@ -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 triggers() override; + void on_start() override; + + private: + const int m_key_id; + }; +}// namespace mad::core + +#endif//MAD_KEYRELEASEDCONDITION_HPP diff --git a/core/event/management/condition/LastStateCondition.cpp b/core/event/management/condition/LastStateCondition.cpp new file mode 100644 index 0000000..a2fb453 --- /dev/null +++ b/core/event/management/condition/LastStateCondition.cpp @@ -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::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 m_machine, mad::core::StateMachine::StateId m_to_state_id) : m_machine(m_machine), m_to_state_id(m_to_state_id){ + +} diff --git a/core/event/management/condition/LastStateCondition.hpp b/core/event/management/condition/LastStateCondition.hpp new file mode 100644 index 0000000..89ec58e --- /dev/null +++ b/core/event/management/condition/LastStateCondition.hpp @@ -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 m_machine, StateMachine::StateId m_to_state_id); + bool is_triggered_by(const mad::core::Event &event) override; + std::unordered_set triggers() override; + void on_start() override; + + private: + std::shared_ptr m_machine; + StateMachine::StateId m_to_state_id; + }; +}// namespace mad::core + +#endif//MAD_LASTSTATECONDITION_HPP diff --git a/core/event/management/condition/SensorCondition.cpp b/core/event/management/condition/SensorCondition.cpp new file mode 100644 index 0000000..24a25b1 --- /dev/null +++ b/core/event/management/condition/SensorCondition.cpp @@ -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(event); + return e.m_id == m_entity_id; +} +std::unordered_set mad::core::SensorCondition::triggers() { + return {mad::core::Event::Type::SensorCollision}; +} +void mad::core::SensorCondition::on_start() { +} diff --git a/core/event/management/condition/SensorCondition.hpp b/core/event/management/condition/SensorCondition.hpp new file mode 100644 index 0000000..31ab53a --- /dev/null +++ b/core/event/management/condition/SensorCondition.hpp @@ -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 triggers() override; + void on_start() override; + + private: + Entity::Id m_entity_id; + }; +}// namespace mad::core + + +#endif//MAD_SENSORCONDITION_HPP diff --git a/core/event/management/condition/SensorEndCondition.cpp b/core/event/management/condition/SensorEndCondition.cpp new file mode 100644 index 0000000..3462a9e --- /dev/null +++ b/core/event/management/condition/SensorEndCondition.cpp @@ -0,0 +1,24 @@ + +#include "SensorEndCondition.hpp" +#include "common/Cast.hpp" +#include "event/physics/SensorCollisionEnd.hpp" +#include + +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(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::SensorEndCondition::triggers() { + return {mad::core::Event::Type::SensorCollisionEnd, mad::core::Event::Type::WorldUpdate}; +} +void mad::core::SensorEndCondition::on_start() { +} diff --git a/core/event/management/condition/SensorEndCondition.hpp b/core/event/management/condition/SensorEndCondition.hpp new file mode 100644 index 0000000..efc7c2c --- /dev/null +++ b/core/event/management/condition/SensorEndCondition.hpp @@ -0,0 +1,23 @@ +#ifndef MAD_SENSORENDCONDITION_HPP +#define MAD_SENSORENDCONDITION_HPP + +#include "Condition.hpp" +#include "world/entity/Entity.hpp" +#include +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 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 diff --git a/core/event/management/controller/Attack.cpp b/core/event/management/controller/Attack.cpp new file mode 100644 index 0000000..f8d3a5b --- /dev/null +++ b/core/event/management/controller/Attack.cpp @@ -0,0 +1,50 @@ +#include "Attack.hpp" +mad::core::Attack::Attack(std::shared_ptr 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; + } +} diff --git a/core/event/management/controller/Attack.hpp b/core/event/management/controller/Attack.hpp new file mode 100644 index 0000000..e278c3a --- /dev/null +++ b/core/event/management/controller/Attack.hpp @@ -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 world, Entity::Id entity_id, Direction dir, int* attack_stage, float velocity = 0); + void control() override; + int *attack_stage; + }; + +} + +#endif//MAD_ATTACK_HPP diff --git a/core/event/management/controller/Fall.cpp b/core/event/management/controller/Fall.cpp new file mode 100644 index 0000000..ed817e6 --- /dev/null +++ b/core/event/management/controller/Fall.cpp @@ -0,0 +1,6 @@ +#include "Fall.hpp" + +mad::core::Fall::Fall(std::shared_ptr 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; +} diff --git a/core/event/management/controller/Fall.hpp b/core/event/management/controller/Fall.hpp new file mode 100644 index 0000000..4e8274d --- /dev/null +++ b/core/event/management/controller/Fall.hpp @@ -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 world, Entity::Id entity_id, Direction dir, float velocity = 0); + }; + +} + +#endif//MAD_FALL_HPP diff --git a/core/event/management/controller/FlyUp.cpp b/core/event/management/controller/FlyUp.cpp new file mode 100644 index 0000000..969d7e2 --- /dev/null +++ b/core/event/management/controller/FlyUp.cpp @@ -0,0 +1,6 @@ +#include "FlyUp.hpp" + +mad::core::FlyUp::FlyUp(std::shared_ptr 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; +} diff --git a/core/event/management/controller/FlyUp.hpp b/core/event/management/controller/FlyUp.hpp new file mode 100644 index 0000000..e87bc4a --- /dev/null +++ b/core/event/management/controller/FlyUp.hpp @@ -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 world, Entity::Id entity_id, Direction dir, float velocity = 0); + }; + +} + +#endif//MAD_FLYUP_HPP diff --git a/core/event/management/controller/GroundMovement.cpp b/core/event/management/controller/GroundMovement.cpp new file mode 100644 index 0000000..b8e127e --- /dev/null +++ b/core/event/management/controller/GroundMovement.cpp @@ -0,0 +1,7 @@ + +#include "GroundMovement.hpp" + +mad::core::GroundMovement::GroundMovement(std::shared_ptr 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; +} diff --git a/core/event/management/controller/GroundMovement.hpp b/core/event/management/controller/GroundMovement.hpp new file mode 100644 index 0000000..339fe34 --- /dev/null +++ b/core/event/management/controller/GroundMovement.hpp @@ -0,0 +1,17 @@ +#ifndef MAD_GROUNDMOVEMENT_HPP +#define MAD_GROUNDMOVEMENT_HPP + +#include "Movement.hpp" +#include "world/LocalWorld.hpp" +#include "world/World.hpp" + +namespace mad::core { + + class GroundMovement : public Movement { + public: + GroundMovement(std::shared_ptr world, Entity::Id entity_id, Direction dir, float velocity = 0); + }; + +} + +#endif//MAD_GROUNDMOVEMENT_HPP diff --git a/core/event/management/controller/JumpImpulse.cpp b/core/event/management/controller/JumpImpulse.cpp new file mode 100644 index 0000000..8ef771f --- /dev/null +++ b/core/event/management/controller/JumpImpulse.cpp @@ -0,0 +1,15 @@ +#include "JumpImpulse.hpp" +#include "world/intent/LambdaIntent.hpp" +mad::core::JumpImpulse::JumpImpulse(std::shared_ptr world, Entity::Id entity_id, float m_impulse) : m_world(world), m_entity_id(entity_id), m_impulse(m_impulse) { +} +void mad::core::JumpImpulse::control() { + + auto impulse = [](mad::core::Vec2d dir) { + return mad::core::LambdaIntent( + [=](mad::core::Entity &entity, mad::core::EventDispatcher &event_dispatcher) { + mad::core::cast_to(entity).apply_linear_impulse_to_center(dir, event_dispatcher); + }); + }; + + m_world->manipulate_entity_id(m_entity_id, impulse(mad::core::Vec2d{0.0f, -m_impulse})); +} diff --git a/core/event/management/controller/JumpImpulse.hpp b/core/event/management/controller/JumpImpulse.hpp new file mode 100644 index 0000000..4d3a654 --- /dev/null +++ b/core/event/management/controller/JumpImpulse.hpp @@ -0,0 +1,26 @@ +#ifndef MAD_JUMPIMPULSE_HPP +#define MAD_JUMPIMPULSE_HPP + +#include "Controller.hpp" +#include "world/LocalWorld.hpp" +#include "world/World.hpp" +namespace mad::core { + + class JumpImpulse : public Controller { + public: + + explicit JumpImpulse(std::shared_ptr world, Entity::Id entity_id, float m_impulse); + + void control() override; + + private: + std::shared_ptr m_world; + Entity::Id m_entity_id; + std::shared_ptr key; + float m_impulse; + + }; + +} + +#endif//MAD_JUMPIMPULSE_HPP diff --git a/core/event/management/controller/Movement.cpp b/core/event/management/controller/Movement.cpp new file mode 100644 index 0000000..ec235af --- /dev/null +++ b/core/event/management/controller/Movement.cpp @@ -0,0 +1,29 @@ +#include "Movement.hpp" +#include "world/intent/LambdaIntent.hpp" +mad::core::Movement::Movement(std::shared_ptr world, Entity::Id entity_id, mad::core::Movement::Direction dir, float velocity) : m_world(world), m_entity_id(entity_id), dir(dir), velocity(velocity){ + m_entity = cast_to_or_null(m_world->get_storage().get_entity(m_entity_id)); +} +void mad::core::Movement::control() { + auto set_horizontal_velocity = [](float vel) { + return mad::core::LambdaIntent( + [=](mad::core::Entity &entity, mad::core::EventDispatcher &event_dispatcher) { + mad::core::cast_to(entity).set_linear_horizontal_velocity(vel, event_dispatcher); + }); + }; + if(dir == Direction::Right || dir == Direction::Left){ + m_entity->set_action(Move_animation); + if(dir == Direction::Right){ + m_entity->flip_over(Image::Orientation::Right); + m_world->manipulate_entity_id(m_entity_id, set_horizontal_velocity(velocity)); + } + else if(dir == Direction::Left){ + m_entity->flip_over(Image::Orientation::Left); + m_world->manipulate_entity_id(m_entity_id, set_horizontal_velocity(-velocity)); + } + } + else if(dir == Direction::Idle){ + m_entity->set_action(Idle_animation); + } + float k = 0.8; + m_world->manipulate_entity_id(m_entity_id, set_horizontal_velocity(m_entity->get_linear_velocity().get_x() * k)); +} diff --git a/core/event/management/controller/Movement.hpp b/core/event/management/controller/Movement.hpp new file mode 100644 index 0000000..2bac02d --- /dev/null +++ b/core/event/management/controller/Movement.hpp @@ -0,0 +1,35 @@ +#ifndef MAD_MOVEMENT_HPP +#define MAD_MOVEMENT_HPP + + +#include "Controller.hpp" +#include "world/LocalWorld.hpp" +#include "world/World.hpp" + +namespace mad::core { + + class Movement : public Controller { + public: + enum class Direction { + Right, + Left, + Idle, + }; + explicit Movement(std::shared_ptr world, Entity::Id entity_id, Direction dir, float velocity = 0); + + void control() override; + + private: + std::shared_ptr m_world; + Entity::Id m_entity_id; + Direction dir; + PhysicalEntity* m_entity; + float velocity; + protected: + ImageStorage::TypeAction Move_animation; + ImageStorage::TypeAction Idle_animation; + }; + +} + +#endif//MAD_MOVEMENT_HPP diff --git a/core/event/management/controller/StartJump.cpp b/core/event/management/controller/StartJump.cpp new file mode 100644 index 0000000..c124a52 --- /dev/null +++ b/core/event/management/controller/StartJump.cpp @@ -0,0 +1,6 @@ +#include "StartJump.hpp" + +mad::core::StartJump::StartJump(std::shared_ptr world, Entity::Id entity_id, Direction dir, float velocity) : Movement(world, entity_id, dir, velocity) { + Move_animation = ImageStorage::TypeAction::Jump; + Idle_animation = ImageStorage::TypeAction::Jump; +} diff --git a/core/event/management/controller/StartJump.hpp b/core/event/management/controller/StartJump.hpp new file mode 100644 index 0000000..ea4df13 --- /dev/null +++ b/core/event/management/controller/StartJump.hpp @@ -0,0 +1,17 @@ +#ifndef MAD_STARTJUMP_HPP +#define MAD_STARTJUMP_HPP + +#include "Movement.hpp" +#include "world/LocalWorld.hpp" +#include "world/World.hpp" + +namespace mad::core { + + class StartJump : public Movement { + public: + StartJump(std::shared_ptr world, Entity::Id entity_id, Direction dir, float velocity = 0); + }; + +} + +#endif//MAD_STARTJUMP_HPP diff --git a/core/event/management/controller/statemachine/HeroStateMachine.cpp b/core/event/management/controller/statemachine/HeroStateMachine.cpp new file mode 100644 index 0000000..45a8d8f --- /dev/null +++ b/core/event/management/controller/statemachine/HeroStateMachine.cpp @@ -0,0 +1,138 @@ +#include "HeroStateMachine.hpp" +#include "event/management/condition/EndAnimationCondition.hpp" +#include "event/management/condition/FallCondition.hpp" +#include "event/management/condition/KeyDownCondition.hpp" +#include "event/management/condition/KeyPressedCondition.hpp" +#include "event/management/condition/KeyReleasedCondition.hpp" +#include "event/management/condition/LastStateCondition.hpp" +#include "event/management/condition/SensorCondition.hpp" +#include "event/management/condition/SensorEndCondition.hpp" +#include "event/management/condition/TimerCondition.hpp" +#include "event/management/condition/TrueCondition.hpp" +#include "event/management/controller/Attack.hpp" +#include "event/management/controller/Fall.hpp" +#include "event/management/controller/FlyUp.hpp" +#include "event/management/controller/GroundMovement.hpp" +#include "event/management/controller/JumpImpulse.hpp" +#include "event/management/controller/Movement.hpp" +#include "event/management/controller/StartJump.hpp" +#include "event/management/controller/statemachine/StateMachine.hpp" + +mad::core::HeroStateMachine::HeroStateMachine(std::shared_ptr world, mad::core::Vec2d position, int hero_id, std::shared_ptr level_dispatcher, float m_impulse, float horizontal_velocity) : StateMachine(level_dispatcher){ + auto machine = this; + + + StateMachine::StateId ground_idle = machine->add_state(std::make_shared(world, hero_id, Movement::Direction::Idle)); + StateMachine::StateId ground_right = machine->add_state(std::make_shared(world, hero_id, Movement::Direction::Right, horizontal_velocity)); + StateMachine::StateId ground_left = machine->add_state(std::make_shared(world, hero_id, Movement::Direction::Left, horizontal_velocity)); + StateMachine::StateId jump_impulse = machine->add_state(std::make_shared(world, hero_id, m_impulse)); + StateMachine::StateId start_jump_left = machine->add_state(std::make_shared(world, hero_id, Movement::Direction::Left, horizontal_velocity)); + StateMachine::StateId start_jump_idle = machine->add_state(std::make_shared(world, hero_id, Movement::Direction::Idle, horizontal_velocity)); + StateMachine::StateId start_jump_right = machine->add_state(std::make_shared(world, hero_id, Movement::Direction::Right, horizontal_velocity)); + StateMachine::StateId fly_up_left = machine->add_state(std::make_shared(world, hero_id, Movement::Direction::Left, horizontal_velocity)); /// 7 + StateMachine::StateId fly_up_idle = machine->add_state(std::make_shared(world, hero_id, Movement::Direction::Idle, horizontal_velocity)); + StateMachine::StateId fly_up_right = machine->add_state(std::make_shared(world, hero_id, Movement::Direction::Right, horizontal_velocity)); + StateMachine::StateId fall_left = machine->add_state(std::make_shared(world, hero_id, Movement::Direction::Left, horizontal_velocity)); /// 10 + StateMachine::StateId fall_idle = machine->add_state(std::make_shared(world, hero_id, Movement::Direction::Idle, horizontal_velocity)); + StateMachine::StateId fall_right= machine->add_state(std::make_shared(world, hero_id, Movement::Direction::Right, horizontal_velocity)); + int *attack_stage = new int(0); + StateMachine::StateId attack_left = machine->add_state(std::make_shared(world, hero_id, Movement::Direction::Left, attack_stage, horizontal_velocity)); + StateMachine::StateId attack_idle= machine->add_state(std::make_shared(world, hero_id, Movement::Direction::Idle, attack_stage, horizontal_velocity)); + StateMachine::StateId attack_right = machine->add_state(std::make_shared(world, hero_id, Movement::Direction::Right, attack_stage, horizontal_velocity)); + + machine->add_transition(ground_idle, ground_right, std::make_shared(sf::Keyboard::Right)); + machine->add_transition(ground_idle, ground_left, std::make_shared(sf::Keyboard::Left)); + machine->add_transition(ground_right, ground_idle, std::make_shared(sf::Keyboard::Right)); + machine->add_transition(ground_left, ground_idle, std::make_shared(sf::Keyboard::Left)); + machine->add_transition(ground_right, ground_left, std::make_shared(sf::Keyboard::Left)); + machine->add_transition(ground_left, ground_right, std::make_shared(sf::Keyboard::Right)); + machine->add_transition(ground_idle, jump_impulse, std::make_shared(sf::Keyboard::Space)); + machine->add_transition(ground_right, jump_impulse, std::make_shared(sf::Keyboard::Space)); + machine->add_transition(ground_left, jump_impulse, std::make_shared(sf::Keyboard::Space)); + + machine->add_transition(jump_impulse, start_jump_idle, std::make_shared()); + machine->add_transition(start_jump_idle, start_jump_left , std::make_shared(sf::Keyboard::Left)); + machine->add_transition(start_jump_idle, start_jump_right, std::make_shared(sf::Keyboard::Right)); + machine->add_transition(start_jump_left , start_jump_idle, std::make_shared(sf::Keyboard::Left)); + machine->add_transition(start_jump_right, start_jump_idle, std::make_shared(sf::Keyboard::Right)); + + + machine->add_transition(start_jump_left , fly_up_idle, std::make_shared(hero_id, ImageStorage::TypeAction::Jump)); + machine->add_transition(start_jump_idle, fly_up_idle, std::make_shared(hero_id, ImageStorage::TypeAction::Jump)); + machine->add_transition(start_jump_right, fly_up_idle, std::make_shared(hero_id, ImageStorage::TypeAction::Jump)); + + machine->add_transition(fly_up_idle, fly_up_left, std::make_shared(sf::Keyboard::Left)); + machine->add_transition(fly_up_idle, fly_up_right, std::make_shared(sf::Keyboard::Right)); + machine->add_transition(fly_up_left, fly_up_idle, std::make_shared(sf::Keyboard::Left)); + machine->add_transition(fly_up_right, fly_up_idle, std::make_shared(sf::Keyboard::Right)); + + machine->add_transition(fly_up_left, fall_idle, std::make_shared(world, hero_id, 0)); + machine->add_transition(fly_up_idle, fall_idle, std::make_shared(world, hero_id, 0)); + machine->add_transition(fly_up_right, fall_idle, std::make_shared(world, hero_id, 0)); + + machine->add_transition(ground_left, fall_idle, std::vector>{std::make_shared(world, hero_id, 0.1), std::make_shared(hero_id, 0.2)}); + machine->add_transition(ground_idle, fall_idle, std::vector>{std::make_shared(world, hero_id, 0.1), std::make_shared(hero_id, 0.2)}); + machine->add_transition(ground_right, fall_idle, std::vector>{std::make_shared(world, hero_id, 0.1), std::make_shared(hero_id, 0.2)}); + + machine->add_transition(fall_idle, fall_left, std::make_shared(sf::Keyboard::Left)); + machine->add_transition(fall_idle, fall_right, std::make_shared(sf::Keyboard::Right)); + machine->add_transition(fall_left, fall_idle, std::make_shared(sf::Keyboard::Left)); + machine->add_transition(fall_right, fall_idle, std::make_shared(sf::Keyboard::Right)); + + machine->add_transition(fall_left, ground_idle, std::make_shared(hero_id)); + machine->add_transition(fall_idle, ground_idle, std::make_shared(hero_id)); + machine->add_transition(fall_right, ground_idle, std::make_shared(hero_id)); + + + machine->add_transition(ground_left, attack_idle, std::make_shared(sf::Keyboard::Q)); + machine->add_transition(ground_idle, attack_idle, std::make_shared(sf::Keyboard::Q)); + machine->add_transition(ground_right, attack_idle, std::make_shared(sf::Keyboard::Q)); + machine->add_transition(start_jump_left, attack_idle, std::make_shared(sf::Keyboard::Q)); + machine->add_transition(start_jump_idle, attack_idle, std::make_shared(sf::Keyboard::Q)); + machine->add_transition(start_jump_right, attack_idle, std::make_shared(sf::Keyboard::Q)); + machine->add_transition(fly_up_left, attack_idle, std::make_shared(sf::Keyboard::Q)); + machine->add_transition(fly_up_idle, attack_idle, std::make_shared(sf::Keyboard::Q)); + machine->add_transition(fly_up_right, attack_idle, std::make_shared(sf::Keyboard::Q)); + machine->add_transition(fall_left, attack_idle, std::make_shared(sf::Keyboard::Q)); + machine->add_transition(fall_idle, attack_idle, std::make_shared(sf::Keyboard::Q)); + machine->add_transition(fall_right, attack_idle, std::make_shared(sf::Keyboard::Q)); + + machine->add_transition(attack_idle, attack_left, std::make_shared(sf::Keyboard::Left)); + machine->add_transition(attack_left, attack_idle, std::make_shared(sf::Keyboard::Left)); + machine->add_transition(attack_idle, attack_right, std::make_shared(sf::Keyboard::Right)); + machine->add_transition(attack_right, attack_idle, std::make_shared(sf::Keyboard::Right)); + + machine->add_transition(attack_idle, attack_idle, std::make_shared(hero_id, ImageStorage::TypeAction::Attack_1_beg, attack_stage)); + machine->add_transition(attack_left, attack_idle, std::make_shared(hero_id, ImageStorage::TypeAction::Attack_1_beg, attack_stage)); + machine->add_transition(attack_right, attack_idle, std::make_shared(hero_id, ImageStorage::TypeAction::Attack_1_beg, attack_stage)); + + machine->add_transition(attack_left, ground_idle, std::make_shared(hero_id, ImageStorage::TypeAction::Attack_1_end, attack_stage)); + machine->add_transition(attack_idle, ground_idle, std::make_shared(hero_id, ImageStorage::TypeAction::Attack_1_end, attack_stage)); + machine->add_transition(attack_right, ground_idle, std::make_shared(hero_id, ImageStorage::TypeAction::Attack_1_end, attack_stage)); + + machine->add_transition(attack_idle, attack_idle, std::make_shared(hero_id, ImageStorage::TypeAction::Attack_2_beg, attack_stage)); + machine->add_transition(attack_left, attack_idle, std::make_shared(hero_id, ImageStorage::TypeAction::Attack_2_beg, attack_stage)); + machine->add_transition(attack_right, attack_idle, std::make_shared(hero_id, ImageStorage::TypeAction::Attack_2_beg, attack_stage)); + + machine->add_transition(attack_left, ground_idle, std::make_shared(hero_id, ImageStorage::TypeAction::Attack_2_end, attack_stage)); + machine->add_transition(attack_idle, ground_idle, std::make_shared(hero_id, ImageStorage::TypeAction::Attack_2_end, attack_stage)); + machine->add_transition(attack_right, ground_idle, std::make_shared(hero_id, ImageStorage::TypeAction::Attack_2_end, attack_stage)); + + machine->add_transition(attack_idle, attack_idle, std::make_shared(hero_id, ImageStorage::TypeAction::Attack_3_beg, attack_stage)); + machine->add_transition(attack_left, attack_idle, std::make_shared(hero_id, ImageStorage::TypeAction::Attack_3_beg, attack_stage)); + machine->add_transition(attack_right, attack_idle, std::make_shared(hero_id, ImageStorage::TypeAction::Attack_3_beg, attack_stage)); + + machine->add_transition(attack_left, ground_idle, std::make_shared(hero_id, ImageStorage::TypeAction::Attack_3_end, attack_stage)); + machine->add_transition(attack_idle, ground_idle, std::make_shared(hero_id, ImageStorage::TypeAction::Attack_3_end, attack_stage)); + machine->add_transition(attack_right, ground_idle, std::make_shared(hero_id, ImageStorage::TypeAction::Attack_3_end, attack_stage)); + + + + + + + + + machine->set_initial_state(0); + //controllers.push_back(machine); +} diff --git a/core/event/management/controller/statemachine/HeroStateMachine.hpp b/core/event/management/controller/statemachine/HeroStateMachine.hpp new file mode 100644 index 0000000..9b8b0f7 --- /dev/null +++ b/core/event/management/controller/statemachine/HeroStateMachine.hpp @@ -0,0 +1,16 @@ +#ifndef MAD_HEROSTATEMACHINE_HPP +#define MAD_HEROSTATEMACHINE_HPP + +#include "StateMachine.hpp" +#include "world/LocalWorld.hpp" +namespace mad::core{ + class HeroStateMachine : public StateMachine { + + public: + explicit HeroStateMachine(std::shared_ptr world, Vec2d position, int hero_id, std::shared_ptr level_dispatcher, float m_impulse, float horizontal_velocity); + }; +} + + + +#endif//MAD_HEROSTATEMACHINE_HPP diff --git a/core/event/management/controller/statemachine/StateMachine.cpp b/core/event/management/controller/statemachine/StateMachine.cpp index b986148..d5bd2d1 100644 --- a/core/event/management/controller/statemachine/StateMachine.cpp +++ b/core/event/management/controller/statemachine/StateMachine.cpp @@ -7,12 +7,28 @@ std::unordered_set mad::core::Transition::handled_types() { - return m_condition->triggers(); + std::unordered_set res; + for(auto const &i : m_conditions){ + res.insert(i->triggers().begin(), i->triggers().end()); + } + return res; } void mad::core::Transition::handle(const mad::core::Event &event) { if (!is_active || m_state_machine->has_made_transition) return; - if (m_condition->is_triggered_by(event)) { + for(auto &i : m_conditions){ + if(i->triggers().find(event.type) != i->triggers().end()){ + if(i->is_triggered_by(event)){ + i->triggered = true; + } + } + } + bool flag = true; + for(auto &i : m_conditions){ + flag &= i->triggered; + } + if (flag) { m_state_machine->has_made_transition = true; + m_state_machine->m_previous_state_id = m_state_machine->m_current_state_id; m_state_machine->m_current_state_id = next_state; SPDLOG_DEBUG("current state {}", m_state_machine->m_current_state_id); for (auto &i : m_state_machine->m_transitions[current_state]) { @@ -20,17 +36,26 @@ void mad::core::Transition::handle(const mad::core::Event &event) { } for (auto &i : m_state_machine->m_transitions[next_state]) { i->is_active = true; - i->m_condition->on_start(); + for(auto &el : i->m_conditions){ + el->on_start(); + } } } } -mad::core::Transition::Transition(mad::core::StateMachine *m_state_machine, mad::core::StateMachine::StateId current_state, mad::core::StateMachine::StateId next_state, std::shared_ptr m_condition) : m_state_machine(m_state_machine), current_state(current_state), next_state(next_state), m_condition(std::move(m_condition)) { +mad::core::Transition::Transition(mad::core::StateMachine *m_state_machine, mad::core::StateMachine::StateId current_state, mad::core::StateMachine::StateId next_state, std::shared_ptr m_condition) : m_state_machine(m_state_machine), current_state(current_state), next_state(next_state), m_conditions({std::move(m_condition)}) { +} +mad::core::Transition::Transition(mad::core::StateMachine *m_state_machine, mad::core::StateMachine::StateId current_state, mad::core::StateMachine::StateId next_state, std::vector> m_conditions) : m_state_machine(m_state_machine), current_state(current_state), next_state(next_state), m_conditions(m_conditions) { } /// StateMachine void mad::core::StateMachine::control() { //SPDLOG_DEBUG("current state {}", m_current_state_id); + for(auto &i : m_transitions[m_current_state_id]){ + for(auto &j : i->m_conditions){ + j->triggered = false; + } + } has_made_transition = false; m_states[m_current_state_id]->control(); } @@ -41,6 +66,7 @@ mad::core::StateMachine::StateId mad::core::StateMachine::add_state(const std::s } void mad::core::StateMachine::set_initial_state(mad::core::StateMachine::StateId state_id) { m_current_state_id = state_id; + m_previous_state_id = state_id; for (auto &i : m_transitions[state_id]) { i->is_active = true; } @@ -50,5 +76,13 @@ void mad::core::StateMachine::add_transition(mad::core::StateMachine::StateId st m_transitions[state_id_from].push_back(transition); m_dispatcher->registry(transition); } +void mad::core::StateMachine::add_transition(mad::core::StateMachine::StateId state_id_from, mad::core::StateMachine::StateId state_id_to, std::vector> transition_conditions) { + auto transition = std::make_shared(this, state_id_from, state_id_to, transition_conditions); + m_transitions[state_id_from].push_back(transition); + m_dispatcher->registry(transition); +} mad::core::StateMachine::StateMachine(std::shared_ptr m_dispatcher) : m_dispatcher(std::move(m_dispatcher)){ } +mad::core::StateMachine::StateId mad::core::StateMachine::get_previous_state_id() { + return m_previous_state_id; +} diff --git a/core/event/management/controller/statemachine/StateMachine.hpp b/core/event/management/controller/statemachine/StateMachine.hpp index 733e029..e9629da 100644 --- a/core/event/management/controller/statemachine/StateMachine.hpp +++ b/core/event/management/controller/statemachine/StateMachine.hpp @@ -19,11 +19,15 @@ namespace mad::core { StateId add_state(const std::shared_ptr &state); void add_transition(StateId state_id_from, StateId state_id_to, std::shared_ptr transition_condition); + void add_transition(StateId state_id_from, StateId state_id_to, std::vector> transition_conditions); void set_initial_state(StateId state_id); void control() override; + StateId get_previous_state_id(); + private: StateId m_current_state_id = -1; + StateId m_previous_state_id = -1; std::vector> m_states; std::vector>> m_transitions; std::shared_ptr m_dispatcher; @@ -32,17 +36,20 @@ namespace mad::core { }; struct Transition : EventHandler { + std::vector> m_conditions; + public: Transition(StateMachine *m_state_machine, StateMachine::StateId current_state, StateMachine::StateId next_state, std::shared_ptr m_condition); + Transition(StateMachine *m_state_machine, StateMachine::StateId current_state, StateMachine::StateId next_state, std::vector> m_conditions); std::unordered_set handled_types() override; void handle(const Event &event) override; bool is_active = false; + int cnt = 0; private: StateMachine *m_state_machine; StateMachine::StateId current_state; StateMachine::StateId next_state; - std::shared_ptr m_condition; }; }// namespace mad::core diff --git a/core/event/management/handler/CollisionHandler.cpp b/core/event/management/handler/CollisionHandler.cpp index 1c80ba1..569f9ab 100644 --- a/core/event/management/handler/CollisionHandler.cpp +++ b/core/event/management/handler/CollisionHandler.cpp @@ -14,7 +14,7 @@ void mad::core::CollisionHandler::handle(const mad::core::Event &event) { const auto &collision = const_cast_to(event); Entity::Id id_A = collision.first_object_id; Entity::Id id_B = collision.second_object_id; -// SPDLOG_INFO("handle collision {0} {1}", id_A, id_B); + SPDLOG_INFO("handle collision {0} {1}", id_A, id_B); } std::unordered_set mad::core::CollisionHandler::handled_types() { return {Event::Type::Collision}; diff --git a/core/event/physics/Collision.cpp b/core/event/physics/Collision.cpp index cc9d138..b932ed2 100644 --- a/core/event/physics/Collision.cpp +++ b/core/event/physics/Collision.cpp @@ -1,4 +1,5 @@ #include "Collision.hpp" +#include "spdlog/spdlog.h" mad::core::Collision::Collision(int new_first_object_id, int new_second_object_id) : Event(Event::Type::Collision), first_object_id(new_first_object_id), second_object_id(new_second_object_id) { - + //SPDLOG_INFO("handle collision {0} {1}", first_object_id, second_object_id); } diff --git a/core/event/physics/SensorCollision.cpp b/core/event/physics/SensorCollision.cpp new file mode 100644 index 0000000..24ec6bb --- /dev/null +++ b/core/event/physics/SensorCollision.cpp @@ -0,0 +1,5 @@ +#include "SensorCollision.hpp" +#include "spdlog/spdlog.h" +mad::core::SensorCollision::SensorCollision(int m_id) : Event(Event::Type::SensorCollision), m_id(m_id) { + //SPDLOG_INFO("sensor {}", m_id); +} diff --git a/core/event/physics/SensorCollision.hpp b/core/event/physics/SensorCollision.hpp new file mode 100644 index 0000000..762bb90 --- /dev/null +++ b/core/event/physics/SensorCollision.hpp @@ -0,0 +1,15 @@ +#ifndef MAD_SENSORCOLLISION_HPP +#define MAD_SENSORCOLLISION_HPP + +#include "event/Event.hpp" +namespace mad::core { + + struct SensorCollision : public Event { + explicit SensorCollision(int m_id); + + const int m_id; + }; + +} + +#endif//MAD_SENSORCOLLISION_HPP diff --git a/core/event/physics/SensorCollisionEnd.cpp b/core/event/physics/SensorCollisionEnd.cpp new file mode 100644 index 0000000..7da112c --- /dev/null +++ b/core/event/physics/SensorCollisionEnd.cpp @@ -0,0 +1,3 @@ +#include "SensorCollisionEnd.hpp" +mad::core::SensorCollisionEnd::SensorCollisionEnd(int m_id) : Event(Event::Type::SensorCollisionEnd), m_id(m_id) { +} diff --git a/core/event/physics/SensorCollisionEnd.hpp b/core/event/physics/SensorCollisionEnd.hpp new file mode 100644 index 0000000..6b936b1 --- /dev/null +++ b/core/event/physics/SensorCollisionEnd.hpp @@ -0,0 +1,16 @@ +#ifndef MAD_SENSORCOLLISIONEND_HPP +#define MAD_SENSORCOLLISIONEND_HPP + +#include "event/Event.hpp" +namespace mad::core { + + struct SensorCollisionEnd : public Event { + explicit SensorCollisionEnd(int m_id); + + const int m_id; + }; + +} + + +#endif//MAD_SENSORCOLLISIONEND_HPP diff --git a/core/loader/LevelLoaderFromFile.cpp b/core/loader/LevelLoaderFromFile.cpp index 3872ab1..fbe8805 100644 --- a/core/loader/LevelLoaderFromFile.cpp +++ b/core/loader/LevelLoaderFromFile.cpp @@ -1,10 +1,17 @@ #include "LevelLoaderFromFile.hpp" -#include #include "event/management/condition/KeyDownCondition.hpp" #include "event/management/condition/KeyPressedCondition.hpp" #include "event/management/condition/TimerCondition.hpp" #include "event/management/condition/TrueCondition.hpp" +#include "event/management/controller/statemachine/HeroStateMachine.hpp" #include "event/management/controller/statemachine/StateMachine.hpp" +#include <../../game/mobs/hero/Hero.hpp> +#include +#include +#include +#include +#include +#include #include @@ -19,30 +26,34 @@ namespace mad::core { std::unique_ptr LevelLoaderFromFile::load(std::shared_ptr global_dispatcher, std::shared_ptr system_listener) { - auto level_dispatcher = std::make_shared(); + level_dispatcher = std::make_shared(); auto world = std::make_shared(*level_dispatcher); Vec2d camera_position = {m_config_json["camera"]["position"]["x"], m_config_json["camera"]["position"]["y"]}; float camera_smoothness = m_config_json["camera"]["smoothness"]; - Camera::FollowType camera_type = m_config_json["camera"]["follow_type"] == "forward" ? - Camera::FollowType::Forward : Camera::FollowType::Backward; + Camera::FollowType camera_type = m_config_json["camera"]["follow_type"] == "forward" ? Camera::FollowType::Forward : Camera::FollowType::Backward; float minimal_distance = m_config_json["camera"]["minimal_distance"]; auto camera = std::make_shared(camera_position, world, true); + controllers = {std::make_shared( + camera)}; + + + //Entity::Id hero_id = create_world(world); auto keys = create_world(world); camera->turn_on(*level_dispatcher, keys[LevelLoaderFromFile::IdKeys::Hero], camera_smoothness, camera_type, minimal_distance); level_dispatcher->registry(camera); - level_dispatcher->registry(std::make_shared(world, keys[LevelLoaderFromFile::IdKeys::Hero])); + //level_dispatcher->registry(std::make_shared(world, keys[LevelLoaderFromFile::IdKeys::Hero])); /* std::vector> controllers { std::make_shared(camera) };*/ - ///State Machine + /*///State Machine struct C1 : mad::core::Controller { void control() override { //SPDLOG_DEBUG("controller 1"); @@ -62,7 +73,9 @@ namespace mad::core { machine->set_initial_state(0); std::vector> controllers{machine, std::make_shared( - camera)}; + camera)};*/ + + camera->set_zoom(0.15); auto level_runner = std::make_unique( system_listener, @@ -71,8 +84,7 @@ namespace mad::core { global_dispatcher, level_dispatcher, world, - controllers - ); + controllers); level_dispatcher->registry(std::make_shared(*level_runner, std::make_shared(keys[LevelLoaderFromFile::IdKeys::Hero], keys[LevelLoaderFromFile::IdKeys::FinishBlock]))); level_dispatcher->registry(std::make_shared(*level_runner)); @@ -86,12 +98,13 @@ namespace mad::core { float current_position_x = object_size / 2; float current_position_y = object_size / 2; std::unordered_map keys; + Entity::Id hero_id = 0; std::string map_line; create_background(world); while (std::getline(m_level_map, map_line)) { - for (char object: map_line) { + for (char object : map_line) { switch (m_objects[object]) { case Objects::UnstableBlock: { create_block(world, @@ -115,12 +128,13 @@ namespace mad::core { break; } case Objects::Hero: { - keys[LevelLoaderFromFile::IdKeys::Hero] = create_hero(world, - {current_position_x, - current_position_y}); + // Hero hero(world, {current_position_x, current_position_y}, m_config_json, level_dispatcher, controllers); + hero_id = create_hero(world, {current_position_x, current_position_y}); + keys[LevelLoaderFromFile::IdKeys::Hero] = hero_id; break; } case Objects::Enemy1: { + create_mob(world, {current_position_x, current_position_y}); break; } case Objects::Enemy2: { @@ -153,16 +167,14 @@ namespace mad::core { {{ImageStorage::TypeAction::Idle, std::make_shared(source, block_size, block_size, - StaticImage::TransformType::Tile) - }})); + StaticImage::TransformType::Fit)}})); Entity::Id square_id = world->create_physical_entity( 0, position, 0, image_storage, - is_stable - ); + is_stable); } Entity::Id LevelLoaderFromFile::create_hero(std::shared_ptr world, Vec2d position) { @@ -182,34 +194,163 @@ namespace mad::core { image_storage = std::make_shared( std::unordered_map>( - {{ImageStorage::TypeAction::Idle, - std::make_shared( - source / m_config_json["hero"]["animated"]["actions"]["idle"]["source"], - m_config_json["hero"]["animated"]["actions"]["idle"]["delta_time"], - physical_size_width, physical_size_height, size_scale, - delta_x, delta_y) - }, + {{ImageStorage::TypeAction::Jump, + std::make_shared( + source / m_config_json["hero"]["animated"]["actions"]["jump"]["source"], + + m_config_json["hero"]["animated"]["actions"]["jump"]["delta_time"], + physical_size_width, physical_size_height, size_scale, + delta_x, delta_y)}, + {ImageStorage::TypeAction::Idle, + std::make_shared( + source / m_config_json["hero"]["animated"]["actions"]["idle"]["source"], + + m_config_json["hero"]["animated"]["actions"]["idle"]["delta_time"], + physical_size_width, physical_size_height, size_scale, + delta_x, delta_y)}, {ImageStorage::TypeAction::Run, - std::make_shared( - source / m_config_json["hero"]["animated"]["actions"]["run"]["source"], - m_config_json["hero"]["animated"]["actions"]["run"]["delta_time"], - physical_size_width, physical_size_height, size_scale, - delta_x, delta_y) - }} - ) - ); + std::make_shared( + source / m_config_json["hero"]["animated"]["actions"]["run"]["source"], + + m_config_json["hero"]["animated"]["actions"]["run"]["delta_time"], + physical_size_width, physical_size_height, size_scale, + delta_x, delta_y)}, + {ImageStorage::TypeAction::Fly_up, + std::make_shared( + source / m_config_json["hero"]["animated"]["actions"]["fly_up"]["source"], + + m_config_json["hero"]["animated"]["actions"]["fly_up"]["delta_time"], + physical_size_width, physical_size_height, size_scale, + delta_x, delta_y)}, + {ImageStorage::TypeAction::Fall, + std::make_shared( + source / m_config_json["hero"]["animated"]["actions"]["fall"]["source"], + + m_config_json["hero"]["animated"]["actions"]["fall"]["delta_time"], + physical_size_width, physical_size_height, size_scale, + delta_x, delta_y)}, + {ImageStorage::TypeAction::Attack_1_beg, + std::make_shared( + source / m_config_json["hero"]["animated"]["actions"]["attack_1_beg"]["source"], + + m_config_json["hero"]["animated"]["actions"]["attack_1_beg"]["delta_time"], + physical_size_width, physical_size_height, size_scale, + delta_x, delta_y)}, + {ImageStorage::TypeAction::Attack_1_end, + std::make_shared( + source / m_config_json["hero"]["animated"]["actions"]["attack_1_end"]["source"], + + m_config_json["hero"]["animated"]["actions"]["attack_1_end"]["delta_time"], + physical_size_width, physical_size_height, size_scale, + delta_x, delta_y)}, + {ImageStorage::TypeAction::Attack_2_beg, + std::make_shared( + source / m_config_json["hero"]["animated"]["actions"]["attack_2_beg"]["source"], + + m_config_json["hero"]["animated"]["actions"]["attack_2_beg"]["delta_time"], + physical_size_width, physical_size_height, size_scale, + delta_x, delta_y)}, + {ImageStorage::TypeAction::Attack_2_end, + std::make_shared( + source / m_config_json["hero"]["animated"]["actions"]["attack_2_end"]["source"], + + m_config_json["hero"]["animated"]["actions"]["attack_2_end"]["delta_time"], + physical_size_width, physical_size_height, size_scale, + delta_x, delta_y)}, + {ImageStorage::TypeAction::Attack_3_beg, + std::make_shared( + source / m_config_json["hero"]["animated"]["actions"]["attack_3_beg"]["source"], + + m_config_json["hero"]["animated"]["actions"]["attack_3_beg"]["delta_time"], + physical_size_width, physical_size_height, size_scale, + delta_x, delta_y)}, + {ImageStorage::TypeAction::Attack_3_end, + std::make_shared( + source / m_config_json["hero"]["animated"]["actions"]["attack_3_end"]["source"], + + m_config_json["hero"]["animated"]["actions"]["attack_3_end"]["delta_time"], + physical_size_width, physical_size_height, size_scale, + delta_x, delta_y)}})); hero_id = world->create_physical_entity( 0, position, 0, image_storage, - false, false - ); + false, false); + + /// add sensor + auto m_entity = cast_to_or_null(world->get_storage().get_entity(hero_id)); + m_entity->add_sensor({0, 6}, 2.65, 0.05); + + float m_impulse = 2000; + float horizontal_velocity = 20; + + auto machine = std::make_shared(world, position, hero_id, level_dispatcher, m_impulse, horizontal_velocity); + controllers.push_back(machine); return hero_id; } + + void LevelLoaderFromFile::create_mob(std::shared_ptr world, Vec2d position) { + std::filesystem::path source(m_config_json["animated_resources"]); + source /= m_config_json["enemy"]["source"]; + + std::shared_ptr image_storage; + + float physical_size_width = m_config_json["enemy"]["animated"]["size_width"]; + float physical_size_height = m_config_json["enemy"]["animated"]["size_height"]; + float size_scale = m_config_json["enemy"]["animated"]["size_scale"]; + float delta_x = m_config_json["enemy"]["animated"]["delta_x"]; + float delta_y = m_config_json["enemy"]["animated"]["delta_y"]; + + + image_storage = std::make_shared( + std::unordered_map>( + {{ImageStorage::TypeAction::Idle, + std::make_shared( + source / m_config_json["enemy"]["animated"]["actions"]["idle"]["source"], + + m_config_json["enemy"]["animated"]["actions"]["idle"]["delta_time"], + physical_size_width, physical_size_height, size_scale, + delta_x, delta_y)}, + {ImageStorage::TypeAction::Run, + std::make_shared( + source / m_config_json["enemy"]["animated"]["actions"]["run"]["source"], + + m_config_json["enemy"]["animated"]["actions"]["run"]["delta_time"], + physical_size_width, physical_size_height, size_scale, + delta_x, delta_y)}, + {ImageStorage::TypeAction::Attack_1_beg, + std::make_shared( + source / m_config_json["enemy"]["animated"]["actions"]["attack_beg"]["source"], + + m_config_json["enemy"]["animated"]["actions"]["attack_beg"]["delta_time"], + physical_size_width, physical_size_height, size_scale, + delta_x, delta_y)}, + {ImageStorage::TypeAction::Attack_1_end, + std::make_shared( + source / m_config_json["enemy"]["animated"]["actions"]["attack_end"]["source"], + + m_config_json["hero"]["animated"]["actions"]["attack_end"]["delta_time"], + physical_size_width, physical_size_height, size_scale, + delta_x, delta_y)}})); + + Entity::Id enemy_id = world->create_physical_entity( + 0, + position, + 0, + image_storage, + false, false); + + + float m_impulse = 2000; + float horizontal_velocity = 20; + + auto machine = std::make_shared(world, position, enemy_id, level_dispatcher, m_impulse, horizontal_velocity); + controllers.push_back(machine); + } Entity::Id LevelLoaderFromFile::create_finish_block(std::shared_ptr world, Vec2d position, float block_size) { std::filesystem::path source("../../game/resources/static/"); source /= static_cast(m_config_json["texture"]["finish"]); @@ -219,16 +360,14 @@ namespace mad::core { {{ImageStorage::TypeAction::Idle, std::make_shared(source, block_size, block_size, - StaticImage::TransformType::Fit) - }})); + StaticImage::TransformType::Fit)}})); return world->create_physical_entity( 0, position, 0, image_storage, - true - ); + true); } void LevelLoaderFromFile::create_background(std::shared_ptr world) { @@ -243,17 +382,13 @@ namespace mad::core { std::make_shared( source, parallax_ratios, - m_config_json["background"]["scale"] - ) - }} - ) - ); + m_config_json["background"]["scale"])}})); world->create_viewable_entity( -1, {0, 0}, 0, - image_storage - ); + image_storage); } -} \ No newline at end of file + +}// namespace mad::core diff --git a/core/loader/LevelLoaderFromFile.hpp b/core/loader/LevelLoaderFromFile.hpp index 40d6a14..74688f9 100644 --- a/core/loader/LevelLoaderFromFile.hpp +++ b/core/loader/LevelLoaderFromFile.hpp @@ -107,6 +107,8 @@ namespace mad::core { Entity::Id create_hero(std::shared_ptr world, Vec2d position); + void create_mob(std::shared_ptr world, Vec2d position); + void create_background(std::shared_ptr world); Entity::Id create_finish_block(std::shared_ptr world, Vec2d position, float block_size); @@ -128,6 +130,10 @@ namespace mad::core { std::ifstream m_level_map; + std::vector> controllers; + + std::shared_ptr level_dispatcher; + std::unordered_map m_objects = { {'.', Objects::Empty}, {'#', Objects::StableBlock}, diff --git a/core/visual/image/animated/RenderableAnimatedSeveralFiles.cpp b/core/visual/image/animated/RenderableAnimatedSeveralFiles.cpp index 8e8868f..cb6353c 100644 --- a/core/visual/image/animated/RenderableAnimatedSeveralFiles.cpp +++ b/core/visual/image/animated/RenderableAnimatedSeveralFiles.cpp @@ -1,8 +1,9 @@ #include "RenderableAnimatedSeveralFiles.hpp" +#include "spdlog/spdlog.h" -#include #include #include +#include namespace mad::core { @@ -26,6 +27,7 @@ namespace mad::core { CHECK_THROW(texture.loadFromFile(file_name), FileDoesNotExist, "File with StaticImage doesn't exist"); m_textures.push_back(texture); + debug_m_textures_names.push_back(file_name); } m_current_frame = m_textures.size(); @@ -36,7 +38,7 @@ namespace mad::core { m_scale = {animated_image->get_size_scale(), animated_image->get_size_scale()}; - float outline = 1; + float outline = 0.2; m_physical_shape = sf::RectangleShape({animated_image->get_physical_width() - outline, animated_image->get_physical_height() - outline}); m_physical_shape.setOrigin((animated_image->get_physical_width() - outline) / 2, @@ -55,6 +57,10 @@ namespace mad::core { } sf::Sprite render_sprite; + if(debug_prev_name != debug_m_textures_names[m_current_frame]){ + debug_prev_name = debug_m_textures_names[m_current_frame]; + //SPDLOG_DEBUG("current frame name {}", debug_prev_name); + } render_sprite.setTexture(m_textures[m_current_frame]); if (*m_orientation == Image::Orientation::Left && m_scale.get_x() > 0 || diff --git a/core/visual/image/animated/RenderableAnimatedSeveralFiles.hpp b/core/visual/image/animated/RenderableAnimatedSeveralFiles.hpp index cdde1a1..c4d28e1 100644 --- a/core/visual/image/animated/RenderableAnimatedSeveralFiles.hpp +++ b/core/visual/image/animated/RenderableAnimatedSeveralFiles.hpp @@ -42,6 +42,12 @@ namespace mad::core { float m_delta_y; sf::RectangleShape m_physical_shape; + + int debug_prev_sprite_num = 0; + + std::vector debug_m_textures_names; + + std::string debug_prev_name; }; } diff --git a/core/visual/image/static/RenderableStatic.cpp b/core/visual/image/static/RenderableStatic.cpp index 8884430..35b97d1 100644 --- a/core/visual/image/static/RenderableStatic.cpp +++ b/core/visual/image/static/RenderableStatic.cpp @@ -32,7 +32,7 @@ namespace mad::core { } } - float outline = 1; + float outline = 0.2; m_physical_shape = sf::RectangleShape({static_image->get_width() - outline, static_image->get_height() - outline}); m_physical_shape.setOrigin((static_image->get_width() - outline) / 2, (static_image->get_height() - outline) / 2); diff --git a/core/visual/image/storage/ImageStorage.hpp b/core/visual/image/storage/ImageStorage.hpp index 5699096..59b4808 100644 --- a/core/visual/image/storage/ImageStorage.hpp +++ b/core/visual/image/storage/ImageStorage.hpp @@ -13,7 +13,16 @@ namespace mad::core { enum class TypeAction { Idle, Run, - Attack + Attack_1_beg, + Attack_1_end, + Attack_2_beg, + Attack_2_end, + Attack_3_beg, + Attack_3_end, + Jump, + Fly_up, + Fall, + }; explicit ImageStorage(std::unordered_map> actions); diff --git a/core/world/LocalWorld.cpp b/core/world/LocalWorld.cpp index b65987c..efa14c6 100644 --- a/core/world/LocalWorld.cpp +++ b/core/world/LocalWorld.cpp @@ -54,6 +54,9 @@ void mad::core::LocalWorld::produce(mad::core::EventDispatcher &dispatcher) { for (Entity::Id entity_id : m_storage.extract(TrueFilter())) { if (auto physical_entity = cast_to_or_null(m_storage.get_entity(entity_id)); physical_entity != nullptr) { physical_entity->synchronize_position_with_viewable(); + if(abs(physical_entity->get_linear_velocity().get_y()) > 0.01){ + //SPDLOG_DEBUG("vel {}", physical_entity->get_linear_velocity().get_y()); + } } } @@ -93,3 +96,6 @@ mad::core::Entity::Id mad::core::LocalWorld::create_physical_entity(int z_ind, m mad::core::Entity &mad::core::LocalWorld::get_entity(mad::core::Entity::Id id) noexcept { return m_storage.get_entity(id); } +mad::core::EntityStorage &mad::core::LocalWorld::get_storage() { + return m_storage; +} diff --git a/core/world/LocalWorld.hpp b/core/world/LocalWorld.hpp index 14c38a8..c517b0e 100644 --- a/core/world/LocalWorld.hpp +++ b/core/world/LocalWorld.hpp @@ -22,7 +22,7 @@ namespace mad::core { class LocalWorld : public World { public: - explicit LocalWorld(EventDispatcher &event_dispatcher, Vec2d gravitation_scale = {0, 30.0f}); + explicit LocalWorld(EventDispatcher &event_dispatcher, Vec2d gravitation_scale = {0, 40.0f}); bool manipulate(const Filter &filter, const Intent &intent) override; @@ -34,6 +34,8 @@ namespace mad::core { Entity::Id create_physical_entity(int z_ind, Vec2d initial_position, float initial_rotation, std::shared_ptr image_storage, bool is_fixed = false, bool is_rotated = true) override; + EntityStorage& get_storage(); + private: std::shared_ptr>> m_step_events_queue; diff --git a/core/world/entity/ContactListener/ContactListener.hpp b/core/world/entity/ContactListener/ContactListener.hpp index c4e0983..113a443 100644 --- a/core/world/entity/ContactListener/ContactListener.hpp +++ b/core/world/entity/ContactListener/ContactListener.hpp @@ -1,15 +1,23 @@ #ifndef MAD_CONTACTLISTENER_HPP #define MAD_CONTACTLISTENER_HPP +#include "event/physics/SensorCollision.hpp" +#include "event/physics/SensorCollisionEnd.hpp" +#include "spdlog/spdlog.h" #include -#include #include #include +#include namespace mad::core{ class MyContactListener : public b2ContactListener { void BeginContact(b2Contact *contact) override { - + ///sensors + b2FixtureUserData fixture_data_A = contact->GetFixtureA()->GetUserData(); + b2FixtureUserData fixture_data_B = contact->GetFixtureB()->GetUserData(); + if(static_cast(fixture_data_A.pointer) != 0) dispatcher.dispatch(std::make_shared(fixture_data_A.pointer)); + if(static_cast(fixture_data_B.pointer) != 0) dispatcher.dispatch(std::make_shared(fixture_data_B.pointer)); + ///bodies b2BodyUserData dataA = contact->GetFixtureA()->GetBody()->GetUserData(); b2BodyUserData dataB = contact->GetFixtureB()->GetBody()->GetUserData(); //std::cout << "!!! " << dataA.pointer << "\n"; @@ -24,15 +32,11 @@ namespace mad::core{ void EndContact(b2Contact* contact) override{ - /*//check if fixture A was a ball - void* bodyUserData = contact->GetFixtureA()->GetBody()->GetUserData(); - if ( bodyUserData ) - static_cast( bodyUserData )->endContact(); - - //check if fixture B was a ball - bodyUserData = contact->GetFixtureB()->GetBody()->GetUserData(); - if ( bodyUserData ) - static_cast( bodyUserData )->endContact();*/ + ///sensors + b2FixtureUserData fixture_data_A = contact->GetFixtureA()->GetUserData(); + b2FixtureUserData fixture_data_B = contact->GetFixtureB()->GetUserData(); + if(static_cast(fixture_data_A.pointer) != 0) dispatcher.dispatch(std::make_shared(fixture_data_A.pointer)); + if(static_cast(fixture_data_B.pointer) != 0) dispatcher.dispatch(std::make_shared(fixture_data_B.pointer)); } diff --git a/core/world/entity/PhysicalEntity.cpp b/core/world/entity/PhysicalEntity.cpp index 9b58177..d62eb10 100644 --- a/core/world/entity/PhysicalEntity.cpp +++ b/core/world/entity/PhysicalEntity.cpp @@ -37,8 +37,10 @@ mad::core::PhysicalEntity::PhysicalEntity(std::int32_t id, int z_ind, Vec2d init b2FixtureDef fixtureDef; fixtureDef.shape = &dynamicBox; fixtureDef.density = 1.0f; - fixtureDef.friction = 0.3f; - fixtureDef.restitution = 0.2f; + fixtureDef.friction = 0.0f; + fixtureDef.restitution = 0.0f; + body->SetLinearDamping(0); + body->SetAngularDamping(0); body->CreateFixture(&fixtureDef); body->SetTransform(body->GetPosition(), initial_rotation); @@ -69,6 +71,10 @@ void mad::core::PhysicalEntity::apply_force_to_center(mad::core::Vec2d force, ma void mad::core::PhysicalEntity::set_linear_velocity(mad::core::Vec2d velocity, mad::core::EventDispatcher &dispatcher) { body->SetLinearVelocity(velocity); } +void mad::core::PhysicalEntity::set_linear_horizontal_velocity(float velocity, mad::core::EventDispatcher &dispatcher) { + body->SetLinearVelocity({velocity, body->GetLinearVelocity().y}); +} + void mad::core::PhysicalEntity::apply_angular_impulse(float impulse, mad::core::EventDispatcher &dispatcher, bool awake) { body->ApplyAngularImpulse(impulse, awake); } @@ -154,3 +160,12 @@ mad::core::Vec2d mad::core::PhysicalEntity::get_local_center() { mad::core::Vec2d mad::core::PhysicalEntity::get_world_center() { return {body->GetWorldCenter().x, body->GetWorldCenter().y}; } +void mad::core::PhysicalEntity::add_sensor(b2Vec2 offset, float x_size, float y_size) { + b2FixtureDef FixtureDef; + b2PolygonShape fixture; + fixture.SetAsBox(x_size, y_size, offset, 0); + FixtureDef.shape = &fixture; + FixtureDef.isSensor = true; + b2Fixture* footSensorFixture = body->CreateFixture(&FixtureDef); + footSensorFixture->GetUserData().pointer = m_id; +} diff --git a/core/world/entity/PhysicalEntity.hpp b/core/world/entity/PhysicalEntity.hpp index fff81c2..14fcaff 100644 --- a/core/world/entity/PhysicalEntity.hpp +++ b/core/world/entity/PhysicalEntity.hpp @@ -45,6 +45,7 @@ namespace mad::core { void apply_angular_impulse(float impulse, EventDispatcher &dispatcher, bool awake = true); void apply_torque(float torque, EventDispatcher &dispatcher, bool awake = true); void set_linear_velocity(Vec2d velocity, EventDispatcher &dispatcher); + void set_linear_horizontal_velocity(float velocity, EventDispatcher &dispatcher); void set_angular_velocity(float velocity, EventDispatcher &dispatcher); void set_linear_damping(float linear_damping, EventDispatcher &dispatcher); void set_angular_damping(float angular_damping, EventDispatcher &dispatcher); @@ -78,6 +79,8 @@ namespace mad::core { void synchronize_position_with_viewable(); + void add_sensor(b2Vec2 offset, float x_size, float y_size); + private: b2Body *body; diff --git a/game/mobs/hero/Hero.cpp b/game/mobs/hero/Hero.cpp new file mode 100644 index 0000000..0440854 --- /dev/null +++ b/game/mobs/hero/Hero.cpp @@ -0,0 +1,258 @@ +#include "Hero.hpp" +#include "event/management/condition/EndAnimationCondition.hpp" +#include "event/management/condition/FallCondition.hpp" +#include "event/management/condition/KeyDownCondition.hpp" +#include "event/management/condition/KeyPressedCondition.hpp" +#include "event/management/condition/KeyReleasedCondition.hpp" +#include "event/management/condition/LastStateCondition.hpp" +#include "event/management/condition/SensorCondition.hpp" +#include "event/management/condition/SensorEndCondition.hpp" +#include "event/management/condition/TimerCondition.hpp" +#include "event/management/condition/TrueCondition.hpp" +#include "event/management/controller/Attack.hpp" +#include "event/management/controller/Fall.hpp" +#include "event/management/controller/FlyUp.hpp" +#include "event/management/controller/GroundMovement.hpp" +#include "event/management/controller/JumpImpulse.hpp" +#include "event/management/controller/Movement.hpp" +#include "event/management/controller/StartJump.hpp" +#include "event/management/controller/statemachine/StateMachine.hpp" +mad::core::Hero::Hero(std::shared_ptr world, Vec2d position, json m_config_json, std::shared_ptr level_dispatcher, std::vector> &controllers) : level_dispatcher(level_dispatcher){ + std::filesystem::path source(m_config_json["animated_resources"]); + source /= m_config_json["hero"]["source"]; + + std::shared_ptr image_storage; + + float physical_size_width = m_config_json["hero"]["animated"]["size_width"]; + float physical_size_height = m_config_json["hero"]["animated"]["size_height"]; + float size_scale = m_config_json["hero"]["animated"]["size_scale"]; + float delta_x = m_config_json["hero"]["animated"]["delta_x"]; + float delta_y = m_config_json["hero"]["animated"]["delta_y"]; + + + image_storage = std::make_shared( + std::unordered_map>( + {{ImageStorage::TypeAction::Idle, + std::make_shared( + source / m_config_json["hero"]["animated"]["actions"]["idle"]["source"], + + m_config_json["hero"]["animated"]["actions"]["idle"]["delta_time"], + physical_size_width, physical_size_height, size_scale, + delta_x, delta_y)}, + {ImageStorage::TypeAction::Run, + std::make_shared( + source / m_config_json["hero"]["animated"]["actions"]["run"]["source"], + + m_config_json["hero"]["animated"]["actions"]["run"]["delta_time"], + physical_size_width, physical_size_height, size_scale, + delta_x, delta_y)}, + {ImageStorage::TypeAction::Jump, + std::make_shared( + source / m_config_json["hero"]["animated"]["actions"]["jump"]["source"], + + m_config_json["hero"]["animated"]["actions"]["jump"]["delta_time"], + physical_size_width, physical_size_height, size_scale, + delta_x, delta_y)}, + {ImageStorage::TypeAction::Fly_up, + std::make_shared( + source / m_config_json["hero"]["animated"]["actions"]["fly_up"]["source"], + + m_config_json["hero"]["animated"]["actions"]["fly_up"]["delta_time"], + physical_size_width, physical_size_height, size_scale, + delta_x, delta_y)}, + {ImageStorage::TypeAction::Fall, + std::make_shared( + source / m_config_json["hero"]["animated"]["actions"]["fall"]["source"], + + m_config_json["hero"]["animated"]["actions"]["fall"]["delta_time"], + physical_size_width, physical_size_height, size_scale, + delta_x, delta_y)}, + {ImageStorage::TypeAction::Attack_1_beg, + std::make_shared( + source / m_config_json["hero"]["animated"]["actions"]["attack_1_beg"]["source"], + + m_config_json["hero"]["animated"]["actions"]["attack_1_beg"]["delta_time"], + physical_size_width, physical_size_height, size_scale, + delta_x, delta_y)}, + {ImageStorage::TypeAction::Attack_1_end, + std::make_shared( + source / m_config_json["hero"]["animated"]["actions"]["attack_1_end"]["source"], + + m_config_json["hero"]["animated"]["actions"]["attack_1_end"]["delta_time"], + physical_size_width, physical_size_height, size_scale, + delta_x, delta_y)}, + {ImageStorage::TypeAction::Attack_2_beg, + std::make_shared( + source / m_config_json["hero"]["animated"]["actions"]["attack_2_beg"]["source"], + + m_config_json["hero"]["animated"]["actions"]["attack_2_beg"]["delta_time"], + physical_size_width, physical_size_height, size_scale, + delta_x, delta_y)}, + {ImageStorage::TypeAction::Attack_2_end, + std::make_shared( + source / m_config_json["hero"]["animated"]["actions"]["attack_2_end"]["source"], + + m_config_json["hero"]["animated"]["actions"]["attack_2_end"]["delta_time"], + physical_size_width, physical_size_height, size_scale, + delta_x, delta_y)}, + {ImageStorage::TypeAction::Attack_3_beg, + std::make_shared( + source / m_config_json["hero"]["animated"]["actions"]["attack_3_beg"]["source"], + + m_config_json["hero"]["animated"]["actions"]["attack_3_beg"]["delta_time"], + physical_size_width, physical_size_height, size_scale, + delta_x, delta_y)}, + {ImageStorage::TypeAction::Attack_3_end, + std::make_shared( + source / m_config_json["hero"]["animated"]["actions"]["attack_3_end"]["source"], + + m_config_json["hero"]["animated"]["actions"]["attack_3_end"]["delta_time"], + physical_size_width, physical_size_height, size_scale, + delta_x, delta_y)} + } + )); + + hero_id = world->create_physical_entity( + 0, + position, + 0, + image_storage, + false, false + ); + + + ///State Machine + struct C1 : mad::core::Controller { + void control() override { + //SPDLOG_DEBUG("controller 1"); + }; + }; + struct C2 : mad::core::Controller { + void control() override { + //SPDLOG_DEBUG("controller 2"); + }; + }; + auto machine = std::make_shared( + std::shared_ptr(level_dispatcher)); + StateMachine::StateId ground_idle = machine->add_state(std::make_shared(world, hero_id, Movement::Direction::Idle)); + StateMachine::StateId ground_right = machine->add_state(std::make_shared(world, hero_id, Movement::Direction::Right, horizontal_velocity)); + StateMachine::StateId ground_left = machine->add_state(std::make_shared(world, hero_id, Movement::Direction::Left, horizontal_velocity)); + StateMachine::StateId jump_impulse = machine->add_state(std::make_shared(world, hero_id, m_impulse)); + StateMachine::StateId start_jump_left = machine->add_state(std::make_shared(world, hero_id, Movement::Direction::Left, horizontal_velocity)); + StateMachine::StateId start_jump_idle = machine->add_state(std::make_shared(world, hero_id, Movement::Direction::Idle, horizontal_velocity)); + StateMachine::StateId start_jump_right = machine->add_state(std::make_shared(world, hero_id, Movement::Direction::Right, horizontal_velocity)); + StateMachine::StateId fly_up_left = machine->add_state(std::make_shared(world, hero_id, Movement::Direction::Left, horizontal_velocity)); /// 7 + StateMachine::StateId fly_up_idle = machine->add_state(std::make_shared(world, hero_id, Movement::Direction::Idle, horizontal_velocity)); + StateMachine::StateId fly_up_right = machine->add_state(std::make_shared(world, hero_id, Movement::Direction::Right, horizontal_velocity)); + StateMachine::StateId fall_left = machine->add_state(std::make_shared(world, hero_id, Movement::Direction::Left, horizontal_velocity)); /// 10 + StateMachine::StateId fall_idle = machine->add_state(std::make_shared(world, hero_id, Movement::Direction::Idle, horizontal_velocity)); + StateMachine::StateId fall_right= machine->add_state(std::make_shared(world, hero_id, Movement::Direction::Right, horizontal_velocity)); + int *attack_stage = new int(0); + StateMachine::StateId attack_left = machine->add_state(std::make_shared(world, hero_id, Movement::Direction::Left, attack_stage, horizontal_velocity)); + StateMachine::StateId attack_idle= machine->add_state(std::make_shared(world, hero_id, Movement::Direction::Idle, attack_stage, horizontal_velocity)); + StateMachine::StateId attack_right = machine->add_state(std::make_shared(world, hero_id, Movement::Direction::Right, attack_stage, horizontal_velocity)); + + machine->add_transition(ground_idle, ground_right, std::make_shared(sf::Keyboard::Right)); + machine->add_transition(ground_idle, ground_left, std::make_shared(sf::Keyboard::Left)); + machine->add_transition(ground_right, ground_idle, std::make_shared(sf::Keyboard::Right)); + machine->add_transition(ground_left, ground_idle, std::make_shared(sf::Keyboard::Left)); + machine->add_transition(ground_right, ground_left, std::make_shared(sf::Keyboard::Left)); + machine->add_transition(ground_left, ground_right, std::make_shared(sf::Keyboard::Right)); + machine->add_transition(ground_idle, jump_impulse, std::make_shared(sf::Keyboard::Space)); + machine->add_transition(ground_right, jump_impulse, std::make_shared(sf::Keyboard::Space)); + machine->add_transition(ground_left, jump_impulse, std::make_shared(sf::Keyboard::Space)); + + machine->add_transition(jump_impulse, start_jump_idle, std::make_shared()); + machine->add_transition(start_jump_idle, start_jump_left , std::make_shared(sf::Keyboard::Left)); + machine->add_transition(start_jump_idle, start_jump_right, std::make_shared(sf::Keyboard::Right)); + machine->add_transition(start_jump_left , start_jump_idle, std::make_shared(sf::Keyboard::Left)); + machine->add_transition(start_jump_right, start_jump_idle, std::make_shared(sf::Keyboard::Right)); + + + machine->add_transition(start_jump_left , fly_up_idle, std::make_shared(hero_id, ImageStorage::TypeAction::Jump)); + machine->add_transition(start_jump_idle, fly_up_idle, std::make_shared(hero_id, ImageStorage::TypeAction::Jump)); + machine->add_transition(start_jump_right, fly_up_idle, std::make_shared(hero_id, ImageStorage::TypeAction::Jump)); + + machine->add_transition(fly_up_idle, fly_up_left, std::make_shared(sf::Keyboard::Left)); + machine->add_transition(fly_up_idle, fly_up_right, std::make_shared(sf::Keyboard::Right)); + machine->add_transition(fly_up_left, fly_up_idle, std::make_shared(sf::Keyboard::Left)); + machine->add_transition(fly_up_right, fly_up_idle, std::make_shared(sf::Keyboard::Right)); + + machine->add_transition(fly_up_left, fall_idle, std::make_shared(world, hero_id, 0)); + machine->add_transition(fly_up_idle, fall_idle, std::make_shared(world, hero_id, 0)); + machine->add_transition(fly_up_right, fall_idle, std::make_shared(world, hero_id, 0)); + + machine->add_transition(ground_left, fall_idle, std::vector>{std::make_shared(world, hero_id, 0.1), std::make_shared(hero_id, 0.2)}); + machine->add_transition(ground_idle, fall_idle, std::vector>{std::make_shared(world, hero_id, 0.1), std::make_shared(hero_id, 0.2)}); + machine->add_transition(ground_right, fall_idle, std::vector>{std::make_shared(world, hero_id, 0.1), std::make_shared(hero_id, 0.2)}); + + machine->add_transition(fall_idle, fall_left, std::make_shared(sf::Keyboard::Left)); + machine->add_transition(fall_idle, fall_right, std::make_shared(sf::Keyboard::Right)); + machine->add_transition(fall_left, fall_idle, std::make_shared(sf::Keyboard::Left)); + machine->add_transition(fall_right, fall_idle, std::make_shared(sf::Keyboard::Right)); + + machine->add_transition(fall_left, ground_idle, std::make_shared(hero_id)); + machine->add_transition(fall_idle, ground_idle, std::make_shared(hero_id)); + machine->add_transition(fall_right, ground_idle, std::make_shared(hero_id)); + + + machine->add_transition(ground_left, attack_idle, std::make_shared(sf::Keyboard::Q)); + machine->add_transition(ground_idle, attack_idle, std::make_shared(sf::Keyboard::Q)); + machine->add_transition(ground_right, attack_idle, std::make_shared(sf::Keyboard::Q)); + machine->add_transition(start_jump_left, attack_idle, std::make_shared(sf::Keyboard::Q)); + machine->add_transition(start_jump_idle, attack_idle, std::make_shared(sf::Keyboard::Q)); + machine->add_transition(start_jump_right, attack_idle, std::make_shared(sf::Keyboard::Q)); + machine->add_transition(fly_up_left, attack_idle, std::make_shared(sf::Keyboard::Q)); + machine->add_transition(fly_up_idle, attack_idle, std::make_shared(sf::Keyboard::Q)); + machine->add_transition(fly_up_right, attack_idle, std::make_shared(sf::Keyboard::Q)); + machine->add_transition(fall_left, attack_idle, std::make_shared(sf::Keyboard::Q)); + machine->add_transition(fall_idle, attack_idle, std::make_shared(sf::Keyboard::Q)); + machine->add_transition(fall_right, attack_idle, std::make_shared(sf::Keyboard::Q)); + + machine->add_transition(attack_idle, attack_left, std::make_shared(sf::Keyboard::Left)); + machine->add_transition(attack_left, attack_idle, std::make_shared(sf::Keyboard::Left)); + machine->add_transition(attack_idle, attack_right, std::make_shared(sf::Keyboard::Right)); + machine->add_transition(attack_right, attack_idle, std::make_shared(sf::Keyboard::Right)); + + machine->add_transition(attack_idle, attack_idle, std::make_shared(hero_id, ImageStorage::TypeAction::Attack_1_beg, attack_stage)); + machine->add_transition(attack_left, attack_idle, std::make_shared(hero_id, ImageStorage::TypeAction::Attack_1_beg, attack_stage)); + machine->add_transition(attack_right, attack_idle, std::make_shared(hero_id, ImageStorage::TypeAction::Attack_1_beg, attack_stage)); + + machine->add_transition(attack_left, ground_idle, std::make_shared(hero_id, ImageStorage::TypeAction::Attack_1_end, attack_stage)); + machine->add_transition(attack_idle, ground_idle, std::make_shared(hero_id, ImageStorage::TypeAction::Attack_1_end, attack_stage)); + machine->add_transition(attack_right, ground_idle, std::make_shared(hero_id, ImageStorage::TypeAction::Attack_1_end, attack_stage)); + + machine->add_transition(attack_idle, attack_idle, std::make_shared(hero_id, ImageStorage::TypeAction::Attack_2_beg, attack_stage)); + machine->add_transition(attack_left, attack_idle, std::make_shared(hero_id, ImageStorage::TypeAction::Attack_2_beg, attack_stage)); + machine->add_transition(attack_right, attack_idle, std::make_shared(hero_id, ImageStorage::TypeAction::Attack_2_beg, attack_stage)); + + machine->add_transition(attack_left, ground_idle, std::make_shared(hero_id, ImageStorage::TypeAction::Attack_2_end, attack_stage)); + machine->add_transition(attack_idle, ground_idle, std::make_shared(hero_id, ImageStorage::TypeAction::Attack_2_end, attack_stage)); + machine->add_transition(attack_right, ground_idle, std::make_shared(hero_id, ImageStorage::TypeAction::Attack_2_end, attack_stage)); + + machine->add_transition(attack_idle, attack_idle, std::make_shared(hero_id, ImageStorage::TypeAction::Attack_3_beg, attack_stage)); + machine->add_transition(attack_left, attack_idle, std::make_shared(hero_id, ImageStorage::TypeAction::Attack_3_beg, attack_stage)); + machine->add_transition(attack_right, attack_idle, std::make_shared(hero_id, ImageStorage::TypeAction::Attack_3_beg, attack_stage)); + + machine->add_transition(attack_left, ground_idle, std::make_shared(hero_id, ImageStorage::TypeAction::Attack_3_end, attack_stage)); + machine->add_transition(attack_idle, ground_idle, std::make_shared(hero_id, ImageStorage::TypeAction::Attack_3_end, attack_stage)); + machine->add_transition(attack_right, ground_idle, std::make_shared(hero_id, ImageStorage::TypeAction::Attack_3_end, attack_stage)); + + + + + + + + + machine->set_initial_state(0); + controllers.push_back(machine); + + + /// add sensor + auto m_entity = cast_to_or_null(world->get_storage().get_entity(hero_id)); + m_entity->add_sensor({0, 6}, 2.65, 0.05); +} +mad::core::Entity::Id mad::core::Hero::get_hero_id() const { + return hero_id; +} diff --git a/game/mobs/hero/Hero.hpp b/game/mobs/hero/Hero.hpp new file mode 100644 index 0000000..11df06c --- /dev/null +++ b/game/mobs/hero/Hero.hpp @@ -0,0 +1,23 @@ +#ifndef MAD_HERO_HPP +#define MAD_HERO_HPP + +#include "loader/LevelLoaderFromFile.hpp" +#include "world/LocalWorld.hpp" +#include +#include "world/entity/PhysicalEntity.hpp" +#include +namespace mad::core { + class Hero { + public: + Hero(std::shared_ptr world, Vec2d position, json m_config_json, std::shared_ptr level_dispatcher, std::vector> &controllers); + Entity::Id get_hero_id() const; + + private: + Entity::Id hero_id; + std::shared_ptr level_dispatcher; + float horizontal_velocity = 20; + float m_impulse = 2000; + }; +}// namespace mad::core + +#endif//MAD_HERO_HPP diff --git a/game/resources/animated/enemy/enemy_attack_beg/slime-attack-0.png b/game/resources/animated/enemy/enemy_attack_beg/slime-attack-0.png new file mode 100644 index 0000000..b0c4d39 Binary files /dev/null and b/game/resources/animated/enemy/enemy_attack_beg/slime-attack-0.png differ diff --git a/game/resources/animated/enemy/enemy_attack_beg/slime-attack-1.png b/game/resources/animated/enemy/enemy_attack_beg/slime-attack-1.png new file mode 100644 index 0000000..bc0d17f Binary files /dev/null and b/game/resources/animated/enemy/enemy_attack_beg/slime-attack-1.png differ diff --git a/game/resources/animated/enemy/enemy_attack_beg/slime-attack-2.png b/game/resources/animated/enemy/enemy_attack_beg/slime-attack-2.png new file mode 100644 index 0000000..716ff73 Binary files /dev/null and b/game/resources/animated/enemy/enemy_attack_beg/slime-attack-2.png differ diff --git a/game/resources/animated/enemy/enemy_attack_beg/slime-attack-3.png b/game/resources/animated/enemy/enemy_attack_beg/slime-attack-3.png new file mode 100644 index 0000000..4d6ca49 Binary files /dev/null and b/game/resources/animated/enemy/enemy_attack_beg/slime-attack-3.png differ diff --git a/game/resources/animated/enemy/enemy_attack_end/slime-attack-4.png b/game/resources/animated/enemy/enemy_attack_end/slime-attack-4.png new file mode 100644 index 0000000..025a660 Binary files /dev/null and b/game/resources/animated/enemy/enemy_attack_end/slime-attack-4.png differ diff --git a/game/resources/animated/enemy/enemy_idle/slime-idle-0.png b/game/resources/animated/enemy/enemy_idle/slime-idle-0.png new file mode 100644 index 0000000..237a1e0 Binary files /dev/null and b/game/resources/animated/enemy/enemy_idle/slime-idle-0.png differ diff --git a/game/resources/animated/enemy/enemy_idle/slime-idle-1.png b/game/resources/animated/enemy/enemy_idle/slime-idle-1.png new file mode 100644 index 0000000..4b4ad8d Binary files /dev/null and b/game/resources/animated/enemy/enemy_idle/slime-idle-1.png differ diff --git a/game/resources/animated/enemy/enemy_idle/slime-idle-2.png b/game/resources/animated/enemy/enemy_idle/slime-idle-2.png new file mode 100644 index 0000000..34383a0 Binary files /dev/null and b/game/resources/animated/enemy/enemy_idle/slime-idle-2.png differ diff --git a/game/resources/animated/enemy/enemy_idle/slime-idle-3.png b/game/resources/animated/enemy/enemy_idle/slime-idle-3.png new file mode 100644 index 0000000..fb4ac77 Binary files /dev/null and b/game/resources/animated/enemy/enemy_idle/slime-idle-3.png differ diff --git a/game/resources/animated/enemy/enemy_run/slime-move-0.png b/game/resources/animated/enemy/enemy_run/slime-move-0.png new file mode 100644 index 0000000..f4d5451 Binary files /dev/null and b/game/resources/animated/enemy/enemy_run/slime-move-0.png differ diff --git a/game/resources/animated/enemy/enemy_run/slime-move-1.png b/game/resources/animated/enemy/enemy_run/slime-move-1.png new file mode 100644 index 0000000..440c9f5 Binary files /dev/null and b/game/resources/animated/enemy/enemy_run/slime-move-1.png differ diff --git a/game/resources/animated/enemy/enemy_run/slime-move-2.png b/game/resources/animated/enemy/enemy_run/slime-move-2.png new file mode 100644 index 0000000..327fb4a Binary files /dev/null and b/game/resources/animated/enemy/enemy_run/slime-move-2.png differ diff --git a/game/resources/animated/enemy/enemy_run/slime-move-3.png b/game/resources/animated/enemy/enemy_run/slime-move-3.png new file mode 100644 index 0000000..ef83926 Binary files /dev/null and b/game/resources/animated/enemy/enemy_run/slime-move-3.png differ diff --git a/game/resources/animated/hero/hero_attack_1_beg/adventurer-attack1-00.png b/game/resources/animated/hero/hero_attack_1_beg/adventurer-attack1-00.png new file mode 100644 index 0000000..893cbe1 Binary files /dev/null and b/game/resources/animated/hero/hero_attack_1_beg/adventurer-attack1-00.png differ diff --git a/game/resources/animated/hero/hero_attack_1_beg/adventurer-attack1-01.png b/game/resources/animated/hero/hero_attack_1_beg/adventurer-attack1-01.png new file mode 100644 index 0000000..893cbe1 Binary files /dev/null and b/game/resources/animated/hero/hero_attack_1_beg/adventurer-attack1-01.png differ diff --git a/game/resources/animated/hero/hero_attack_1_beg/adventurer-attack1-02.png b/game/resources/animated/hero/hero_attack_1_beg/adventurer-attack1-02.png new file mode 100644 index 0000000..d5d52cf Binary files /dev/null and b/game/resources/animated/hero/hero_attack_1_beg/adventurer-attack1-02.png differ diff --git a/game/resources/animated/hero/hero_attack_1_beg/adventurer-attack1-03.png b/game/resources/animated/hero/hero_attack_1_beg/adventurer-attack1-03.png new file mode 100644 index 0000000..d5d52cf Binary files /dev/null and b/game/resources/animated/hero/hero_attack_1_beg/adventurer-attack1-03.png differ diff --git a/game/resources/animated/hero/hero_attack_1_beg/adventurer-attack1-04.png b/game/resources/animated/hero/hero_attack_1_beg/adventurer-attack1-04.png new file mode 100644 index 0000000..00f6001 Binary files /dev/null and b/game/resources/animated/hero/hero_attack_1_beg/adventurer-attack1-04.png differ diff --git a/game/resources/animated/hero/hero_attack_1_end/adventurer-attack1-02.png b/game/resources/animated/hero/hero_attack_1_end/adventurer-attack1-02.png new file mode 100644 index 0000000..00f6001 Binary files /dev/null and b/game/resources/animated/hero/hero_attack_1_end/adventurer-attack1-02.png differ diff --git a/game/resources/animated/hero/hero_attack_1_end/adventurer-attack1-03.png b/game/resources/animated/hero/hero_attack_1_end/adventurer-attack1-03.png new file mode 100644 index 0000000..3704560 Binary files /dev/null and b/game/resources/animated/hero/hero_attack_1_end/adventurer-attack1-03.png differ diff --git a/game/resources/animated/hero/hero_attack_1_end/adventurer-attack1-04.png b/game/resources/animated/hero/hero_attack_1_end/adventurer-attack1-04.png new file mode 100644 index 0000000..3704560 Binary files /dev/null and b/game/resources/animated/hero/hero_attack_1_end/adventurer-attack1-04.png differ diff --git a/game/resources/animated/hero/hero_attack_1_end/adventurer-attack1-05.png b/game/resources/animated/hero/hero_attack_1_end/adventurer-attack1-05.png new file mode 100644 index 0000000..7f4983a Binary files /dev/null and b/game/resources/animated/hero/hero_attack_1_end/adventurer-attack1-05.png differ diff --git a/game/resources/animated/hero/hero_attack_1_end/adventurer-attack1-06.png b/game/resources/animated/hero/hero_attack_1_end/adventurer-attack1-06.png new file mode 100644 index 0000000..7f4983a Binary files /dev/null and b/game/resources/animated/hero/hero_attack_1_end/adventurer-attack1-06.png differ diff --git a/game/resources/animated/hero/hero_attack_2_beg/adventurer-attack2-00.png b/game/resources/animated/hero/hero_attack_2_beg/adventurer-attack2-00.png new file mode 100644 index 0000000..38e8301 Binary files /dev/null and b/game/resources/animated/hero/hero_attack_2_beg/adventurer-attack2-00.png differ diff --git a/game/resources/animated/hero/hero_attack_2_beg/adventurer-attack2-000.png b/game/resources/animated/hero/hero_attack_2_beg/adventurer-attack2-000.png new file mode 100644 index 0000000..38e8301 Binary files /dev/null and b/game/resources/animated/hero/hero_attack_2_beg/adventurer-attack2-000.png differ diff --git a/game/resources/animated/hero/hero_attack_2_beg/adventurer-attack2-01.png b/game/resources/animated/hero/hero_attack_2_beg/adventurer-attack2-01.png new file mode 100644 index 0000000..a237738 Binary files /dev/null and b/game/resources/animated/hero/hero_attack_2_beg/adventurer-attack2-01.png differ diff --git a/game/resources/animated/hero/hero_attack_2_beg/adventurer-attack2-02.png b/game/resources/animated/hero/hero_attack_2_beg/adventurer-attack2-02.png new file mode 100644 index 0000000..a237738 Binary files /dev/null and b/game/resources/animated/hero/hero_attack_2_beg/adventurer-attack2-02.png differ diff --git a/game/resources/animated/hero/hero_attack_2_beg/adventurer-attack2-03.png b/game/resources/animated/hero/hero_attack_2_beg/adventurer-attack2-03.png new file mode 100644 index 0000000..18e53fc Binary files /dev/null and b/game/resources/animated/hero/hero_attack_2_beg/adventurer-attack2-03.png differ diff --git a/game/resources/animated/hero/hero_attack_2_beg/adventurer-attack2-04.png b/game/resources/animated/hero/hero_attack_2_beg/adventurer-attack2-04.png new file mode 100644 index 0000000..18e53fc Binary files /dev/null and b/game/resources/animated/hero/hero_attack_2_beg/adventurer-attack2-04.png differ diff --git a/game/resources/animated/hero/hero_attack_2_beg/adventurer-attack2-05.png b/game/resources/animated/hero/hero_attack_2_beg/adventurer-attack2-05.png new file mode 100644 index 0000000..5e807d5 Binary files /dev/null and b/game/resources/animated/hero/hero_attack_2_beg/adventurer-attack2-05.png differ diff --git a/game/resources/animated/hero/hero_attack_2_end/adventurer-attack2-03.png b/game/resources/animated/hero/hero_attack_2_end/adventurer-attack2-03.png new file mode 100644 index 0000000..5e807d5 Binary files /dev/null and b/game/resources/animated/hero/hero_attack_2_end/adventurer-attack2-03.png differ diff --git a/game/resources/animated/hero/hero_attack_2_end/adventurer-attack2-04.png b/game/resources/animated/hero/hero_attack_2_end/adventurer-attack2-04.png new file mode 100644 index 0000000..7495386 Binary files /dev/null and b/game/resources/animated/hero/hero_attack_2_end/adventurer-attack2-04.png differ diff --git a/game/resources/animated/hero/hero_attack_2_end/adventurer-attack2-05.png b/game/resources/animated/hero/hero_attack_2_end/adventurer-attack2-05.png new file mode 100644 index 0000000..7495386 Binary files /dev/null and b/game/resources/animated/hero/hero_attack_2_end/adventurer-attack2-05.png differ diff --git a/game/resources/animated/hero/hero_attack_2_end/adventurer-attack2-06.png b/game/resources/animated/hero/hero_attack_2_end/adventurer-attack2-06.png new file mode 100644 index 0000000..95b51a4 Binary files /dev/null and b/game/resources/animated/hero/hero_attack_2_end/adventurer-attack2-06.png differ diff --git a/game/resources/animated/hero/hero_attack_2_end/adventurer-attack2-07.png b/game/resources/animated/hero/hero_attack_2_end/adventurer-attack2-07.png new file mode 100644 index 0000000..95b51a4 Binary files /dev/null and b/game/resources/animated/hero/hero_attack_2_end/adventurer-attack2-07.png differ diff --git a/game/resources/animated/hero/hero_attack_3_beg/adventurer-attack3-00.png b/game/resources/animated/hero/hero_attack_3_beg/adventurer-attack3-00.png new file mode 100644 index 0000000..99b6794 Binary files /dev/null and b/game/resources/animated/hero/hero_attack_3_beg/adventurer-attack3-00.png differ diff --git a/game/resources/animated/hero/hero_attack_3_beg/adventurer-attack3-01.png b/game/resources/animated/hero/hero_attack_3_beg/adventurer-attack3-01.png new file mode 100644 index 0000000..99b6794 Binary files /dev/null and b/game/resources/animated/hero/hero_attack_3_beg/adventurer-attack3-01.png differ diff --git a/game/resources/animated/hero/hero_attack_3_beg/adventurer-attack3-02.png b/game/resources/animated/hero/hero_attack_3_beg/adventurer-attack3-02.png new file mode 100644 index 0000000..02eca0d Binary files /dev/null and b/game/resources/animated/hero/hero_attack_3_beg/adventurer-attack3-02.png differ diff --git a/game/resources/animated/hero/hero_attack_3_beg/adventurer-attack3-03.png b/game/resources/animated/hero/hero_attack_3_beg/adventurer-attack3-03.png new file mode 100644 index 0000000..02eca0d Binary files /dev/null and b/game/resources/animated/hero/hero_attack_3_beg/adventurer-attack3-03.png differ diff --git a/game/resources/animated/hero/hero_attack_3_beg/adventurer-attack3-04.png b/game/resources/animated/hero/hero_attack_3_beg/adventurer-attack3-04.png new file mode 100644 index 0000000..40901e1 Binary files /dev/null and b/game/resources/animated/hero/hero_attack_3_beg/adventurer-attack3-04.png differ diff --git a/game/resources/animated/hero/hero_attack_3_end/adventurer-attack3-02.png b/game/resources/animated/hero/hero_attack_3_end/adventurer-attack3-02.png new file mode 100644 index 0000000..40901e1 Binary files /dev/null and b/game/resources/animated/hero/hero_attack_3_end/adventurer-attack3-02.png differ diff --git a/game/resources/animated/hero/hero_attack_3_end/adventurer-attack3-03.png b/game/resources/animated/hero/hero_attack_3_end/adventurer-attack3-03.png new file mode 100644 index 0000000..22462fa Binary files /dev/null and b/game/resources/animated/hero/hero_attack_3_end/adventurer-attack3-03.png differ diff --git a/game/resources/animated/hero/hero_attack_3_end/adventurer-attack3-04.png b/game/resources/animated/hero/hero_attack_3_end/adventurer-attack3-04.png new file mode 100644 index 0000000..22462fa Binary files /dev/null and b/game/resources/animated/hero/hero_attack_3_end/adventurer-attack3-04.png differ diff --git a/game/resources/animated/hero/hero_attack_3_end/adventurer-attack3-05.png b/game/resources/animated/hero/hero_attack_3_end/adventurer-attack3-05.png new file mode 100644 index 0000000..ceedfdf Binary files /dev/null and b/game/resources/animated/hero/hero_attack_3_end/adventurer-attack3-05.png differ diff --git a/game/resources/animated/hero/hero_attack_3_end/adventurer-attack3-06.png b/game/resources/animated/hero/hero_attack_3_end/adventurer-attack3-06.png new file mode 100644 index 0000000..ceedfdf Binary files /dev/null and b/game/resources/animated/hero/hero_attack_3_end/adventurer-attack3-06.png differ diff --git a/game/resources/animated/hero/hero_attack_3_end/adventurer-attack3-07.png b/game/resources/animated/hero/hero_attack_3_end/adventurer-attack3-07.png new file mode 100644 index 0000000..1156b4e Binary files /dev/null and b/game/resources/animated/hero/hero_attack_3_end/adventurer-attack3-07.png differ diff --git a/game/resources/animated/hero/hero_attack_3_end/adventurer-attack3-08.png b/game/resources/animated/hero/hero_attack_3_end/adventurer-attack3-08.png new file mode 100644 index 0000000..1156b4e Binary files /dev/null and b/game/resources/animated/hero/hero_attack_3_end/adventurer-attack3-08.png differ diff --git a/game/resources/animated/hero/hero_fall/adventurer-fall-00.png b/game/resources/animated/hero/hero_fall/adventurer-fall-00.png new file mode 100644 index 0000000..3a4b30f Binary files /dev/null and b/game/resources/animated/hero/hero_fall/adventurer-fall-00.png differ diff --git a/game/resources/animated/hero/hero_fall/adventurer-fall-01.png b/game/resources/animated/hero/hero_fall/adventurer-fall-01.png new file mode 100644 index 0000000..cd61af0 Binary files /dev/null and b/game/resources/animated/hero/hero_fall/adventurer-fall-01.png differ diff --git a/game/resources/animated/hero/hero_fly_up/adventurer-jump-03.png b/game/resources/animated/hero/hero_fly_up/adventurer-jump-03.png new file mode 100644 index 0000000..0458013 Binary files /dev/null and b/game/resources/animated/hero/hero_fly_up/adventurer-jump-03.png differ diff --git a/game/resources/animated/hero/hero_idle/adventurer-idle-00.png b/game/resources/animated/hero/hero_idle/adventurer-idle-00.png new file mode 100644 index 0000000..3bd528e Binary files /dev/null and b/game/resources/animated/hero/hero_idle/adventurer-idle-00.png differ diff --git a/game/resources/animated/hero/hero_idle/adventurer-idle-01.png b/game/resources/animated/hero/hero_idle/adventurer-idle-01.png new file mode 100644 index 0000000..230c1cb Binary files /dev/null and b/game/resources/animated/hero/hero_idle/adventurer-idle-01.png differ diff --git a/game/resources/animated/hero/hero_idle/adventurer-idle-02.png b/game/resources/animated/hero/hero_idle/adventurer-idle-02.png new file mode 100644 index 0000000..2668b59 Binary files /dev/null and b/game/resources/animated/hero/hero_idle/adventurer-idle-02.png differ diff --git a/game/resources/animated/hero/hero_idle/adventurer-idle-03.png b/game/resources/animated/hero/hero_idle/adventurer-idle-03.png new file mode 100644 index 0000000..53207e8 Binary files /dev/null and b/game/resources/animated/hero/hero_idle/adventurer-idle-03.png differ diff --git a/game/resources/animated/hero/hero_jump/adventurer-jump-00.png b/game/resources/animated/hero/hero_jump/adventurer-jump-00.png new file mode 100644 index 0000000..eedea05 Binary files /dev/null and b/game/resources/animated/hero/hero_jump/adventurer-jump-00.png differ diff --git a/game/resources/animated/hero/hero_jump/adventurer-jump-01.png b/game/resources/animated/hero/hero_jump/adventurer-jump-01.png new file mode 100644 index 0000000..b20e034 Binary files /dev/null and b/game/resources/animated/hero/hero_jump/adventurer-jump-01.png differ diff --git a/game/resources/animated/hero/hero_jump/adventurer-jump-02.png b/game/resources/animated/hero/hero_jump/adventurer-jump-02.png new file mode 100644 index 0000000..ba27779 Binary files /dev/null and b/game/resources/animated/hero/hero_jump/adventurer-jump-02.png differ diff --git a/game/resources/animated/hero/hero_jump/adventurer-jump-03.png b/game/resources/animated/hero/hero_jump/adventurer-jump-03.png new file mode 100644 index 0000000..0458013 Binary files /dev/null and b/game/resources/animated/hero/hero_jump/adventurer-jump-03.png differ diff --git a/game/resources/animated/hero/hero_run/adventurer-run-00.png b/game/resources/animated/hero/hero_run/adventurer-run-00.png new file mode 100644 index 0000000..e3d7cc0 Binary files /dev/null and b/game/resources/animated/hero/hero_run/adventurer-run-00.png differ diff --git a/game/resources/animated/hero/hero_run/adventurer-run-01.png b/game/resources/animated/hero/hero_run/adventurer-run-01.png new file mode 100644 index 0000000..96d8320 Binary files /dev/null and b/game/resources/animated/hero/hero_run/adventurer-run-01.png differ diff --git a/game/resources/animated/hero/hero_run/adventurer-run-02.png b/game/resources/animated/hero/hero_run/adventurer-run-02.png new file mode 100644 index 0000000..2e3b74d Binary files /dev/null and b/game/resources/animated/hero/hero_run/adventurer-run-02.png differ diff --git a/game/resources/animated/hero/hero_run/adventurer-run-03.png b/game/resources/animated/hero/hero_run/adventurer-run-03.png new file mode 100644 index 0000000..a512930 Binary files /dev/null and b/game/resources/animated/hero/hero_run/adventurer-run-03.png differ diff --git a/game/resources/animated/hero/hero_run/adventurer-run-04.png b/game/resources/animated/hero/hero_run/adventurer-run-04.png new file mode 100644 index 0000000..ca34331 Binary files /dev/null and b/game/resources/animated/hero/hero_run/adventurer-run-04.png differ diff --git a/game/resources/animated/hero/hero_run/adventurer-run-05.png b/game/resources/animated/hero/hero_run/adventurer-run-05.png new file mode 100644 index 0000000..01c9c00 Binary files /dev/null and b/game/resources/animated/hero/hero_run/adventurer-run-05.png differ diff --git a/game/resources/levels/level_01/config.json b/game/resources/levels/level_01/config.json index d44f1a2..5bb6d88 100644 --- a/game/resources/levels/level_01/config.json +++ b/game/resources/levels/level_01/config.json @@ -1,7 +1,7 @@ { "name" : "level_01", "animated_resources" : "../../game/resources/animated/", - "block" : 50.0, + "block" : 10.0, "camera": { "position" : { "x" : 10.0, @@ -26,21 +26,98 @@ "hero" : { "source" : "hero", "animated" : { - "size_width": 30, - "size_height": 50, - "size_scale": 0.2, + "size_width": 5.5, + "size_height": 9, + "size_scale": 0.3, "delta_x" : 0, - "delta_y" : 0, + "delta_y" : 3, "actions" : { "idle" : { - "source": "idle", + "source": "hero_idle", "type": "several_files", - "delta_time": 100 + "delta_time": 200 }, "run" : { - "source": "run", + "source": "hero_run", + "type": "several_files", + "delta_time": 130 + }, + "jump" : { + "source": "hero_jump", + "type": "several_files", + "delta_time": 50 + }, + "fly_up" : { + "source": "hero_fly_up", "type": "several_files", "delta_time": 100 + }, + "fall" : { + "source": "hero_fall", + "type": "several_files", + "delta_time": 130 + }, + "attack_1_beg" : { + "source": "hero_attack_1_beg", + "type": "several_files", + "delta_time": 30 + }, + "attack_1_end" : { + "source": "hero_attack_1_end", + "type": "several_files", + "delta_time": 30 + }, + "attack_2_beg" : { + "source": "hero_attack_2_beg", + "type": "several_files", + "delta_time": 30 + }, + "attack_2_end" : { + "source": "hero_attack_2_end", + "type": "several_files", + "delta_time": 30 + }, + "attack_3_beg" : { + "source": "hero_attack_3_beg", + "type": "several_files", + "delta_time": 30 + }, + "attack_3_end" : { + "source": "hero_attack_3_end", + "type": "several_files", + "delta_time": 30 + } + } + } + }, + "enemy" : { + "source" : "enemy", + "animated" : { + "size_width": 5.5, + "size_height": 9, + "size_scale": 0.3, + "delta_x" : 0, + "delta_y" : 3, + "actions" : { + "idle" : { + "source": "enemy_idle", + "type": "several_files", + "delta_time": 200 + }, + "run" : { + "source": "enemy_run", + "type": "several_files", + "delta_time": 130 + }, + "attack_beg" : { + "source": "enemy_attack_beg", + "type": "several_files", + "delta_time": 30 + }, + "attack_end" : { + "source": "enemy_attack_end", + "type": "several_files", + "delta_time": 30 } } } diff --git a/game/resources/levels/level_01/map b/game/resources/levels/level_01/map index 6dd1ec9..82266f0 100644 --- a/game/resources/levels/level_01/map +++ b/game/resources/levels/level_01/map @@ -1,6 +1,11 @@ @...F..H..#..# -....#.......## +.............. +.............. +.............. +.............. +.............. +...##.......## ...#.#......## ###########.## -............@@ -............## \ No newline at end of file +............## +............##= \ No newline at end of file diff --git a/game/resources/levels/level_with_finish/config.json b/game/resources/levels/level_with_finish/config.json index a3b8ce0..391e191 100644 --- a/game/resources/levels/level_with_finish/config.json +++ b/game/resources/levels/level_with_finish/config.json @@ -1,7 +1,7 @@ { "name" : "level_with_finish", "animated_resources" : "../../game/resources/animated/", - "block" : 50.0, + "block" : 10.0, "camera": { "position" : { "x" : 10.0, @@ -26,21 +26,98 @@ "hero" : { "source" : "hero", "animated" : { - "size_width": 30, - "size_height": 50, - "size_scale": 0.2, + "size_width": 5.5, + "size_height": 9, + "size_scale": 0.3, "delta_x" : 0, - "delta_y" : 0, + "delta_y" : 3, "actions" : { "idle" : { - "source": "idle", + "source": "hero_idle", "type": "several_files", - "delta_time": 100 + "delta_time": 200 }, "run" : { - "source": "run", + "source": "hero_run", + "type": "several_files", + "delta_time": 130 + }, + "jump" : { + "source": "hero_jump", + "type": "several_files", + "delta_time": 50 + }, + "fly_up" : { + "source": "hero_fly_up", "type": "several_files", "delta_time": 100 + }, + "fall" : { + "source": "hero_fall", + "type": "several_files", + "delta_time": 130 + }, + "attack_1_beg" : { + "source": "hero_attack_1_beg", + "type": "several_files", + "delta_time": 30 + }, + "attack_1_end" : { + "source": "hero_attack_1_end", + "type": "several_files", + "delta_time": 30 + }, + "attack_2_beg" : { + "source": "hero_attack_2_beg", + "type": "several_files", + "delta_time": 30 + }, + "attack_2_end" : { + "source": "hero_attack_2_end", + "type": "several_files", + "delta_time": 30 + }, + "attack_3_beg" : { + "source": "hero_attack_3_beg", + "type": "several_files", + "delta_time": 30 + }, + "attack_3_end" : { + "source": "hero_attack_3_end", + "type": "several_files", + "delta_time": 30 + } + } + } + }, + "enemy" : { + "source" : "enemy", + "animated" : { + "size_width": 5.5, + "size_height": 9, + "size_scale": 0.3, + "delta_x" : 0, + "delta_y" : 3, + "actions" : { + "idle" : { + "source": "enemy_idle", + "type": "several_files", + "delta_time": 200 + }, + "run" : { + "source": "enemy_run", + "type": "several_files", + "delta_time": 130 + }, + "attack_beg" : { + "source": "enemy_attack_beg", + "type": "several_files", + "delta_time": 30 + }, + "attack_end" : { + "source": "enemy_attack_end", + "type": "several_files", + "delta_time": 30 } } }