aboutsummaryrefslogtreecommitdiff
path: root/src/example
diff options
context:
space:
mode:
authorLoek Le Blansch <loek@pipeframe.xyz>2024-12-14 11:26:04 +0100
committerLoek Le Blansch <loek@pipeframe.xyz>2024-12-14 11:26:04 +0100
commitb86f87bec14d80bbb8e319bcebeca64764d2fb3c (patch)
tree3914bc77f4f7e9972b4994bb7565eb179648807a /src/example
parentb25d9438b3849efd0a6b6034d238eb36e23d6a5c (diff)
parent47cc992a4892d4f3de5702668033ad45ea43dd73 (diff)
Merge branch 'jaro/collision-system' of github.com:lonkaars/crepe
Diffstat (limited to 'src/example')
-rw-r--r--src/example/game.cpp23
1 files changed, 13 insertions, 10 deletions
diff --git a/src/example/game.cpp b/src/example/game.cpp
index 16fe18f..8ea50ea 100644
--- a/src/example/game.cpp
+++ b/src/example/game.cpp
@@ -29,23 +29,23 @@ class MyScript1 : public Script {
Log::logf("Box script keypressed()");
switch (test.key) {
case Keycode::A: {
- Transform & tf = this->get_component<Transform>();
- tf.position.x -= 1;
+ Rigidbody & tf = this->get_component<Rigidbody>();
+ tf.data.linear_velocity.x -= 1;
break;
}
case Keycode::W: {
- Transform & tf = this->get_component<Transform>();
- tf.position.y -= 1;
+ Rigidbody & tf = this->get_component<Rigidbody>();
+ tf.data.linear_velocity.y -= 1;
break;
}
case Keycode::S: {
- Transform & tf = this->get_component<Transform>();
- tf.position.y += 1;
+ Rigidbody & tf = this->get_component<Rigidbody>();
+ tf.data.linear_velocity.y += 1;
break;
}
case Keycode::D: {
- Transform & tf = this->get_component<Transform>();
- tf.position.x += 1;
+ Rigidbody & tf = this->get_component<Rigidbody>();
+ tf.data.linear_velocity.x += 1;
break;
}
case Keycode::E: {
@@ -85,7 +85,10 @@ class MyScript1 : public Script {
[this](const KeyPressEvent & ev) -> bool { return this->keypressed(ev); });
}
void update() {
- // Retrieve component from the same GameObject this script is on
+ Rigidbody & tf = this->get_component<Rigidbody>();
+ Log::logf("linear_velocity.x {}", tf.data.linear_velocity.x);
+ Log::logf("linear_velocity.y {}", tf.data.linear_velocity.y);
+ // tf.data.linear_velocity = {0,0};
}
};
@@ -200,7 +203,7 @@ public:
.mass = 1,
.gravity_scale = 1,
.body_type = Rigidbody::BodyType::DYNAMIC,
- .linear_velocity = {0, 0},
+ .linear_velocity = {0, 1},
.constraints = {0, 0, 0},
.elastisity_coefficient = 1,
.offset = {0, 0},