aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulien Dessaux2022-09-22 23:24:37 +0200
committerJulien Dessaux2022-09-22 23:24:37 +0200
commita945de3218e3cf9593fa21bcc6d8af04de4443ef (patch)
treefbdf8b64290388c87681ec554560b20ff0ab1b9b
parentImplemented brothers movements (diff)
downloadgrenade-brothers-a945de3218e3cf9593fa21bcc6d8af04de4443ef.tar.gz
grenade-brothers-a945de3218e3cf9593fa21bcc6d8af04de4443ef.tar.bz2
grenade-brothers-a945de3218e3cf9593fa21bcc6d8af04de4443ef.zip
Added brothers jumping
-rw-r--r--src/brothers.zig9
-rw-r--r--src/utils.zig3
2 files changed, 11 insertions, 1 deletions
diff --git a/src/brothers.zig b/src/brothers.zig
index 6121841..c3bde96 100644
--- a/src/brothers.zig
+++ b/src/brothers.zig
@@ -28,6 +28,15 @@ pub const Brother = struct {
self.x -= 1;
if (gamepad.held.right and self.x <= utils.rightLimit[@enumToInt(self.side)] - brother_width)
self.x += 1;
+ if (self.y < 160) { // jumping!
+ self.vy += utils.gravity;
+ self.y += self.vy * utils.frequency;
+ if (self.y > 160)
+ self.y = 160;
+ } else if (gamepad.pressed.up) {
+ self.vy = -200;
+ self.y += self.vy * utils.frequency;
+ }
}
};
diff --git a/src/utils.zig b/src/utils.zig
index 5fa40f9..bb9eb13 100644
--- a/src/utils.zig
+++ b/src/utils.zig
@@ -1,6 +1,7 @@
//----- Physics ---------------------------------------------------------------
pub const gravity: f64 = 9.807; // m/s²
-pub const scale: f64 = 1.0 / 30; // 30 pixels == 1m
+pub const scale: f64 = 1.0 / 30.0; // 30 pixels == 1m
+pub const frequency: f64 = 1.0 / 60.0; // 60 fps
//----- Playground ------------------------------------------------------------
pub const side = enum(u1) {