Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release branch #123

Open
wants to merge 147 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
147 commits
Select commit Hold shift + click to select a range
a35ca7c
create Hero 2.0
Mirong1707 May 14, 2022
b36e8f9
set animations in statemachine
Mirong1707 May 14, 2022
d9bd2dc
set animations in statemachine
Mirong1707 May 15, 2022
c93a178
?
Mirong1707 May 15, 2022
442ccf5
create Hero 2.0
Mirong1707 May 14, 2022
5859a71
set animations in statemachine
Mirong1707 May 14, 2022
c97f35c
set animations in statemachine
Mirong1707 May 15, 2022
aa62dd7
Merge remote-tracking branch 'origin/105-program-player-and-enemy-beh…
Mirong1707 May 15, 2022
053a755
create Hero 2.0
Mirong1707 May 14, 2022
6ddb7fb
set animations in statemachine
Mirong1707 May 14, 2022
b9f34fa
set animations in statemachine
Mirong1707 May 15, 2022
9437242
create Hero 2.0
Mirong1707 May 14, 2022
773fbda
set animations in statemachine
Mirong1707 May 14, 2022
4aeac70
set animations in statemachine
Mirong1707 May 15, 2022
3bfd4a6
Merge branch '105-program-player-and-enemy-behaviour' of github.com:P…
Mirong1707 May 15, 2022
42a92ea
?
Mirong1707 May 15, 2022
9492389
create Hero 2.0
Mirong1707 May 14, 2022
6def163
set animations in statemachine
Mirong1707 May 14, 2022
c5bcc88
set animations in statemachine
Mirong1707 May 15, 2022
beefc83
create Hero 2.0
Mirong1707 May 14, 2022
dbb1e76
set animations in statemachine
Mirong1707 May 14, 2022
863ee18
set animations in statemachine
Mirong1707 May 15, 2022
8d5043b
create Hero 2.0
Mirong1707 May 14, 2022
c5ed894
set animations in statemachine
Mirong1707 May 14, 2022
b84ebde
set animations in statemachine
Mirong1707 May 15, 2022
6774b46
create Hero 2.0
Mirong1707 May 14, 2022
5e96958
set animations in statemachine
Mirong1707 May 14, 2022
32ecd06
set animations in statemachine
Mirong1707 May 15, 2022
3860f6a
?
Mirong1707 May 15, 2022
dfe2057
Merge branch '105-program-player-and-enemy-behaviour' of github.com:P…
Mirong1707 May 15, 2022
150ae15
Merge remote-tracking branch 'origin/main' into 105-program-player-an…
Mirong1707 May 15, 2022
699b2cb
?
Mirong1707 May 15, 2022
1d865f8
Merge remote-tracking branch 'origin/main' into 105-program-player-an…
Mirong1707 May 15, 2022
ff6b66d
merge main
Mirong1707 May 16, 2022
7ba72f6
set normal jump animations
Mirong1707 May 16, 2022
9a8c217
set normal jump animations
Mirong1707 May 16, 2022
9ea4554
debug
Mirong1707 May 17, 2022
7f893c0
add sensor to physicalEntity
Mirong1707 May 17, 2022
6df869f
finish jump state
Mirong1707 May 17, 2022
6b09d92
merge main
Mirong1707 May 22, 2022
dba4e72
merge main
Mirong1707 May 22, 2022
6fc2b69
add animations
Mirong1707 May 22, 2022
c7f7f64
add animations
Mirong1707 May 22, 2022
df599e4
add animations
Mirong1707 May 22, 2022
e91c0bb
Merge remote-tracking branch 'origin/main' into 105-program-player-an…
Mirong1707 May 22, 2022
34b7507
find bug in anim
Mirong1707 May 22, 2022
458519d
add debug
Mirong1707 May 23, 2022
b63a238
multiple conditions in one transaction
Mirong1707 May 23, 2022
94aee0c
multiple conditions in one transaction + add fall without jump
Mirong1707 May 23, 2022
ce4ef0f
Add httplib.h in submodule, move resources, add network directory and…
MhlvDenis May 28, 2022
6ee5a4b
Add httplib.h in submodule, move resources, add network directory and…
MhlvDenis May 28, 2022
6624759
make HeroStateMachine
Mirong1707 May 29, 2022
6a7fa64
Merge remote-tracking branch 'origin/115-network' into 115-network
MhlvDenis May 29, 2022
fe60003
Test for httplib
MhlvDenis May 29, 2022
cf3727a
Add simple client and server realisation
MhlvDenis May 29, 2022
2d1ea08
Chain server and window
MhlvDenis May 30, 2022
20f9518
Add server control buttons
MhlvDenis May 30, 2022
04e24ce
Add server logs
MhlvDenis May 30, 2022
87dc434
Add mutex for logs and db
MhlvDenis May 30, 2022
84d2adf
Add httplib.h in submodule, move resources, add network directory and…
MhlvDenis May 28, 2022
995cbe3
Test for httplib
MhlvDenis May 29, 2022
72b1e90
Add simple client and server realisation
MhlvDenis May 29, 2022
9b3b98f
Chain server and window
MhlvDenis May 30, 2022
205ff02
Add server control buttons
MhlvDenis May 30, 2022
acc028e
Add server logs
MhlvDenis May 30, 2022
2af5698
Add mutex for logs and db
MhlvDenis May 30, 2022
fe12638
Provide rebase
MhlvDenis May 30, 2022
9b6e2be
Merge remote-tracking branch 'origin/115-network' into 115-network
MhlvDenis May 30, 2022
8560e00
Add httplib.h in submodule, move resources, add network directory and…
MhlvDenis May 28, 2022
1f9e1fb
Test for httplib
MhlvDenis May 29, 2022
cf8a92f
Add simple client and server realisation
MhlvDenis May 29, 2022
cb7cdac
Chain server and window
MhlvDenis May 30, 2022
7a9ec4a
Add server control buttons
MhlvDenis May 30, 2022
3e4ee47
Add server logs
MhlvDenis May 30, 2022
4c81fe7
Add mutex for logs and db
MhlvDenis May 30, 2022
9ab7131
Provide rebase
MhlvDenis May 30, 2022
7a89383
Add httplib.h in submodule, move resources, add network directory and…
MhlvDenis May 28, 2022
9aaded5
Add httplib.h in submodule, move resources, add network directory and…
MhlvDenis May 28, 2022
0a95808
Add simple client and server realisation
MhlvDenis May 29, 2022
35b01e9
Add server control buttons
MhlvDenis May 30, 2022
765788e
Add server logs
MhlvDenis May 30, 2022
7021ea2
Add mutex for logs and db
MhlvDenis May 30, 2022
a5a02b2
Merge remote-tracking branch 'origin/115-network' into 115-network
MhlvDenis May 30, 2022
69c2c45
Implement LevelLoaderFromServer
MhlvDenis Jun 1, 2022
b25cacd
add slime files
Mirong1707 Jun 1, 2022
f07ef06
merge main
Mirong1707 Jun 1, 2022
0b95b65
merge main
Mirong1707 Jun 1, 2022
f2a3d80
merge main
Mirong1707 Jun 1, 2022
5e34de2
merge main
Mirong1707 Jun 1, 2022
1cda33b
merge main
Mirong1707 Jun 1, 2022
fd5ec30
Update build_and_run_tests.yml
Mirong1707 Jun 1, 2022
d28a4b3
Merge remote-tracking branch 'origin/create-complete-graphics' into r…
Alexeyha Jun 2, 2022
f254c40
Merge graphics and fix zoom
Alexeyha Jun 2, 2022
5c1b158
Add parameter of distance over hero in config
Alexeyha Jun 2, 2022
b347cda
add enemy to map
Mirong1707 Jun 2, 2022
fdc84bb
merge
Mirong1707 Jun 2, 2022
5be62eb
create enemy StateMachine
Mirong1707 Jun 2, 2022
0105892
reverse sprites
Mirong1707 Jun 2, 2022
6e90660
Level-table in database
MhlvDenis Jun 2, 2022
21f7631
Fix Attack
Alexeyha Jun 2, 2022
6f710e2
Load levels from server
MhlvDenis Jun 2, 2022
7cef2f0
something
MhlvDenis Jun 3, 2022
7d466e6
Input levelname
MhlvDenis Jun 3, 2022
39d234d
Input levelname frontend
MhlvDenis Jun 4, 2022
bd08179
Fix window size
Alexeyha Jun 4, 2022
a97dec0
Add hero parameters
Alexeyha Jun 4, 2022
5ed0f06
Fix view size
Alexeyha Jun 4, 2022
5056e88
add destroy object
Mirong1707 Jun 4, 2022
1ff802d
add destroy object
Mirong1707 Jun 4, 2022
4b81d43
Fix config
Alexeyha Jun 4, 2022
740bd08
Merge remote-tracking branch 'origin/release_branch' into release_branch
Alexeyha Jun 4, 2022
d7c1d74
Add tiles
Alexeyha Jun 4, 2022
3229182
add kill enemy
Mirong1707 Jun 4, 2022
e1e38ae
Add tiles
Alexeyha Jun 4, 2022
d9a1dc0
Merge remote-tracking branch 'origin/release_branch' into release_branch
Alexeyha Jun 4, 2022
e2328b1
Add tiles
Alexeyha Jun 4, 2022
33ef740
Input levelname with checking
MhlvDenis Jun 4, 2022
0afeaa1
add enemy
Mirong1707 Jun 4, 2022
73b1c44
add enemy
Mirong1707 Jun 4, 2022
d31a7e0
add enemy
Mirong1707 Jun 4, 2022
02c8d86
Add unstable
Alexeyha Jun 4, 2022
09a0376
Merge remote-tracking branch 'origin/release_branch' into release_branch
Alexeyha Jun 4, 2022
77c145c
fall death
Mirong1707 Jun 4, 2022
37e61a0
Merge remote-tracking branch 'origin/release_branch' into release_branch
Mirong1707 Jun 4, 2022
e4ea020
Move resources
MhlvDenis Jun 4, 2022
31e1c32
Move resources
MhlvDenis Jun 4, 2022
bd1f2d2
Merge server and release
MhlvDenis Jun 4, 2022
d1ce0d5
Fix submodule
MhlvDenis Jun 4, 2022
aef7366
Fix submodule
MhlvDenis Jun 4, 2022
b8d76ec
Merge remote-tracking branch 'origin/120-merge-server-and-release' in…
MhlvDenis Jun 4, 2022
0d51504
Fix submodule
MhlvDenis Jun 4, 2022
1453ef7
Merge remote-tracking branch 'origin/120-merge-server-and-release' in…
MhlvDenis Jun 4, 2022
f3326f9
Fix submodule
MhlvDenis Jun 4, 2022
0da6691
Merge pull request #125 from PlatformerTeam/120-merge-server-and-release
MhlvDenis Jun 4, 2022
413a8d4
Add blocks
Alexeyha Jun 4, 2022
87797d6
delete level
Alexeyha Jun 4, 2022
aaba357
Add some decoration
Alexeyha Jun 4, 2022
5dd1f3e
add death event
Mirong1707 Jun 4, 2022
666308a
Complete level_03
Alexeyha Jun 5, 2022
c1fafc3
fix bugs
Mirong1707 Jun 5, 2022
159eb19
Merge remote-tracking branch 'origin/release_branch' into release_branch
Mirong1707 Jun 5, 2022
0af17ac
fix bugs
Mirong1707 Jun 5, 2022
c003306
Fix decoration
Alexeyha Jun 5, 2022
ed407e9
Add debug_mode
Alexeyha Jun 5, 2022
fe4b166
Add debug_mode in server
Alexeyha Jun 5, 2022
3844646
Add demo levels
MhlvDenis Jul 9, 2022
5681502
Drop levels after server shutdown
MhlvDenis Jul 9, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
4 changes: 2 additions & 2 deletions .github/workflows/build_and_run_tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ name: CI

