aboutsummaryrefslogtreecommitdiff
path: root/src/example
diff options
context:
space:
mode:
authorJAROWMR <jarorutjes07@gmail.com>2024-11-20 10:43:32 +0100
committerJAROWMR <jarorutjes07@gmail.com>2024-11-20 10:43:32 +0100
commit690471c7c4536c074a4dca5aab7cc618d47bfb5f (patch)
tree35dcf3858b8f86a031cf5070de9caa069af4257d /src/example
parentd81ecc242ff88ffd49e0b5296dfb23ab54a0cd78 (diff)
merge with maser
Diffstat (limited to 'src/example')
-rw-r--r--src/example/CMakeLists.txt2
-rw-r--r--src/example/game.cpp (renamed from src/example/collision.cpp)84
-rw-r--r--src/example/particles.cpp43
-rw-r--r--src/example/physics.cpp24
-rw-r--r--src/example/rendering.cpp4
5 files changed, 28 insertions, 129 deletions
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/game.cpp
index f51380e..a9f6103 100644
--- a/src/example/collision.cpp
+++ b/src/example/game.cpp
@@ -1,31 +1,19 @@
-#include "api/BoxCollider.h"
-#include "system/CollisionSystem.h"
-#include <crepe/system/ScriptSystem.h>
-#include <crepe/Component.h>
-#include <crepe/ComponentManager.h>
#include <crepe/api/GameObject.h>
+#include <crepe/api/Transform.h>
#include <crepe/api/Rigidbody.h>
#include <crepe/api/BoxCollider.h>
-#include <crepe/api/Transform.h>
-#include <crepe/system/PhysicsSystem.h>
-#include <crepe/system/RenderSystem.h>
-#include <crepe/util/log.h>
-
+#include <crepe/api/Camera.h>
#include <crepe/api/Script.h>
-#include <crepe/api/AssetManager.h>
#include <crepe/api/Color.h>
#include <crepe/api/Sprite.h>
#include <crepe/api/Texture.h>
-#include <crepe/api/Transform.h>
#include <crepe/api/Vector2.h>
#include <crepe/api/Event.h>
#include <crepe/api/EventManager.h>
#include <crepe/api/LoopManager.h>
-#include <chrono>
-#include <memory>
-
using namespace crepe;
+
using namespace std;
class MyScript : public Script {
@@ -34,27 +22,28 @@ class MyScript : public Script {
return true;
}
void init() {
- EventManager::get_instance().subscribe<CollisionEvent>(oncollision, this->parent->game_object_id);
+ EventManager::get_instance().subscribe<CollisionEvent>(oncollision, this->get_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);
+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(0, "Name", "Tag", Vector2{screen_size_width/2, screen_size_height/2}, 0, 1);
- World.add_component<Rigidbody>(Rigidbody::Data{
+ GameObject world = mgr.new_object("Name", "Tag", Vector2{screen_size_width/2, screen_size_height/2}, 0, 1);
+ world.add_component<Rigidbody>(Rigidbody::Data{
.mass = 0,
.gravity_scale = 0,
.body_type = Rigidbody::BodyType::STATIC,
@@ -63,13 +52,13 @@ int main(int argc, char * argv[]) {
.bounce = false,
.offset = {0,0}
});
- World.add_component<BoxCollider>(Vector2{0, 0-(screen_size_height/2+world_collider/2)}, world_collider, world_collider);; // Top
- World.add_component<BoxCollider>(Vector2{0, screen_size_height/2+world_collider/2}, world_collider, world_collider); // Bottom
- World.add_component<BoxCollider>(Vector2{0-(screen_size_width/2+world_collider/2), 0}, world_collider, world_collider); // Left
- World.add_component<BoxCollider>(Vector2{screen_size_width/2+world_collider/2, 0}, world_collider, world_collider); // right
+ world.add_component<BoxCollider>(Vector2{0, 0-(screen_size_height/2+world_collider/2)}, world_collider, world_collider);; // Top
+ world.add_component<BoxCollider>(Vector2{0, screen_size_height/2+world_collider/2}, world_collider, world_collider); // Bottom
+ world.add_component<BoxCollider>(Vector2{0-(screen_size_width/2+world_collider/2), 0}, world_collider, world_collider); // Left
+ world.add_component<BoxCollider>(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);
+ GameObject game_object1 = mgr.new_object("Name", "Tag", Vector2{screen_size_width/2, screen_size_height/2}, 0, 1);
game_object1.add_component<Rigidbody>(Rigidbody::Data{
.mass = 1,
.gravity_scale = 0.01,
@@ -87,37 +76,14 @@ int main(int argc, char * argv[]) {
make_shared<Texture>("/home/jaro/crepe/asset/texture/green_square.png"), color,
FlipSettings{true, true});
game_object1.add_component<Camera>(Color::get_white());
-
-
- // GameObject game_object2(2, "Name", "Tag", Vector2{20, 470}, 0, 1);
- // game_object2.add_component<Rigidbody>(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<BoxCollider>(Vector2{0, 0}, 0, 0);
- // game_object2.add_component<BehaviorScript>().set_script<MyScript>();
- // game_object2.add_component<Sprite>(
- // make_shared<Texture>("/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();
- // }
+ }
+};
+int main(int argc, char * argv[]) {
+ LoopManager gameloop;
+ gameloop.scene_manager.add_scene<ConcreteScene1>("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 <crepe/ComponentManager.h>
-#include <crepe/api/AssetManager.h>
-
-#include <crepe/Component.h>
-#include <crepe/api/Color.h>
-#include <crepe/api/GameObject.h>
-#include <crepe/api/ParticleEmitter.h>
-#include <crepe/api/Rigidbody.h>
-#include <crepe/api/Sprite.h>
-#include <crepe/api/Texture.h>
-#include <crepe/api/Transform.h>
-
-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<Sprite>(
- make_shared<Texture>("../asset/texture/img.png"), color, FlipSettings{true, true});
- game_object.add_component<ParticleEmitter>(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 <crepe/Component.h>
-#include <crepe/ComponentManager.h>
-#include <crepe/api/GameObject.h>
-#include <crepe/api/Rigidbody.h>
-#include <crepe/api/Transform.h>
-#include <crepe/system/PhysicsSystem.h>
-
-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>(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<Sprite>(make_shared<Texture>("../asset/texture/img.png"), color,
+ obj.add_component<Sprite>(make_shared<Texture>("/home/jaro/crepe/asset/texture/green_square.png"), color,
FlipSettings{false, false});
obj.add_component<Camera>(Color::get_red());
}
{
Color color(0, 0, 0, 0);
- obj1.add_component<Sprite>(make_shared<Texture>("../asset/texture/second.png"), color,
+ obj1.add_component<Sprite>(make_shared<Texture>("/home/jaro/crepe/asset/texture/green_square.png"), color,
FlipSettings{true, true});
}