From 8f76ba782669bc986a5e450e5a50ac84232c1323 Mon Sep 17 00:00:00 2001 From: Julien Dessaux Date: Wed, 21 Sep 2022 23:19:45 +0200 Subject: Began rewriting the game as a wasm4 cartridge --- src/ball.zig | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 src/ball.zig (limited to 'src/ball.zig') diff --git a/src/ball.zig b/src/ball.zig new file mode 100644 index 0000000..11737bb --- /dev/null +++ b/src/ball.zig @@ -0,0 +1,28 @@ +const std = @import("std"); +const utils = @import("utils.zig"); +const w4 = @import("wasm4.zig"); + +pub const Ball = struct { + x: f64, + y: f64, + dx: f64, + dy: f64, + pub fn draw(self: Ball) void { + var y = @floatToInt(u8, std.math.round(self.y)); + var x = @floatToInt(u8, std.math.round(self.x)); + w4.DRAW_COLORS.* = 0x4321; + w4.blit(&ball, x, y, ball_width, ball_height, ball_flags); + } + pub fn resetRound(self: *Ball, side: utils.side) void { + self.x = @intToFloat(f64, utils.startingX[@enumToInt(side)] + 4); + self.y = 160 - 32 - 8; + self.dx = 0; + self.dy = 0; + } +}; + +//----- Sprite ---------------------------------------------------------------- +const ball_width = 8; +const ball_height = 8; +const ball_flags = 1; // BLIT_2BPP +const ball = [16]u8{ 0x1a, 0xa4, 0x6f, 0xf9, 0xbf, 0xae, 0xbf, 0xae, 0xbf, 0xfe, 0xbf, 0xfe, 0x6f, 0xf9, 0x1a, 0xa4 }; -- cgit v1.2.3