on:
push:
branches: [ main ]
branches: [ main, release_branch ]
pull_request:
branches: [ main ]
branches: [ main, release_branch ]

jobs:

Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@
[submodule "deps/libpqxx"]
path = deps/libpqxx
url = https://github.com/jtv/libpqxx
[submodule "deps/cpp-httplib"]
path = deps/cpp-httplib
url = https://github.com/yhirose/cpp-httplib
17 changes: 17 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,13 @@ add_subdirectory(${DIRECTORY_PQXX})
message(STATUS "PostgreSQL include: ${INCLUDE_PQXX}")
message(STATUS "PostgreSQL library: ${LIBRARY_PQXX}")

# HTTP library
set(DIRECTORY_HTTP ${PROJECT_SOURCE_DIR}/deps/cpp-httplib)
set(INCLUDE_HTTP ${DIRECTORY_HTTP})

add_subdirectory(${DIRECTORY_HTTP})
message(STATUS "HTTP include: ${INCLUDE_HTTP}")

# Core library
set(DIRECTORY_CORE ${PROJECT_SOURCE_DIR}/core)
set(INCLUDE_CORE ${DIRECTORY_CORE})
Expand All @@ -100,11 +107,21 @@ set(DIRECTORY_GAME ${PROJECT_SOURCE_DIR}/game)
set(EXECUTABLE_GAME example)
set(EXECUTABLE_GAME_RUNNER game_runner_example)
set(EXECUTABLE_GAME_DATABASE game_database_example)
set(EXECUTABLE_LOADER_FROM_SERVER game_loader_from_server_example)

