diff options
author | Jaro <59013720+JaroWMR@users.noreply.github.com> | 2024-12-12 18:47:54 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-12-12 18:47:54 +0100 |
commit | fd403d038b017ec8976023471073329896035e36 (patch) | |
tree | fcf4af55aa56b2de19e87e5246888e1af9f4f527 /src/example | |
parent | 05a33d4793520fa84a93bc79882ef29d39cd08e5 (diff) | |
parent | ab1423f48d82ba9b0619ec107639a80773edbfc2 (diff) |
Merge pull request #64 from lonkaars/jaro/physics-system-improvement
Jaro/physics system improvement
Diffstat (limited to 'src/example')
-rw-r--r-- | src/example/AITest.cpp | 24 | ||||
-rw-r--r-- | src/example/game.cpp | 45 |
2 files changed, 45 insertions, 24 deletions
diff --git a/src/example/AITest.cpp b/src/example/AITest.cpp index f4efc9f..93ba500 100644 --- a/src/example/AITest.cpp +++ b/src/example/AITest.cpp @@ -8,7 +8,6 @@ #include <crepe/api/Scene.h> #include <crepe/api/Script.h> #include <crepe/api/Sprite.h> -#include <crepe/api/Texture.h> #include <crepe/manager/Mediator.h> #include <crepe/types.h> @@ -47,14 +46,19 @@ public: GameObject game_object1 = mgr.new_object("", "", vec2{0, 0}, 0, 1); GameObject game_object2 = mgr.new_object("", "", vec2{0, 0}, 0, 1); - Texture img = Texture("asset/texture/test_ap43.png"); - game_object1.add_component<Sprite>(img, Sprite::Data{ - .color = Color::MAGENTA, - .flip = Sprite::FlipSettings{false, false}, - .sorting_in_layer = 1, - .order_in_layer = 1, - .size = {0, 195}, - }); + Asset img{"asset/texture/test_ap43.png"}; + + Sprite & test_sprite = game_object1.add_component<Sprite>( + img, Sprite::Data{ + .color = Color::MAGENTA, + .flip = Sprite::FlipSettings{false, false}, + .sorting_in_layer = 2, + .order_in_layer = 2, + .size = {0, 100}, + .angle_offset = 0, + .position_offset = {0, 0}, + }); + AI & ai = game_object1.add_component<AI>(3000); // ai.arrive_on(); // ai.flee_on(); @@ -63,7 +67,7 @@ public: ai.make_oval_path(1000, 500, {0, 500}, 4.7124, false); game_object1.add_component<Rigidbody>(Rigidbody::Data{ .mass = 0.1f, - .max_linear_velocity = {40, 40}, + .max_linear_velocity = 40, }); game_object1.add_component<BehaviorScript>().set_script<Script1>(); diff --git a/src/example/game.cpp b/src/example/game.cpp index 4239c15..5361f3a 100644 --- a/src/example/game.cpp +++ b/src/example/game.cpp @@ -2,6 +2,7 @@ #include "api/Scene.h" #include "manager/ComponentManager.h" #include "manager/Mediator.h" +#include "types.h" #include <crepe/api/BoxCollider.h> #include <crepe/api/Camera.h> #include <crepe/api/Color.h> @@ -11,7 +12,6 @@ #include <crepe/api/Rigidbody.h> #include <crepe/api/Script.h> #include <crepe/api/Sprite.h> -#include <crepe/api/Texture.h> #include <crepe/api/Transform.h> #include <crepe/api/Vector2.h> @@ -66,6 +66,11 @@ class MyScript1 : public Script { //add collider switch break; } + case Keycode::Q: { + Rigidbody & rg = this->get_component<Rigidbody>(); + rg.data.angular_velocity = 1; + break; + } default: break; } @@ -184,15 +189,18 @@ public: world.add_component<BoxCollider>(vec2{screen_size_width / 2 + world_collider / 2, 0}, vec2{world_collider, world_collider}); // right world.add_component<Camera>( - Color::WHITE, ivec2{static_cast<int>(screen_size_width), static_cast<int>(screen_size_height)}, - vec2{screen_size_width, screen_size_height}, 1.0f); + vec2{screen_size_width, screen_size_height}, + Camera::Data{ + .bg_color = Color::WHITE, + .zoom = 1, + }); GameObject game_object1 = mgr.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 = 0, + .gravity_scale = 1, .body_type = Rigidbody::BodyType::DYNAMIC, .linear_velocity = {0, 0}, .constraints = {0, 0, 0}, @@ -203,15 +211,20 @@ public: // add box with boxcollider game_object1.add_component<BoxCollider>(vec2{0, 0}, vec2{20, 20}); game_object1.add_component<BehaviorScript>().set_script<MyScript1>(); - auto img1 = Texture("asset/texture/square.png"); - game_object1.add_component<Sprite>(img1, color, Sprite::FlipSettings{false, false}, 1, - 1, 20); + + Asset img1{"asset/texture/square.png"}; + game_object1.add_component<Sprite>(img1, Sprite::Data{ + .size = {20, 20}, + }); //add circle with cirlcecollider deactiveated game_object1.add_component<CircleCollider>(vec2{0, 0}, 10).active = false; - auto img2 = Texture("asset/texture/circle.png"); + Asset img2{"asset/texture/circle.png"}; game_object1 - .add_component<Sprite>(img2, color, Sprite::FlipSettings{false, false}, 1, 1, 20) + .add_component<Sprite>(img2, + Sprite::Data{ + .size = {20, 20}, + }) .active = false; @@ -230,15 +243,19 @@ public: // add box with boxcollider game_object2.add_component<BoxCollider>(vec2{0, 0}, vec2{20, 20}); game_object2.add_component<BehaviorScript>().set_script<MyScript2>(); - auto img3 = Texture("asset/texture/square.png"); - game_object2.add_component<Sprite>(img3, color, Sprite::FlipSettings{false, false}, 1, - 1, 20); + + game_object2.add_component<Sprite>(img1, Sprite::Data{ + .size = {20, 20}, + }); //add circle with cirlcecollider deactiveated game_object2.add_component<CircleCollider>(vec2{0, 0}, 10).active = false; - auto img4 = Texture("asset/texture/circle.png"); + game_object2 - .add_component<Sprite>(img4, color, Sprite::FlipSettings{false, false}, 1, 1, 20) + .add_component<Sprite>(img2, + Sprite::Data{ + .size = {20, 20}, + }) .active = false; } |