From 39175885d001b70df5863a141135b069d9871476 Mon Sep 17 00:00:00 2001 From: kdx Date: Thu, 1 Jun 2023 11:36:55 +0200 Subject: use it --- src/main.zig | 19 +++++++++++-------- src/zxc.zig | 21 +++++++++++++++++---- 2 files changed, 28 insertions(+), 12 deletions(-) diff --git a/src/main.zig b/src/main.zig index 0bfbe60..c1c04db 100644 --- a/src/main.zig +++ b/src/main.zig @@ -1,6 +1,9 @@ const std = @import("std"); const zxc = @import("zxc.zig"); +const purple = zxc.Color{ .r = 1, .g = 0, .b = 1, .a = 1 }; +const black = zxc.Color{ .r = 0, .g = 0, .b = 0, .a = 1 }; + pub fn main() !void { var z = try zxc.init(.{ .width = 400, @@ -9,21 +12,21 @@ pub fn main() !void { }); defer z.deinit(); - var score: usize = 0; + var x: i32 = 16; while (!z.shouldQuit()) { z.cycleEvents(); - if (z.getKey(.space) == .pressed) { - score += 1; - std.log.info("score: {}", .{score}); - } + if (z.getKey(.left).down()) + x -= 1; + if (z.getKey(.right).down()) + x += 1; try z.drawBegin(); - try z.drawSetColor(.{ .r = 1, .g = 0, .b = 1 }); + try z.drawSetColor(purple); try z.drawClear(); - try z.drawSetColor(.{ .r = 0, .g = 0, .b = 0 }); + try z.drawSetColor(black); try z.drawRectangle(.{ - .x = 12, + .x = x, .y = 25, .w = 32, .h = 16, diff --git a/src/zxc.zig b/src/zxc.zig index d826585..cee099f 100644 --- a/src/zxc.zig +++ b/src/zxc.zig @@ -4,7 +4,7 @@ const Self = @This(); pub const Scancode = sdl.Scancode; -const Config = struct { +pub const Config = struct { const RenderMode = enum { pixel, pixel_perfect, @@ -20,21 +20,34 @@ const Config = struct { title: [:0]const u8 = "ZXC", }; -const Keystate = enum { +pub const Keystate = enum { up, released, down, pressed, + + pub fn up(self: Keystate) bool { + return self == .up or self == .released; + } + pub fn released(self: Keystate) bool { + return self == .released; + } + pub fn down(self: Keystate) bool { + return self == .down or self == .pressed; + } + pub fn pressed(self: Keystate) bool { + return self == .pressed; + } }; -const Color = struct { +pub const Color = struct { r: ?f32 = null, g: ?f32 = null, b: ?f32 = null, a: ?f32 = null, }; -const Rectangle = struct { +pub const Rectangle = struct { x: i32, y: i32, w: u16, -- cgit v1.2.3