diff options
author | WBoerenkamps <wrj.boerenkamps@student.avans.nl> | 2024-12-12 19:48:18 +0100 |
---|---|---|
committer | WBoerenkamps <wrj.boerenkamps@student.avans.nl> | 2024-12-12 19:48:18 +0100 |
commit | 8cb43ae9ce445c757274874934c30f815b3b6108 (patch) | |
tree | 47e2d09223995b122cab3be6af0a5d6dd09dfbbd /src/example/game.cpp | |
parent | f7b4866811c63ae24c366d9452e53d24e504336f (diff) | |
parent | fd403d038b017ec8976023471073329896035e36 (diff) |
Merge branch 'master' of https://github.com/lonkaars/crepe into wouter/gameloop
Diffstat (limited to 'src/example/game.cpp')
-rw-r--r-- | src/example/game.cpp | 45 |
1 files changed, 31 insertions, 14 deletions
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; } |