aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLoek Le Blansch <loek@pipeframe.xyz>2024-12-19 10:26:55 +0100
committerLoek Le Blansch <loek@pipeframe.xyz>2024-12-19 10:26:55 +0100
commitf58b920da434c6eb67f7e439277d7fb2eaa4f2e0 (patch)
tree25b420467f20d29dcd73afaf0bfce49abdead1ea
parentfb76ba279cc2500f2ed385c3463caed003d43e00 (diff)
fix player controller responsivenessmax/game
-rw-r--r--src/example/Player.cpp15
1 files changed, 3 insertions, 12 deletions
diff --git a/src/example/Player.cpp b/src/example/Player.cpp
index a3126cf..73f0275 100644
--- a/src/example/Player.cpp
+++ b/src/example/Player.cpp
@@ -11,19 +11,10 @@ using namespace std;
class PlayerScript : public Script {
public:
- void init() {
- subscribe<KeyPressEvent>(
- [this](const KeyPressEvent & ev) -> bool { return this->keypressed(ev); });
- }
-
-private:
- bool keypressed(const KeyPressEvent & event) {
- if (event.key == Keycode::SPACE) {
- Rigidbody & rb = this->get_components_by_name<Rigidbody>("player").front();
+ void update() {
+ Rigidbody & rb = this->get_components_by_name<Rigidbody>("player").front();
+ if (this->get_key_state(Keycode::SPACE))
rb.add_force_linear(vec2(0, -10));
- return true;
- }
- return false;
}
};