diff options
author | JAROWMR <jarorutjes07@gmail.com> | 2024-12-14 11:51:13 +0100 |
---|---|---|
committer | JAROWMR <jarorutjes07@gmail.com> | 2024-12-14 11:51:13 +0100 |
commit | d6b11fadd9e64aecbe96e5f73f85be3c0d790dcf (patch) | |
tree | 2a1465e219d14ff02c2b293b76b54b74a37ade92 /src/example/game.cpp | |
parent | d3a77a80fbda1f40d1f46552c1e3c2f6cd767668 (diff) | |
parent | b9fc66f6922b1f40f2dbe14e8dfc4caa469654bc (diff) |
Merge branch 'master' of github.com:lonkaars/crepe into jaro/particle-system-improvement
Diffstat (limited to 'src/example/game.cpp')
-rw-r--r-- | src/example/game.cpp | 31 |
1 files changed, 16 insertions, 15 deletions
diff --git a/src/example/game.cpp b/src/example/game.cpp index 2d25153..f8520f4 100644 --- a/src/example/game.cpp +++ b/src/example/game.cpp @@ -30,23 +30,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: { @@ -86,7 +86,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}; } }; @@ -161,15 +164,13 @@ public: void load_scene() { - Mediator & m = this->mediator; - ComponentManager & mgr = m.component_manager; Color color(0, 0, 0, 255); float screen_size_width = 320; float screen_size_height = 240; float world_collider = 1000; //define playable world - GameObject world = mgr.new_object( + GameObject world = new_object( "Name", "Tag", vec2{screen_size_width / 2, screen_size_height / 2}, 0, 1); world.add_component<Rigidbody>(Rigidbody::Data{ .mass = 0, @@ -197,13 +198,13 @@ public: .zoom = 1, }); - GameObject game_object1 = mgr.new_object( + GameObject game_object1 = new_object( "Name", "Tag", vec2{screen_size_width / 2, screen_size_height / 2}, 0, 1); game_object1.add_component<Rigidbody>(Rigidbody::Data{ .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}, @@ -229,7 +230,7 @@ public: .active = false; - GameObject game_object2 = mgr.new_object( + GameObject game_object2 = new_object( "Name", "Tag", vec2{screen_size_width / 2, screen_size_height / 2}, 0, 1); game_object2.add_component<Rigidbody>(Rigidbody::Data{ .mass = 1, |