add_subdirectory(${DIRECTORY_GAME})
message(STATUS "Game executable: ${EXECUTABLE_GAME}")
message(STATUS "Game-runner executable ${EXECUTABLE_GAME_RUNNER}")

# Network binaries
set(DIRECTORY_NETWORK ${PROJECT_SOURCE_DIR}/network)
set(EXECUTABLE_SIMPLE_SERVER simple-server)
set(EXECUTABLE_SIMPLE_CLIENT simple-client)

add_subdirectory(${DIRECTORY_NETWORK})
message(STATUS "Server executable: ${EXECUTABLE_SERVER}")
message(STATUS "Client executable ${EXECUTABLE_GAME_CLIENT}")

# Tests
set(DIRECTORY_TEST ${PROJECT_SOURCE_DIR}/test)
set(EXECUTABLE_TEST test)
Expand Down
3 changes: 2 additions & 1 deletion core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ set(
runner/GameRunner.hpp runner/GameRunner.cpp
loader/LevelLoader.hpp
loader/LevelLoaderFromFile.cpp loader/LevelLoaderFromFile.hpp
loader/LevelLoaderFromServer.hpp loader/LevelLoaderFromServer.cpp

visual/image/Image.hpp
visual/image/static/RenderableStatic.cpp visual/image/static/RenderableStatic.hpp
Expand All @@ -103,7 +104,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 event/management/controller/statemachine/EnemyStateMachine.hpp event/management/controller/statemachine/EnemyStateMachine.cpp event/management/controller/EnemyAttack.hpp event/management/controller/EnemyAttack.cpp event/management/controller/Die.hpp event/management/controller/Die.cpp event/management/controller/Destroy.hpp event/management/controller/Destroy.cpp world/filter/RadiusFilter.hpp event/management/controller/DealDamage.hpp event/management/controller/DealDamage.cpp event/physics/TakeDamage.hpp event/physics/TakeDamage.cpp event/management/condition/TakeDamageCondition.hpp event/management/condition/TakeDamageCondition.cpp event/management/controller/Hurt.hpp event/management/controller/Hurt.cpp event/management/condition/Counter.hpp event/management/condition/Counter.cpp event/management/condition/EnemyAttackCondition.hpp event/management/condition/EnemyAttackCondition.cpp event/physics/Death.hpp event/physics/Death.cpp event/management/condition/FallDownCondition.hpp event/management/condition/FallDownCondition.cpp)

