diff options
Diffstat (limited to 'src/example')
-rw-r--r-- | src/example/game.cpp | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/src/example/game.cpp b/src/example/game.cpp index 16fe18f..8ea50ea 100644 --- a/src/example/game.cpp +++ b/src/example/game.cpp @@ -29,23 +29,23 @@ class MyScript1 : public Script { Log::logf("Box script keypressed()"); switch (test.key) { case Keycode::A: { - Transform & tf = this->get_component<Transform>(); - tf.position.x -= 1; + Rigidbody & tf = this->get_component<Rigidbody>(); + tf.data.linear_velocity.x -= 1; break; } case Keycode::W: { - Transform & tf = this->get_component<Transform>(); - tf.position.y -= 1; + Rigidbody & tf = this->get_component<Rigidbody>(); + tf.data.linear_velocity.y -= 1; break; } case Keycode::S: { - Transform & tf = this->get_component<Transform>(); - tf.position.y += 1; + Rigidbody & tf = this->get_component<Rigidbody>(); + tf.data.linear_velocity.y += 1; break; } case Keycode::D: { - Transform & tf = this->get_component<Transform>(); - tf.position.x += 1; + Rigidbody & tf = this->get_component<Rigidbody>(); + tf.data.linear_velocity.x += 1; break; } case Keycode::E: { @@ -85,7 +85,10 @@ class MyScript1 : public Script { [this](const KeyPressEvent & ev) -> bool { return this->keypressed(ev); }); } void update() { - // Retrieve component from the same GameObject this script is on + Rigidbody & tf = this->get_component<Rigidbody>(); + Log::logf("linear_velocity.x {}", tf.data.linear_velocity.x); + Log::logf("linear_velocity.y {}", tf.data.linear_velocity.y); + // tf.data.linear_velocity = {0,0}; } }; @@ -200,7 +203,7 @@ public: .mass = 1, .gravity_scale = 1, .body_type = Rigidbody::BodyType::DYNAMIC, - .linear_velocity = {0, 0}, + .linear_velocity = {0, 1}, .constraints = {0, 0, 0}, .elastisity_coefficient = 1, .offset = {0, 0}, |