From 8dd5eff733e01df2728b270790acbace01435a91 Mon Sep 17 00:00:00 2001 From: Julien Dessaux Date: Tue, 16 Aug 2022 19:25:53 +0200 Subject: Implemented the jump command --- src/brothers.zig | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src/brothers.zig') diff --git a/src/brothers.zig b/src/brothers.zig index cf78988..1b34a6b 100644 --- a/src/brothers.zig +++ b/src/brothers.zig @@ -28,6 +28,11 @@ pub const Brother = struct { _ = try rc.buffer.writer().write(line); } } + pub fn moveJump(self: *Brother) void { + if (self.dy == 0) { // no double jumps! TODO allow kicks off the wall + self.dy -= 4 / (1000 / 60.0); + } + } pub fn moveLeft(self: *Brother) void { self.dx -= 5 / (1000 / 60.0); self.moveDuration = 24; @@ -37,6 +42,7 @@ pub const Brother = struct { self.moveDuration = 24; } pub fn step(self: *Brother) void { + // Horizontal movement const x = self.x + self.dx; const ll = leftLimit[@enumToInt(self.side)]; const rl = rightLimit[@enumToInt(self.side)]; @@ -57,6 +63,17 @@ pub const Brother = struct { } } } + // Vertical movement + const y = self.y + self.dy; + if (y < 12) { // jumping + self.y = 12; + self.dy = -self.dy; + } else if (y > 17) { // falling + self.y = 17; + self.dy = 0; + } else { + self.y = y; + } } pub fn reset(self: *Brother, side: ?Side) void { if (side) |s| { -- cgit v1.2.3