From 085df94d383506dd44b6a27894b32501f9e1b5a9 Mon Sep 17 00:00:00 2001 From: Julien Dessaux Date: Thu, 22 Sep 2022 23:05:21 +0200 Subject: Implemented brothers movements --- src/brothers.zig | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src/brothers.zig') diff --git a/src/brothers.zig b/src/brothers.zig index 3b92de4..6121841 100644 --- a/src/brothers.zig +++ b/src/brothers.zig @@ -1,3 +1,4 @@ +const inputs = @import("inputs.zig"); const std = @import("std"); const utils = @import("utils.zig"); const w4 = @import("wasm4.zig"); @@ -5,8 +6,10 @@ const w4 = @import("wasm4.zig"); pub const Brother = struct { side: utils.side, score: u8, + // position of the bottom left corner x: u8, y: f64, + vy: f64, pub fn draw(self: Brother) void { var y = @floatToInt(u8, std.math.round(self.y)); w4.DRAW_COLORS.* = 0x30; @@ -20,6 +23,12 @@ pub const Brother = struct { self.x = utils.startingX[@enumToInt(self.side)]; self.y = 160; } + pub fn update(self: *Brother, gamepad: inputs.Gamepad) void { + if (gamepad.held.left and self.x > utils.leftLimit[@enumToInt(self.side)]) + self.x -= 1; + if (gamepad.held.right and self.x <= utils.rightLimit[@enumToInt(self.side)] - brother_width) + self.x += 1; + } }; //----- Sprite ---------------------------------------------------------------- -- cgit v1.2.3