feat: highlight selected card, change highlight card
parent
45bc09b612
commit
d63a6d06fb
50
src/main.zig
50
src/main.zig
|
@ -226,6 +226,10 @@ pub fn main() !void {
|
|||
gl.makeBindingCurrent(&gl_binding);
|
||||
|
||||
// Set up input callbacks
|
||||
var input_state: InputState = undefined;
|
||||
_ = seizer.backend.glfw.c.glfwSetWindowUserPointer(window, &input_state);
|
||||
|
||||
_ = seizer.backend.glfw.c.glfwSetKeyCallback(window, &glfw_key_callback);
|
||||
_ = seizer.backend.glfw.c.glfwSetFramebufferSizeCallback(window, &glfw_framebuffer_size_callback);
|
||||
|
||||
var card_tilemap_small: ?DeckSprites = null;
|
||||
|
@ -244,9 +248,21 @@ pub fn main() !void {
|
|||
var game_state = try GameState.init(gpa.allocator(), std.crypto.random.int(u64), 1);
|
||||
defer game_state.deinit();
|
||||
|
||||
var selection: usize = 0;
|
||||
|
||||
while (seizer.backend.glfw.c.glfwWindowShouldClose(window) != seizer.backend.glfw.c.GLFW_TRUE) {
|
||||
input_state = .{
|
||||
.left = false,
|
||||
.right = false,
|
||||
.up = false,
|
||||
.down = false,
|
||||
};
|
||||
seizer.backend.glfw.c.glfwPollEvents();
|
||||
|
||||
if (input_state.right) {
|
||||
selection = (selection + 1) % game_state.hands[0].items.len;
|
||||
}
|
||||
|
||||
gl.clearColor(0.7, 0.5, 0.5, 1.0);
|
||||
gl.clear(gl.COLOR_BUFFER_BIT);
|
||||
|
||||
|
@ -317,10 +333,17 @@ pub fn main() !void {
|
|||
}
|
||||
|
||||
for (game_state.hands[0].items, 0..) |card, i| {
|
||||
deck_sprites.tilesheet.renderTile(&canvas, deck_sprites.getTileForCard(card), .{
|
||||
const pos = [2]f32{
|
||||
hand_pos[0] + @as(f32, @floatFromInt(i)) * @as(f32, @floatFromInt(deck_sprites.tilesheet.tile_size[0])),
|
||||
hand_pos[1],
|
||||
}, .{});
|
||||
};
|
||||
deck_sprites.tilesheet.renderTile(&canvas, deck_sprites.getTileForCard(card), pos, .{});
|
||||
if (i == selection) {
|
||||
canvas.rect(pos, [2]f32{
|
||||
@floatFromInt(deck_sprites.tilesheet.tile_size[0]),
|
||||
@floatFromInt(deck_sprites.tilesheet.tile_size[1]),
|
||||
}, .{ .color = .{ 0xAA, 0xFF, 0xAA, 0x60 } });
|
||||
}
|
||||
}
|
||||
|
||||
canvas.end();
|
||||
|
@ -514,6 +537,29 @@ fn glfw_framebuffer_size_callback(window: ?*seizer.backend.glfw.c.GLFWwindow, wi
|
|||
);
|
||||
}
|
||||
|
||||
const InputState = struct {
|
||||
left: bool,
|
||||
right: bool,
|
||||
up: bool,
|
||||
down: bool,
|
||||
};
|
||||
|
||||
fn glfw_key_callback(window: ?*seizer.backend.glfw.c.GLFWwindow, key: c_int, scancode: c_int, action: c_int, mods: c_int) callconv(.C) void {
|
||||
const input_state = @as(*InputState, @alignCast(@ptrCast(seizer.backend.glfw.c.glfwGetWindowUserPointer(window))));
|
||||
|
||||
_ = scancode;
|
||||
_ = mods;
|
||||
if (action == seizer.backend.glfw.c.GLFW_PRESS) {
|
||||
switch (key) {
|
||||
seizer.backend.glfw.c.GLFW_KEY_LEFT => input_state.left = true,
|
||||
seizer.backend.glfw.c.GLFW_KEY_RIGHT => input_state.right = true,
|
||||
seizer.backend.glfw.c.GLFW_KEY_UP => input_state.up = true,
|
||||
seizer.backend.glfw.c.GLFW_KEY_DOWN => input_state.down = true,
|
||||
else => {},
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
const seizer = @import("seizer");
|
||||
const gl = seizer.gl;
|
||||
const std = @import("std");
|
||||
|
|
Loading…
Reference in New Issue