From 690471c7c4536c074a4dca5aab7cc618d47bfb5f Mon Sep 17 00:00:00 2001 From: JAROWMR Date: Wed, 20 Nov 2024 10:43:32 +0100 Subject: merge with maser --- src/example/CMakeLists.txt | 2 +- src/example/collision.cpp | 123 --------------------------------------------- src/example/game.cpp | 89 ++++++++++++++++++++++++++++++++ src/example/particles.cpp | 43 ---------------- src/example/physics.cpp | 24 --------- src/example/rendering.cpp | 4 +- 6 files changed, 92 insertions(+), 193 deletions(-) delete mode 100644 src/example/collision.cpp create mode 100644 src/example/game.cpp delete mode 100644 src/example/particles.cpp delete mode 100644 src/example/physics.cpp (limited to 'src/example') diff --git a/src/example/CMakeLists.txt b/src/example/CMakeLists.txt index d2ea926..2facc4d 100644 --- a/src/example/CMakeLists.txt +++ b/src/example/CMakeLists.txt @@ -28,7 +28,7 @@ add_example(proxy) add_example(db) add_example(ecs) add_example(scene_manager) -add_example(collision) +add_example(game) add_example(events) add_example(particles) add_example(gameloop) diff --git a/src/example/collision.cpp b/src/example/collision.cpp deleted file mode 100644 index f51380e..0000000 --- a/src/example/collision.cpp +++ /dev/null @@ -1,123 +0,0 @@ -#include "api/BoxCollider.h" -#include "system/CollisionSystem.h" -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -using namespace crepe; -using namespace std; - -class MyScript : public Script { - static bool oncollision(const CollisionEvent& test) { - std::cout << "test collision: " << test.info.first.collider.game_object_id << std::endl; - return true; - } - void init() { - EventManager::get_instance().subscribe(oncollision, this->parent->game_object_id); - } - void update() { - // Retrieve component from the same GameObject this script is on - - } - - -}; - -int main(int argc, char * argv[]) { - //setup - LoopManager gameloop; - Color color(0, 0, 0, 0); - - double screen_size_width = 640; - double screen_size_height = 480; - double world_collider = 1000; - //define playable world - GameObject World(0, "Name", "Tag", Vector2{screen_size_width/2, screen_size_height/2}, 0, 1); - World.add_component(Rigidbody::Data{ - .mass = 0, - .gravity_scale = 0, - .body_type = Rigidbody::BodyType::STATIC, - .constraints = {0, 0, 0}, - .use_gravity = false, - .bounce = false, - .offset = {0,0} - }); - World.add_component(Vector2{0, 0-(screen_size_height/2+world_collider/2)}, world_collider, world_collider);; // Top - World.add_component(Vector2{0, screen_size_height/2+world_collider/2}, world_collider, world_collider); // Bottom - World.add_component(Vector2{0-(screen_size_width/2+world_collider/2), 0}, world_collider, world_collider); // Left - World.add_component(Vector2{screen_size_width/2+world_collider/2, 0}, world_collider, world_collider); // right - - - GameObject game_object1(1, "Name", "Tag", Vector2{screen_size_width/2, screen_size_height/2}, 0, 1); - game_object1.add_component(Rigidbody::Data{ - .mass = 1, - .gravity_scale = 0.01, - .body_type = Rigidbody::BodyType::DYNAMIC, - .linear_velocity = {1,0}, - .constraints = {0, 0, 0}, - .use_gravity = true, - .bounce = true, - .elastisity = 1, - .offset = {0,0}, - }); - game_object1.add_component(Vector2{0, 0}, 20, 20); - game_object1.add_component().set_script(); - game_object1.add_component( - make_shared("/home/jaro/crepe/asset/texture/green_square.png"), color, - FlipSettings{true, true}); - game_object1.add_component(Color::get_white()); - - - // GameObject game_object2(2, "Name", "Tag", Vector2{20, 470}, 0, 1); - // game_object2.add_component(Rigidbody::Data{ - // .mass = 1, - // .gravity_scale = 1, - // .body_type = Rigidbody::BodyType::DYNAMIC, - // .linear_velocity = {0,0}, - // .constraints = {0, 0, 0}, - // .use_gravity = false, - // .bounce = false, - // .offset = {0,0}, - // }); - // game_object2.add_component(Vector2{0, 0}, 0, 0); - // game_object2.add_component().set_script(); - // game_object2.add_component( - // make_shared("/home/jaro/crepe/asset/texture/red_square.png"), color, - // FlipSettings{true, true}); - - - crepe::ScriptSystem sys; - // Update all scripts. This should result in MyScript::update being called - sys.update(); - - 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)) { - // render.update(); - // } - - - return 0; -} diff --git a/src/example/game.cpp b/src/example/game.cpp new file mode 100644 index 0000000..a9f6103 --- /dev/null +++ b/src/example/game.cpp @@ -0,0 +1,89 @@ +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +using namespace crepe; + +using namespace std; + +class MyScript : public Script { + static bool oncollision(const CollisionEvent& test) { + std::cout << "test collision: " << test.info.first.collider.game_object_id << std::endl; + return true; + } + void init() { + EventManager::get_instance().subscribe(oncollision, this->get_game_object_id()); + } + void update() { + // Retrieve component from the same GameObject this script is on + + } +}; + +class ConcreteScene1 : public Scene { +public: + using Scene::Scene; + + void load_scene() { + ComponentManager & mgr = this->component_manager; + Color color(0, 0, 0, 0); + + double screen_size_width = 640; + double screen_size_height = 480; + double world_collider = 1000; + //define playable world + GameObject world = mgr.new_object("Name", "Tag", Vector2{screen_size_width/2, screen_size_height/2}, 0, 1); + world.add_component(Rigidbody::Data{ + .mass = 0, + .gravity_scale = 0, + .body_type = Rigidbody::BodyType::STATIC, + .constraints = {0, 0, 0}, + .use_gravity = false, + .bounce = false, + .offset = {0,0} + }); + world.add_component(Vector2{0, 0-(screen_size_height/2+world_collider/2)}, world_collider, world_collider);; // Top + world.add_component(Vector2{0, screen_size_height/2+world_collider/2}, world_collider, world_collider); // Bottom + world.add_component(Vector2{0-(screen_size_width/2+world_collider/2), 0}, world_collider, world_collider); // Left + world.add_component(Vector2{screen_size_width/2+world_collider/2, 0}, world_collider, world_collider); // right + + + GameObject game_object1 = mgr.new_object("Name", "Tag", Vector2{screen_size_width/2, screen_size_height/2}, 0, 1); + game_object1.add_component(Rigidbody::Data{ + .mass = 1, + .gravity_scale = 0.01, + .body_type = Rigidbody::BodyType::DYNAMIC, + .linear_velocity = {1,0}, + .constraints = {0, 0, 0}, + .use_gravity = true, + .bounce = true, + .elastisity = 1, + .offset = {0,0}, + }); + game_object1.add_component(Vector2{0, 0}, 20, 20); + game_object1.add_component().set_script(); + game_object1.add_component( + make_shared("/home/jaro/crepe/asset/texture/green_square.png"), color, + FlipSettings{true, true}); + game_object1.add_component(Color::get_white()); + } +}; + +int main(int argc, char * argv[]) { + + LoopManager gameloop; + gameloop.scene_manager.add_scene("scene1"); + gameloop.scene_manager.load_next_scene(); + gameloop.start(); + return 0; +} diff --git a/src/example/particles.cpp b/src/example/particles.cpp deleted file mode 100644 index 3d5f676..0000000 --- a/src/example/particles.cpp +++ /dev/null @@ -1,43 +0,0 @@ -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include - -using namespace crepe; -using namespace std; - -int main(int argc, char * argv[]) { - ComponentManager mgr{}; - GameObject game_object = mgr.new_object("", "", Vector2{0, 0}, 0, 0); - Color color(0, 0, 0, 0); - Sprite test_sprite = game_object.add_component( - make_shared("../asset/texture/img.png"), color, FlipSettings{true, true}); - game_object.add_component(ParticleEmitter::Data{ - .position = {0, 0}, - .max_particles = 100, - .emission_rate = 0, - .min_speed = 0, - .max_speed = 0, - .min_angle = 0, - .max_angle = 0, - .begin_lifespan = 0, - .end_lifespan = 0, - .force_over_time = Vector2{0, 0}, - .boundary{ - .width = 0, - .height = 0, - .offset = Vector2{0, 0}, - .reset_on_exit = false, - }, - .sprite = test_sprite, - }); - - return 0; -} diff --git a/src/example/physics.cpp b/src/example/physics.cpp deleted file mode 100644 index ad663a0..0000000 --- a/src/example/physics.cpp +++ /dev/null @@ -1,24 +0,0 @@ -#include -#include -#include -#include -#include -#include - -using namespace crepe; -using namespace std; - -int main(int argc, char * argv[]) { - ComponentManager mgr{}; - - GameObject game_object = mgr.new_object("Name", "Tag", Vector2{0, 0}, 0, 0); - game_object.add_component(Rigidbody::Data{ - .mass = 1, - .gravity_scale = 1, - .body_type = Rigidbody::BodyType::DYNAMIC, - .constraints = {0, 0, 0}, - .use_gravity = true, - .bounce = false, - }); - return 0; -} diff --git a/src/example/rendering.cpp b/src/example/rendering.cpp index c9e62f1..14ecaa9 100644 --- a/src/example/rendering.cpp +++ b/src/example/rendering.cpp @@ -30,13 +30,13 @@ int main() { // Normal adding components { Color color(0, 0, 0, 0); - obj.add_component(make_shared("../asset/texture/img.png"), color, + obj.add_component(make_shared("/home/jaro/crepe/asset/texture/green_square.png"), color, FlipSettings{false, false}); obj.add_component(Color::get_red()); } { Color color(0, 0, 0, 0); - obj1.add_component(make_shared("../asset/texture/second.png"), color, + obj1.add_component(make_shared("/home/jaro/crepe/asset/texture/green_square.png"), color, FlipSettings{true, true}); } -- cgit v1.2.3