aboutsummaryrefslogtreecommitdiff
path: root/src/main.zig
diff options
context:
space:
mode:
authortslil clingman <>2021-09-12 21:40:58 -0400
committertslil clingman <>2021-09-12 21:40:58 -0400
commitd89f038b7a5eb42dd48d729d8808747d5cbc182b (patch)
tree2f726aef25edaf1723e62ec99e19c425afa37cdf /src/main.zig
parentb674e201cecf38ae719f76c0d159d8cbf00158ed (diff)
Walk bob and collision detection
Diffstat (limited to 'src/main.zig')
-rw-r--r--src/main.zig29
1 files changed, 19 insertions, 10 deletions
diff --git a/src/main.zig b/src/main.zig
index c44b5e6..ec47f86 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -133,24 +133,33 @@ pub fn main() !void {
if (isKeyPressed(.R)) player.ang += rotation;
if (isKeyPressed(.T)) player.ang -= rotation;
+ const cos = std.math.cos(player.ang);
+ const sin = std.math.sin(player.ang);
+
player.acc_x = 0;
player.acc_y = 0;
- const acc_mag = 50;
+ const acc_mag = 30;
if (isKeyPressed(.Right)) {
- player.acc_x += std.math.cos(player.ang - PI / 2.0) * acc_mag;
- player.acc_y += std.math.sin(player.ang - PI / 2.0) * acc_mag;
+ player.acc_x += sin;
+ player.acc_y -= cos;
}
if (isKeyPressed(.Left)) {
- player.acc_x -= std.math.cos(player.ang - PI / 2.0) * acc_mag;
- player.acc_y -= std.math.sin(player.ang - PI / 2.0) * acc_mag;
+ player.acc_x -= sin;
+ player.acc_y += cos;
}
if (isKeyPressed(.Up) or isKeyPressed(.F)) {
- player.acc_x += std.math.cos(player.ang) * acc_mag;
- player.acc_y += std.math.sin(player.ang) * acc_mag;
+ player.acc_x += cos;
+ player.acc_y += sin;
}
if (isKeyPressed(.Down) or isKeyPressed(.S)) {
- player.acc_x -= std.math.cos(player.ang) * acc_mag;
- player.acc_y -= std.math.sin(player.ang) * acc_mag;
+ player.acc_x -= cos;
+ player.acc_y -= sin;
+ }
+ // normalise
+ const a = std.math.sqrt(player.acc_x * player.acc_x + player.acc_y * player.acc_y);
+ if (a > 0) {
+ player.acc_x *= acc_mag / a;
+ player.acc_y *= acc_mag / a;
}
// First the background
@@ -177,6 +186,6 @@ pub fn main() !void {
window.display();
- player.tick();
+ player.tick(map);
}
}