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, 50 insertions, 21 deletions
diff --git a/src/example/game.cpp b/src/example/game.cpp
index 3975650..76ea8c2 100644
--- a/src/example/game.cpp
+++ b/src/example/game.cpp
@@ -4,6 +4,7 @@
#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>
@@ -23,7 +24,7 @@ using namespace std;
class MyScript1 : public Script {
bool flip = false;
bool oncollision(const CollisionEvent & test) {
- Log::logf("Box {} script on_collision()", test.info.this_collider.game_object_id);
+ Log::logf("Box {} script on_collision()", test.info.self.metadata.game_object_id);
return true;
}
bool keypressed(const KeyPressEvent & test) {
@@ -68,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;
}
@@ -97,7 +93,7 @@ class MyScript1 : public Script {
class MyScript2 : public Script {
bool flip = false;
bool oncollision(const CollisionEvent & test) {
- Log::logf("Box {} script on_collision()", test.info.this_collider.game_object_id);
+ Log::logf("Box {} script on_collision()", test.info.self.metadata.game_object_id);
return true;
}
bool keypressed(const KeyPressEvent & test) {
@@ -141,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;
}
@@ -174,10 +195,9 @@ public:
GameObject world = new_object(
"Name", "Tag", vec2{screen_size_width / 2, screen_size_height / 2}, 0, 1);
world.add_component<Rigidbody>(Rigidbody::Data{
- .mass = 0,
+ .mass = 1,
.gravity_scale = 0,
- .body_type = Rigidbody::BodyType::STATIC,
- .offset = {0, 0},
+ .body_type = Rigidbody::BodyType::DYNAMIC,
});
world.add_component<BoxCollider>(
vec2{world_collider, world_collider},
@@ -200,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+20}, 0, 1);
game_object1.add_component<Rigidbody>(Rigidbody::Data{
.mass = 1,
- .gravity_scale = 1,
+ .gravity_scale = 0,
.body_type = Rigidbody::BodyType::DYNAMIC,
- .linear_velocity = {0, 1},
+ .linear_velocity = {0, 0},
.constraints = {0, 0, 0},
- .elastisity_coefficient = 0,
- .offset = {0, 0},
+ .elasticity_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, 0},
});
//add circle with cirlcecollider deactiveated
@@ -231,15 +253,14 @@ public:
= false;
GameObject game_object2 = 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}, 90, 1);
game_object2.add_component<Rigidbody>(Rigidbody::Data{
.mass = 1,
.gravity_scale = 0,
.body_type = Rigidbody::BodyType::STATIC,
.linear_velocity = {0, 0},
.constraints = {0, 0, 0},
- .elastisity_coefficient = 1,
- .offset = {0, 0},
+ .elasticity_coefficient = 1,
});
// add box with boxcollider
game_object2.add_component<BoxCollider>(vec2{20, 20});
@@ -247,6 +268,9 @@ public:
game_object2.add_component<Sprite>(img1, Sprite::Data{
.size = {20, 20},
+ .angle_offset = 45,
+ .scale_offset = 1,
+ .position_offset = {0,20},
});
//add circle with cirlcecollider deactiveated
@@ -262,15 +286,17 @@ public:
Asset img5{"asset/texture/square.png"};
GameObject particle = 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}, 90, 1);
auto & particle_image = particle.add_component<Sprite>(img5, Sprite::Data{
.size = {5, 5},
+ .angle_offset = 45,
+ .scale_offset = 1,
});
auto & test
= particle.add_component<ParticleEmitter>(particle_image, ParticleEmitter::Data{
.offset = {0, 0},
.max_particles = 256,
- .emission_rate = 1,
+ .emission_rate = 4,
.min_speed = 10,
.max_speed = 20,
.min_angle = -20,
@@ -278,6 +304,9 @@ public:
.begin_lifespan = 0,
.end_lifespan = 5,
});
+ particle.add_component<Rigidbody>(Rigidbody::Data{
+ .angular_velocity = 20,
+ });
}
string get_name() const { return "scene1"; }