diff --git a/assets/nice_boy.png b/assets/nice_boy.png new file mode 100644 index 0000000..c8c77ab Binary files /dev/null and b/assets/nice_boy.png differ diff --git a/build.zig b/build.zig index 45cafae..ef8dee4 100644 --- a/build.zig +++ b/build.zig @@ -4,6 +4,12 @@ pub fn build(b: *std.Build) void { const target = b.standardTargetOptions(.{}); const optimize = b.standardOptimizeOption(.{}); + const assets = b.addInstallDirectory(.{ + .source_dir = .{ .src_path = .{ .owner = b, .sub_path = "assets" } }, + .install_dir = .bin, + .install_subdir = "assets", + }); + const raylib_dep = b.dependency("raylib_zig", .{ .target = target, .optimize = optimize, @@ -104,6 +110,8 @@ pub fn build(b: *std.Build) void { b.installArtifact(client); b.installArtifact(server); + b.getInstallStep().dependOn(&assets.step); + const run_step = b.step("run", "Run the app"); const run_cmd_client = b.addRunArtifact(client); diff --git a/src/client/main.zig b/src/client/main.zig index 0a28cb4..6d322e8 100644 --- a/src/client/main.zig +++ b/src/client/main.zig @@ -103,12 +103,16 @@ pub fn main() !void { // Draw //---------------------------------------------------------------------------------- + rl.clearBackground(.sky_blue); + rl.beginDrawing(); defer rl.endDrawing(); - rl.clearBackground(.sky_blue); + rl.drawText("Congrats! You created your first window!", rl.getMouseX(), rl.getMouseY(), 20, .white); + rl.drawRectangleLines(0, 0, 100, 100, .red); + + rl.drawFPS(0, 0); - rl.drawText("Congrats! You created your first window!", 190, 200, 20, .light_gray); //---------------------------------------------------------------------------------- } } diff --git a/src/shared/entity.zig b/src/shared/entity.zig index d0b1a47..c79ea8a 100644 --- a/src/shared/entity.zig +++ b/src/shared/entity.zig @@ -1,6 +1,7 @@ const std = @import("std"); const zm = @import("zmath"); const protocol = @import("protocol.zig"); +const rl = @import(); pub const entity_id = u64; pub const INVALID_ENTITY_ID: entity_id = 0; @@ -16,13 +17,29 @@ pub const Player = struct { pos: zm.Vec, hp: i32, - pub fn encode(self: Projectile, w: *std.Io.Writer) !void { + boy: rl.Texture, + + pub fn init() void { + const boy = try rl.loadTexture("assets/nice_boy.png"); + } + + pub fn update(self: *Player) void { + self.pos += zm.f32x4(1, 1, 0, 0); + } + + pub fn draw(self: *Player) void { + const src = rl.Rectangle.init(0, 0, @floatFromInt(boy.width), @floatFromInt(boy.height)); + const dst = rl.Rectangle.init(100 + 100 * zm.cos(@as(f32, @floatCast(rl.getTime()))), 100 + 100 * zm.sin(@as(f32, @floatCast(rl.getTime()))), @floatFromInt(boy.width), @floatFromInt(boy.height)); + boy.drawPro(src, dst, .{ .x = 0, .y = 0 }, 0, .white); + } + + pub fn encode(self: Player, w: *std.Io.Writer) !void { try w.writeInt(u64, self.id, .little); try protocol.writeVec4(w, self.pos); try protocol.writeVec4(w, self.vel); } - pub fn decode(r: *std.Io.Reader) !Projectile { + pub fn decode(r: *std.Io.Reader) !Player { return .{ .id = try r.readInt(u64, .little), .pos = try protocol.readVec4(r), @@ -36,13 +53,13 @@ pub const Monster = struct { pos: zm.Vec, hp: i32, - pub fn encode(self: Projectile, w: *std.Io.Writer) !void { + pub fn encode(self: Monster, w: *std.Io.Writer) !void { try w.writeInt(u64, self.id, .little); try protocol.writeVec4(w, self.pos); try protocol.writeVec4(w, self.vel); } - pub fn decode(r: *std.Io.Reader) !Projectile { + pub fn decode(r: *std.Io.Reader) !Monster { return .{ .id = try r.readInt(u64, .little), .pos = try protocol.readVec4(r),