diff options
author | Loek Le Blansch <loek@pipeframe.xyz> | 2024-12-17 15:08:28 +0100 |
---|---|---|
committer | Loek Le Blansch <loek@pipeframe.xyz> | 2024-12-17 15:08:28 +0100 |
commit | 3a785620908f7ebc4299f974b7833afcb7d52a2f (patch) | |
tree | fc6a879da463327215918e9ff3034a157e106205 | |
parent | 9232a98b72eee7af4f7f2153c1b2ccedbfa4cc65 (diff) |
create bug MWEloek/bounce-vel-bug
-rw-r--r--[-rwxr-xr-x] | asset/texture/circle.png | bin | 509 -> 250 bytes | |||
-rw-r--r--[-rwxr-xr-x] | asset/texture/square.png | bin | 162 -> 136 bytes | |||
-rw-r--r-- | src/example/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/example/bounce-vel-bug.cpp | 68 |
4 files changed, 69 insertions, 0 deletions
diff --git a/asset/texture/circle.png b/asset/texture/circle.png Binary files differindex 0a92ac7..e81688c 100755..100644 --- a/asset/texture/circle.png +++ b/asset/texture/circle.png diff --git a/asset/texture/square.png b/asset/texture/square.png Binary files differindex d07ec98..15b98aa 100755..100644 --- a/asset/texture/square.png +++ b/asset/texture/square.png diff --git a/src/example/CMakeLists.txt b/src/example/CMakeLists.txt index 187ed46..89b2e6e 100644 --- a/src/example/CMakeLists.txt +++ b/src/example/CMakeLists.txt @@ -20,3 +20,4 @@ add_example(rendering_particle) add_example(game) add_example(button) add_example(AITest) +add_example(bounce-vel-bug) diff --git a/src/example/bounce-vel-bug.cpp b/src/example/bounce-vel-bug.cpp new file mode 100644 index 0000000..a1c3021 --- /dev/null +++ b/src/example/bounce-vel-bug.cpp @@ -0,0 +1,68 @@ +#include <crepe/api/LoopManager.h> +#include <crepe/api/Scene.h> +#include <crepe/api/Camera.h> +#include <crepe/api/Rigidbody.h> +#include <crepe/api/BoxCollider.h> + +using namespace crepe; +using namespace std; + +class DemoScene : public Scene { + virtual std::string get_name() const override { return "aa"; } + void load_scene() override { + GameObject camera = new_object("camera"); + camera.add_component<Camera>(ivec2{800, 800}, vec2{10, 10}, Camera::Data{ + .bg_color = {0x22, 0x22, 0x22}, + }); + + + GameObject ground = new_object("ground", "", vec2{0, 4}); + Sprite & ground_sprite = ground.add_component<Sprite>( + Asset{"asset/texture/square.png"}, + Sprite::Data{ .size = {10, 2}, } + ); + ground.add_component<Rigidbody>(Rigidbody::Data{ + .gravity_scale = 1.0, + .body_type = Rigidbody::BodyType::STATIC, + }); + ground.add_component<BoxCollider>(ground_sprite.data.size); + + + GameObject bouncy = new_object("bouncy", "", vec2{-4, 0}); + bouncy.add_component<Sprite>( + Asset{"asset/texture/square.png"}, + Sprite::Data{ + .color = Color::GREEN, + .size = { 1, 1 }, + } + ); + bouncy.add_component<Rigidbody>(Rigidbody::Data{ + .gravity_scale = 1.0, + .linear_velocity = {1, 0}, + .elastisity_coefficient = 0.6, + }); + bouncy.add_component<BoxCollider>(vec2{1, 1}); + + GameObject stiff = new_object("stiff", "", vec2{-4, 0}); + stiff.add_component<Sprite>( + Asset{"asset/texture/square.png"}, + Sprite::Data{ + .color = Color::RED, + .size = { 1, 1 }, + } + ); + stiff.add_component<Rigidbody>(Rigidbody::Data{ + .gravity_scale = 1.0, + .linear_velocity = {1, 0}, + .elastisity_coefficient = 0.0, + }); + stiff.add_component<BoxCollider>(vec2{1, 1}); + } +}; + +int main() { + LoopManager example; + example.add_scene<DemoScene>(); + example.start(); + return 0; +} |