diff options
author | JAROWMR <jarorutjes07@gmail.com> | 2024-11-17 15:34:32 +0100 |
---|---|---|
committer | JAROWMR <jarorutjes07@gmail.com> | 2024-11-17 15:34:32 +0100 |
commit | 876a2e2ba115f6f8afa45155c8c6ed90d10576de (patch) | |
tree | 71dd70d555831eba188210d522993f1f249e772d /src/example/collision.cpp | |
parent | b019b401c3a1de0ffea7e6776242ae73599651ef (diff) |
added functionality to example and added pictures
Diffstat (limited to 'src/example/collision.cpp')
-rw-r--r-- | src/example/collision.cpp | 72 |
1 files changed, 45 insertions, 27 deletions
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 <crepe/api/Vector2.h> #include <crepe/api/Event.h> #include <crepe/api/EventManager.h> +#include <crepe/api/LoopManager.h> #include <chrono> #include <memory> @@ -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>(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>(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<BoxCollider>(Vector2{5, 5}, 5, 5); - game_object1.add_component<BehaviorScript>().set_script<MyScript>(); - game_object1.add_component<BehaviorScript>().set_script<MyScript>(); + World.add_component<BoxCollider>(Vector2{0, -740}, 1000, 1000); // Top + World.add_component<BoxCollider>(Vector2{0, 740}, 1000, 1000); // Bottom + World.add_component<BoxCollider>(Vector2{-820, 0}, 1000, 1000); // Left + World.add_component<BoxCollider>(Vector2{820, 0}, 1000, 1000); // right - // game_object1.add_component<Sprite>( - // make_shared<Texture>("/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>(Rigidbody::Data{ + GameObject game_object1(1, "Name", "Tag", Vector2{320, 240}, 0, 1); + game_object1.add_component<Rigidbody>(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<BoxCollider>(Vector2{5, 5}, 5, 5); - game_object2.add_component<BehaviorScript>().set_script<MyScript>(); + game_object1.add_component<BoxCollider>(Vector2{5, 5}, 5, 5); + game_object1.add_component<BehaviorScript>().set_script<MyScript>(); + game_object1.add_component<Sprite>( + make_shared<Texture>("/home/jaro/crepe/asset/texture/img.png"), color, + FlipSettings{true, true}); + game_object1.add_component<Camera>(Color::get_white()); + + + // GameObject game_object2(2, "Name", "Tag", Vector2{10, 10}, 0, 1); + // game_object2.add_component<Rigidbody>(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<BoxCollider>(Vector2{5, 5}, 5, 5); + // game_object2.add_component<BehaviorScript>().set_script<MyScript>(); // game_object2.add_component<Sprite>( // make_shared<Texture>("/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; |