diff options
author | Loek Le Blansch <loek@pipeframe.xyz> | 2024-12-19 10:26:55 +0100 |
---|---|---|
committer | Loek Le Blansch <loek@pipeframe.xyz> | 2024-12-19 10:26:55 +0100 |
commit | f58b920da434c6eb67f7e439277d7fb2eaa4f2e0 (patch) | |
tree | 25b420467f20d29dcd73afaf0bfce49abdead1ea | |
parent | fb76ba279cc2500f2ed385c3463caed003d43e00 (diff) |
fix player controller responsivenessmax/game
-rw-r--r-- | src/example/Player.cpp | 15 |
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; } }; |