aboutsummaryrefslogtreecommitdiffstats
path: root/src/player.cpp
diff options
context:
space:
mode:
authorClyne Sullivan <clyne@bitgloo.com>2019-09-03 20:03:41 -0400
committerClyne Sullivan <clyne@bitgloo.com>2019-09-03 20:03:41 -0400
commitcff6ba0a316f6f23852f7451adaade8454b6592f (patch)
tree35e121a87b618be49dda8e77fffd3272dc4a3758 /src/player.cpp
parentec1d57aeadbd0f34616eeec8f1a922ca61b90085 (diff)
lua handling movement events? idea
Diffstat (limited to 'src/player.cpp')
-rw-r--r--src/player.cpp34
1 files changed, 26 insertions, 8 deletions
diff --git a/src/player.cpp b/src/player.cpp
index 187d61a..5346a24 100644
--- a/src/player.cpp
+++ b/src/player.cpp
@@ -20,6 +20,8 @@
#include "player.hpp"
+#include "components/EventListener.hpp"
+#include "components/Script.hpp"
#include "components/Velocity.hpp"
void PlayerSystem::configure([[maybe_unused]] entityx::EntityManager& entities,
@@ -52,11 +54,19 @@ void PlayerSystem::receive(const KeyDownEvent& kue)
{
if (player.valid()) {
if (kue.sym == SDLK_a) {
- if (auto vel = player.component<Velocity>(); vel)
- vel->x -= GROUND_VELOCITY;
+ entities.each<EventListener>([&]([[maybe_unused]] entityx::Entity e,
+ EventListener& el)
+ {
+ el.tryListener("MoveLeftPressed",
+ e.component<Scripted>()->caller);
+ });
} else if (kue.sym == SDLK_d) {
- if (auto vel = player.component<Velocity>(); vel)
- vel->x += GROUND_VELOCITY;
+ entities.each<EventListener>([&]([[maybe_unused]] entityx::Entity e,
+ EventListener& el)
+ {
+ el.tryListener("MoveRightPressed",
+ e.component<Scripted>()->caller);
+ });
}
}
}
@@ -65,11 +75,19 @@ void PlayerSystem::receive(const KeyUpEvent& kue)
{
if (player.valid()) {
if (kue.sym == SDLK_a) {
- if (auto vel = player.component<Velocity>(); vel)
- vel->x += GROUND_VELOCITY;
+ entities.each<EventListener>([&]([[maybe_unused]] entityx::Entity e,
+ EventListener& el)
+ {
+ el.tryListener("MoveLeftReleased",
+ e.component<Scripted>()->caller);
+ });
} else if (kue.sym == SDLK_d) {
- if (auto vel = player.component<Velocity>(); vel)
- vel->x -= GROUND_VELOCITY;
+ entities.each<EventListener>([&]([[maybe_unused]] entityx::Entity e,
+ EventListener& el)
+ {
+ el.tryListener("MoveRightReleased",
+ e.component<Scripted>()->caller);
+ });
}
}
}