Implemented brothers movements
This commit is contained in:
parent
8f76ba7826
commit
085df94d38
3 changed files with 24 additions and 3 deletions
|
@ -1,3 +1,4 @@
|
||||||
|
const inputs = @import("inputs.zig");
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const utils = @import("utils.zig");
|
const utils = @import("utils.zig");
|
||||||
const w4 = @import("wasm4.zig");
|
const w4 = @import("wasm4.zig");
|
||||||
|
@ -5,8 +6,10 @@ const w4 = @import("wasm4.zig");
|
||||||
pub const Brother = struct {
|
pub const Brother = struct {
|
||||||
side: utils.side,
|
side: utils.side,
|
||||||
score: u8,
|
score: u8,
|
||||||
|
// position of the bottom left corner
|
||||||
x: u8,
|
x: u8,
|
||||||
y: f64,
|
y: f64,
|
||||||
|
vy: f64,
|
||||||
pub fn draw(self: Brother) void {
|
pub fn draw(self: Brother) void {
|
||||||
var y = @floatToInt(u8, std.math.round(self.y));
|
var y = @floatToInt(u8, std.math.round(self.y));
|
||||||
w4.DRAW_COLORS.* = 0x30;
|
w4.DRAW_COLORS.* = 0x30;
|
||||||
|
@ -20,6 +23,12 @@ pub const Brother = struct {
|
||||||
self.x = utils.startingX[@enumToInt(self.side)];
|
self.x = utils.startingX[@enumToInt(self.side)];
|
||||||
self.y = 160;
|
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 ----------------------------------------------------------------
|
//----- Sprite ----------------------------------------------------------------
|
||||||
|
|
17
src/game.zig
17
src/game.zig
|
@ -1,14 +1,16 @@
|
||||||
|
const ball = @import("ball.zig");
|
||||||
|
const brothers = @import("brothers.zig");
|
||||||
|
const inputs = @import("inputs.zig");
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const utils = @import("utils.zig");
|
const utils = @import("utils.zig");
|
||||||
const w4 = @import("wasm4.zig");
|
const w4 = @import("wasm4.zig");
|
||||||
|
|
||||||
const ball = @import("ball.zig");
|
|
||||||
const brothers = @import("brothers.zig");
|
|
||||||
|
|
||||||
pub const Game = struct {
|
pub const Game = struct {
|
||||||
ball: ball.Ball = undefined,
|
ball: ball.Ball = undefined,
|
||||||
brothers: [2]brothers.Brother = undefined,
|
brothers: [2]brothers.Brother = undefined,
|
||||||
|
gamepads: [4]inputs.Gamepad = undefined,
|
||||||
playerSide: utils.side = undefined,
|
playerSide: utils.side = undefined,
|
||||||
|
|
||||||
pub fn draw(self: *Game) void {
|
pub fn draw(self: *Game) void {
|
||||||
self.ball.draw();
|
self.ball.draw();
|
||||||
self.brothers[0].draw();
|
self.brothers[0].draw();
|
||||||
|
@ -20,8 +22,17 @@ pub const Game = struct {
|
||||||
pub fn reset(self: *Game) void {
|
pub fn reset(self: *Game) void {
|
||||||
self.brothers[0].reset(.left);
|
self.brothers[0].reset(.left);
|
||||||
self.brothers[1].reset(.right);
|
self.brothers[1].reset(.right);
|
||||||
|
self.resetRound();
|
||||||
|
}
|
||||||
|
pub fn resetRound(self: *Game) void {
|
||||||
self.ball.resetRound(.left);
|
self.ball.resetRound(.left);
|
||||||
self.brothers[0].resetRound();
|
self.brothers[0].resetRound();
|
||||||
self.brothers[1].resetRound();
|
self.brothers[1].resetRound();
|
||||||
}
|
}
|
||||||
|
pub fn update(self: *Game) void {
|
||||||
|
self.gamepads[0].update(w4.GAMEPAD1.*);
|
||||||
|
self.gamepads[1].update(w4.GAMEPAD2.*);
|
||||||
|
self.brothers[0].update(self.gamepads[0]);
|
||||||
|
self.brothers[1].update(self.gamepads[1]);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -11,5 +11,6 @@ export fn start() void {
|
||||||
}
|
}
|
||||||
|
|
||||||
export fn update() void {
|
export fn update() void {
|
||||||
|
Game.update();
|
||||||
Game.draw();
|
Game.draw();
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue