aboutsummaryrefslogtreecommitdiff
path: root/src/example/game.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/example/game.cpp')
-rw-r--r--src/example/game.cpp71
1 files changed, 56 insertions, 15 deletions
diff --git a/src/example/game.cpp b/src/example/game.cpp
index 61f8760..a8b3d5d 100644
--- a/src/example/game.cpp
+++ b/src/example/game.cpp
@@ -1,8 +1,10 @@
#include "api/CircleCollider.h"
+#include "api/ParticleEmitter.h"
#include "api/Scene.h"
#include "manager/ComponentManager.h"
#include "manager/Mediator.h"
#include "types.h"
+#include <cmath>
#include <crepe/api/BoxCollider.h>
#include <crepe/api/Camera.h>
#include <crepe/api/Color.h>
@@ -67,11 +69,6 @@ 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;
}
@@ -140,6 +137,31 @@ class MyScript2 : public Script {
//add collider switch
break;
}
+ case Keycode::J: {
+ Rigidbody & tf = this->get_component<Rigidbody>();
+ tf.data.linear_velocity.x = -10;
+ break;
+ }
+ case Keycode::I: {
+ Rigidbody & tf = this->get_component<Rigidbody>();
+ tf.data.linear_velocity.y -= 1;
+ break;
+ }
+ case Keycode::K: {
+ Rigidbody & tf = this->get_component<Rigidbody>();
+ tf.data.linear_velocity.y += 1;
+ break;
+ }
+ case Keycode::L: {
+ Rigidbody & tf = this->get_component<Rigidbody>();
+ tf.data.linear_velocity.x = 10;
+ break;
+ }
+ case Keycode::O: {
+ Rigidbody & tf = this->get_component<Rigidbody>();
+ tf.data.linear_velocity.x = 0;
+ break;
+ }
default:
break;
}
@@ -176,7 +198,6 @@ public:
.mass = 0,
.gravity_scale = 0,
.body_type = Rigidbody::BodyType::STATIC,
- .offset = {0, 0},
});
world.add_component<BoxCollider>(
vec2{world_collider, world_collider},
@@ -199,23 +220,25 @@ public:
});
GameObject game_object1 = new_object(
- "Name", "Tag", vec2{screen_size_width / 2, screen_size_height / 2}, 0, 1);
+ "Name", "Tag", vec2{screen_size_width / 2, screen_size_height / 2}, 45, 1);
game_object1.add_component<Rigidbody>(Rigidbody::Data{
.mass = 1,
- .gravity_scale = 1,
- .body_type = Rigidbody::BodyType::DYNAMIC,
+ .gravity_scale = 0,
+ .body_type = Rigidbody::BodyType::KINEMATIC,
.linear_velocity = {0, 1},
.constraints = {0, 0, 0},
- .elastisity_coefficient = 0,
- .offset = {0, 0},
+ .elastisity_coefficient = 1,
});
// add box with boxcollider
game_object1.add_component<BoxCollider>(vec2{20, 20});
game_object1.add_component<BehaviorScript>().set_script<MyScript1>();
- Asset img1{"asset/texture/square.png"};
+ Asset img1{"asset/texture/test_ap43.png"};
game_object1.add_component<Sprite>(img1, Sprite::Data{
+ .sorting_in_layer = 2,
+ .order_in_layer = 2,
.size = {20, 20},
+ .position_offset = {0, -10},
});
//add circle with cirlcecollider deactiveated
@@ -233,12 +256,11 @@ public:
"Name", "Tag", vec2{screen_size_width / 2, screen_size_height / 2}, 0, 1);
game_object2.add_component<Rigidbody>(Rigidbody::Data{
.mass = 1,
- .gravity_scale = 0,
- .body_type = Rigidbody::BodyType::STATIC,
+ .gravity_scale = 1,
+ .body_type = Rigidbody::BodyType::KINEMATIC,
.linear_velocity = {0, 0},
.constraints = {0, 0, 0},
.elastisity_coefficient = 1,
- .offset = {0, 0},
});
// add box with boxcollider
game_object2.add_component<BoxCollider>(vec2{20, 20});
@@ -258,6 +280,25 @@ public:
})
.active
= false;
+ Asset img5{"asset/texture/square.png"};
+
+ GameObject particle = new_object(
+ "Name", "Tag", vec2{screen_size_width / 2, screen_size_height / 2}, 0, 1);
+ auto & particle_image = particle.add_component<Sprite>(img5, Sprite::Data{
+ .size = {5, 5},
+ });
+ auto & test
+ = particle.add_component<ParticleEmitter>(particle_image, ParticleEmitter::Data{
+ .offset = {0, 0},
+ .max_particles = 256,
+ .emission_rate = 1,
+ .min_speed = 10,
+ .max_speed = 20,
+ .min_angle = -20,
+ .max_angle = 20,
+ .begin_lifespan = 0,
+ .end_lifespan = 5,
+ });
}
string get_name() const { return "scene1"; }