summaryrefslogtreecommitdiff
path: root/2d/_collisions/rectangle_rectangle
diff options
context:
space:
mode:
Diffstat (limited to '2d/_collisions/rectangle_rectangle')
-rwxr-xr-x2d/_collisions/rectangle_rectangle/dist/output.wasmbin55607 -> 55719 bytes
-rw-r--r--2d/_collisions/rectangle_rectangle/main.cpp8
2 files changed, 7 insertions, 1 deletions
diff --git a/2d/_collisions/rectangle_rectangle/dist/output.wasm b/2d/_collisions/rectangle_rectangle/dist/output.wasm
index 5a17a67..f61e371 100755
--- a/2d/_collisions/rectangle_rectangle/dist/output.wasm
+++ b/2d/_collisions/rectangle_rectangle/dist/output.wasm
Binary files differ
diff --git a/2d/_collisions/rectangle_rectangle/main.cpp b/2d/_collisions/rectangle_rectangle/main.cpp
index 99dafe5..689ea11 100644
--- a/2d/_collisions/rectangle_rectangle/main.cpp
+++ b/2d/_collisions/rectangle_rectangle/main.cpp
@@ -398,19 +398,25 @@ void update(float32 deltaTimeSeconds, void* userData) {
}
}
- // Check collisions with walls
+ // Check collisions with walls.
+ // @NOTE: Setting the position backwards by a small amount _could_ move it into another object, but we are ignoring that circumstance
+ // for now, as it is very unlikely.
for (int r = 0; r < 4; r++) {
Rectangle* rect = &rectangleList[r];
if (rect->body.position.x <= 0.f) {
+ rect->body.position.x = 0.f;
rect->body.velocity = rect->body.velocity - Vector2 { 1.f, 0.f } * (2 * (rect->body.velocity.dot(Vector2 { 1.f, 0.f })));
}
if (rect->body.position.y <= 0.f) {
+ rect->body.position.y = 0.f;
rect->body.velocity = rect->body.velocity - Vector2 { 0.f, 1.f } * (2 * (rect->body.velocity.dot(Vector2 { 0.f, 1.f })));
}
if (rect->body.position.x >= 640.f) {
+ rect->body.position.x = 640.f;
rect->body.velocity = rect->body.velocity - Vector2 { -1.f, 0.f } * (2 * (rect->body.velocity.dot(Vector2{ -1.f, 0.f })));
}
if (rect->body.position.y >= 480.f) {
+ rect->body.position.y = 480.f;
rect->body.velocity = rect->body.velocity - Vector2 { 0.f, -1.f } * (2 * (rect->body.velocity.dot(Vector2 { 0.f, -1.f }))) ;
}
}