add_library(
${LIBRARY_CORE} STATIC
Expand Down
2 changes: 2 additions & 0 deletions core/common/FVec2D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,6 @@ namespace mad::core {
Vec2d operator*(float k, Vec2d v) {
return v *= k;
}


}
1 change: 0 additions & 1 deletion core/common/FVec2D.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ namespace mad::core {

operator sf::Vector2<float>() const;


[[nodiscard]] float get_x() const noexcept;

[[nodiscard]] float get_y() const noexcept;
Expand Down
48 changes: 47 additions & 1 deletion core/database/database/Database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,11 @@ namespace mad::core {
"levels_completed SMALLINT NOT NULL);";
w.exec(m_query);

m_query = "CREATE TABLE IF NOT EXISTS levels("
"id SERIAL PRIMARY KEY,"
"name TEXT NOT NULL UNIQUE);";
w.exec(m_query);

w.commit();

SPDLOG_DEBUG("Tables created successfully");
Expand All @@ -33,17 +38,28 @@ namespace mad::core {
}
}

Database::~Database() {
drop_levels();
}

bool Database::is_user_exists(const std::string &username) {
pqxx::work W(m_connector);
m_query = "SELECT * FROM users WHERE name = '" + W.esc(username) + "';";
pqxx::result rows_found = W.exec(m_query);
return !rows_found.empty();
}

bool Database::is_level_exists(const std::string &levelname) {
pqxx::work W(m_connector);
m_query = "SELECT * FROM levels WHERE name = '" + W.esc(levelname) + "';";
pqxx::result rows_found = W.exec(m_query);
return !rows_found.empty();
}

void Database::registry_user(const std::string &username) {
pqxx::work W(m_connector);

m_query = "SELECT id FROM users";
m_query = "SELECT id FROM users;";
pqxx::result total_rows = W.exec(m_query);
std::size_t id = total_rows.size();

Expand All @@ -56,6 +72,15 @@ namespace mad::core {
W.commit();
}

void Database::append_level(const std::string &levelname) {
pqxx::work W(m_connector);

m_query = "INSERT INTO levels(name) VALUES('" + levelname + "');";
W.exec(m_query);

W.commit();
}

std::size_t Database::get_id(const std::string &username) {
pqxx::work W(m_connector);
m_query = "SELECT * FROM users WHERE name = '" + W.esc(username) + "';";
Expand Down Expand Up @@ -99,4 +124,25 @@ namespace mad::core {
void Database::reset_progress(const std::string &username) {
reset_progress(get_id(username));
}

std::string Database::get_levelname(std::size_t id) {
pqxx::work W(m_connector);
m_query = "SELECT * FROM levels WHERE id = " + std::to_string(id) + ";";
auto found_row = W.exec1(m_query);
return found_row["name"].as<std::string>();
}

std::size_t Database::get_levels_total() {
pqxx::work W(m_connector);
m_query = "SELECT id FROM levels;";
auto total_rows = W.exec(m_query);
return total_rows.size();
}

void Database::drop_levels() {
pqxx::work W(m_connector);
m_query = "DROP TABLE levels;";
W.exec(m_query);
W.commit();
}
}
15 changes: 14 additions & 1 deletion core/database/database/Database.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <pqxx/pqxx>
#include <cstddef>
#include <mutex>


namespace mad::core {
Expand All @@ -13,19 +14,31 @@ namespace mad::core {

bool is_user_exists(const std::string &username);

void registry_user(const std::string &username);
bool is_level_exists(const std::string &levelname);

std::size_t get_id(const std::string &username);

std::size_t get_progress(std::size_t id);
std::size_t get_progress(const std::string &username);

std::string get_levelname(std::size_t id);

std::size_t get_levels_total();

void registry_user(const std::string &username);

void append_level(const std::string &levelname);

void increment_progress(std::size_t id);
void increment_progress(const std::string &username);

void reset_progress(std::size_t id);
void reset_progress(const std::string &username);

void drop_levels();

~Database();

private:
pqxx::connection m_connector;
std::string m_query;
Expand Down
6 changes: 5 additions & 1 deletion core/event/Event.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ namespace mad::core {
LevelPause,
Runner,
WorldUpdate,
EndOfRenderAction
EndOfRenderAction,
SensorCollision,
SensorCollisionEnd,
TakeDamage,
Death,
};

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

virtual ~Condition() = default;

bool triggered;
};

}
Expand Down
11 changes: 11 additions & 0 deletions core/event/management/condition/Counter.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include "Counter.hpp"
mad::core::Counter::Counter(int *c, int mx) : c(c), mx(mx){
}
bool mad::core::Counter::is_triggered_by(const mad::core::Event &event) {
return *c >= mx;
}
std::unordered_set<mad::core::Event::Type> mad::core::Counter::triggers() {
return {Event::Type::WorldUpdate};
}
void mad::core::Counter::on_start() {
}
20 changes: 20 additions & 0 deletions core/event/management/condition/Counter.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#ifndef MAD_COUNTER_HPP
#define MAD_COUNTER_HPP

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

private:
int *c;
int mx;
};
}// namespace mad::core


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

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

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

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

#endif//MAD_ENDANIMATIONCONDITION_HPP
20 changes: 20 additions & 0 deletions core/event/management/condition/EnemyAttackCondition.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include "EnemyAttackCondition.hpp"
#include "world/filter/RadiusFilter.hpp"
mad::core::EnemyAttackCondition::EnemyAttackCondition(std::shared_ptr<mad::core::LocalWorld> world, Entity::Id hero_id, Entity::Id enemy_id) : world(world), hero_id(hero_id), enemy_id(enemy_id) {
hero_entity = cast_to_or_null<PhysicalEntity>(world->get_storage().get_entity(hero_id));
enemy_entity = cast_to_or_null<PhysicalEntity>(world->get_storage().get_entity(enemy_id));

}
std::unordered_set<mad::core::Event::Type> mad::core::EnemyAttackCondition::triggers() {
return {Event::Type::WorldUpdate};
}
bool mad::core::EnemyAttackCondition::is_triggered_by(const mad::core::Event &event) {
for(auto id : world->get_storage().extract(RadiusFilter(hero_entity->get_position(), 6.0f))){
if(id == enemy_id){
return true;
}
}
return false;
}
void mad::core::EnemyAttackCondition::on_start() {
}
27 changes: 27 additions & 0 deletions core/event/management/condition/EnemyAttackCondition.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#ifndef MAD_ENEMYATTACKCONDITION_HPP
#define MAD_ENEMYATTACKCONDITION_HPP

#include "Condition.hpp"
#include "world/LocalWorld.hpp"
#include "world/entity/Entity.hpp"
#include <world/entity/PhysicalEntity.hpp>
namespace mad::core {
struct EnemyAttackCondition : Condition {
public:
EnemyAttackCondition(std::shared_ptr<mad::core::LocalWorld> world, Entity::Id hero_id, Entity::Id enemy_id);
bool is_triggered_by(const mad::core::Event &event) override;
std::unordered_set<Event::Type> triggers() override;
void on_start() override;

private:
Entity::Id hero_id;
Entity::Id enemy_id;
PhysicalEntity* hero_entity;
PhysicalEntity* enemy_entity;
std::shared_ptr<mad::core::LocalWorld> world;

};
}// namespace mad::core


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



bool mad::core::FallCondition::is_triggered_by(const mad::core::Event &event) {
return m_entity->get_linear_velocity().get_y() >= vel;
}
std::unordered_set<mad::core::Event::Type> mad::core::FallCondition::triggers() {
return {mad::core::Event::Type::WorldUpdate};
}
void mad::core::FallCondition::on_start() {
}
mad::core::FallCondition::FallCondition(std::shared_ptr<mad::core::LocalWorld> world, mad::core::Entity::Id entity_id, float vel) : m_world(world), m_entity_id(entity_id), vel(vel) {
m_entity = cast_to_or_null<PhysicalEntity>(m_world->get_storage().get_entity(m_entity_id));
}
Loading