aboutsummaryrefslogtreecommitdiff
path: root/src/brothers.zig
diff options
context:
space:
mode:
authorJulien Dessaux2022-09-22 23:05:21 +0200
committerJulien Dessaux2022-09-22 23:05:21 +0200
commit085df94d383506dd44b6a27894b32501f9e1b5a9 (patch)
tree5e80361546f5dedd501778bb6c723b041f482ea5 /src/brothers.zig
parentBegan rewriting the game as a wasm4 cartridge (diff)
downloadgrenade-brothers-085df94d383506dd44b6a27894b32501f9e1b5a9.tar.gz
grenade-brothers-085df94d383506dd44b6a27894b32501f9e1b5a9.tar.bz2
grenade-brothers-085df94d383506dd44b6a27894b32501f9e1b5a9.zip
Implemented brothers movements
Diffstat (limited to '')
-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 ----------------------------------------------------------------