From 876a2e2ba115f6f8afa45155c8c6ed90d10576de Mon Sep 17 00:00:00 2001 From: JAROWMR Date: Sun, 17 Nov 2024 15:34:32 +0100 Subject: added functionality to example and added pictures --- src/example/collision.cpp | 72 +++++++++++++++++++++++++++++------------------ 1 file changed, 45 insertions(+), 27 deletions(-) (limited to 'src/example/collision.cpp') diff --git a/src/example/collision.cpp b/src/example/collision.cpp index 45ed0b0..a1b22f0 100644 --- a/src/example/collision.cpp +++ b/src/example/collision.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include #include @@ -44,55 +45,72 @@ class MyScript : public Script { }; int main(int argc, char * argv[]) { + //setup + LoopManager gameloop; Color color(0, 0, 0, 0); - GameObject game_object1(0, "Name", "Tag", Vector2{10, 10}, 0, 1); - game_object1.add_component(Rigidbody::Data{ - .mass = 1, - .gravity_scale = 1, - .body_type = Rigidbody::BodyType::DYNAMIC, + //define playable world + GameObject World(0, "Name", "Tag", Vector2{0, 0}, 0, 1); + World.add_component(Rigidbody::Data{ + .mass = 0, + .gravity_scale = 0, + .body_type = Rigidbody::BodyType::STATIC, .constraints = {0, 0, 0}, - .use_gravity = true, - .bounce = true, - .offset = {0,0} + .use_gravity = false, + .bounce = false, + .offset = {320,240} }); - game_object1.add_component(Vector2{5, 5}, 5, 5); - game_object1.add_component().set_script(); - game_object1.add_component().set_script(); + World.add_component(Vector2{0, -740}, 1000, 1000); // Top + World.add_component(Vector2{0, 740}, 1000, 1000); // Bottom + World.add_component(Vector2{-820, 0}, 1000, 1000); // Left + World.add_component(Vector2{820, 0}, 1000, 1000); // right - // game_object1.add_component( - // make_shared("/home/jaro/crepe/asset/texture/img.png"), color, - // FlipSettings{true, true}); - - GameObject game_object2(1, "Name", "Tag", Vector2{10, 10}, 0, 1); - game_object2.add_component(Rigidbody::Data{ + GameObject game_object1(1, "Name", "Tag", Vector2{320, 240}, 0, 1); + game_object1.add_component(Rigidbody::Data{ .mass = 1, .gravity_scale = 1, .body_type = Rigidbody::BodyType::DYNAMIC, .constraints = {0, 0, 0}, - .use_gravity = true, + .use_gravity = false, .bounce = false, .offset = {0,0} }); - game_object2.add_component(Vector2{5, 5}, 5, 5); - game_object2.add_component().set_script(); + game_object1.add_component(Vector2{5, 5}, 5, 5); + game_object1.add_component().set_script(); + game_object1.add_component( + make_shared("/home/jaro/crepe/asset/texture/img.png"), color, + FlipSettings{true, true}); + game_object1.add_component(Color::get_white()); + + + // GameObject game_object2(2, "Name", "Tag", Vector2{10, 10}, 0, 1); + // game_object2.add_component(Rigidbody::Data{ + // .mass = 1, + // .gravity_scale = 1, + // .body_type = Rigidbody::BodyType::DYNAMIC, + // .constraints = {0, 0, 0}, + // .use_gravity = false, + // .bounce = false, + // .offset = {0,0} + // }); + // game_object2.add_component(Vector2{5, 5}, 5, 5); + // game_object2.add_component().set_script(); // game_object2.add_component( // make_shared("/home/jaro/crepe/asset/texture/img.png"), color, // FlipSettings{true, true}); - - ScriptSystem sys; + + crepe::ScriptSystem sys; // Update all scripts. This should result in MyScript::update being called sys.update(); - // auto & sys = crepe::RenderSystem::get_instance(); + + gameloop.start(); + // auto & render = crepe::RenderSystem::get_instance(); // auto start = std::chrono::steady_clock::now(); // while (std::chrono::steady_clock::now() - start < std::chrono::seconds(5)) { - // sys.update(); + // render.update(); // } - CollisionSystem coltest; - coltest.update(); - return 0; -- cgit v1.2.3