aboutsummaryrefslogtreecommitdiff
path: root/src/brothers.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/brothers.zig')
-rw-r--r--src/brothers.zig9
1 files changed, 9 insertions, 0 deletions
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 ----------------------------------------------------------------