201 lines
3.5 KiB
Zig
201 lines
3.5 KiB
Zig
const sh0rk = @import("./sh0rk.zig");
|
|
const w4 = @import("./wasm4.zig");
|
|
const sprites = @import("./sprites.zig");
|
|
|
|
pub var enabled: bool = false;
|
|
var curr_text: []const u8 = undefined;
|
|
var text_index: usize = 0;
|
|
var text_counter: u4 = 0;
|
|
|
|
fn frame() void {
|
|
w4.m.colors.* = .{
|
|
._0 = .p0,
|
|
._1 = .p1,
|
|
._2 = .p2,
|
|
._3 = .p3,
|
|
};
|
|
|
|
w4.blitSub(
|
|
&sprites.frame,
|
|
0,
|
|
128,
|
|
8,
|
|
8,
|
|
0,
|
|
0,
|
|
sprites.frame_width,
|
|
w4.BlitFlags{.two_bits = true},
|
|
);
|
|
|
|
w4.blitSub(
|
|
&sprites.frame,
|
|
152,
|
|
128,
|
|
8,
|
|
8,
|
|
16,
|
|
0,
|
|
sprites.frame_width,
|
|
w4.BlitFlags{.two_bits = true},
|
|
);
|
|
|
|
w4.blitSub(
|
|
&sprites.frame,
|
|
0,
|
|
136,
|
|
8,
|
|
8,
|
|
0,
|
|
8,
|
|
sprites.frame_width,
|
|
w4.BlitFlags{.two_bits = true},
|
|
);
|
|
|
|
w4.blitSub(
|
|
&sprites.frame,
|
|
152,
|
|
144,
|
|
8,
|
|
8,
|
|
16,
|
|
8,
|
|
sprites.frame_width,
|
|
w4.BlitFlags{.two_bits = true},
|
|
);
|
|
|
|
w4.blitSub(
|
|
&sprites.frame,
|
|
152,
|
|
136,
|
|
8,
|
|
8,
|
|
16,
|
|
8,
|
|
sprites.frame_width,
|
|
w4.BlitFlags{.two_bits = true},
|
|
);
|
|
|
|
w4.blitSub(
|
|
&sprites.frame,
|
|
0,
|
|
144,
|
|
8,
|
|
8,
|
|
0,
|
|
8,
|
|
sprites.frame_width,
|
|
w4.BlitFlags{.two_bits = true},
|
|
);
|
|
|
|
w4.blitSub(
|
|
&sprites.frame,
|
|
0,
|
|
152,
|
|
8,
|
|
8,
|
|
0,
|
|
16,
|
|
sprites.frame_width,
|
|
w4.BlitFlags{.two_bits = true},
|
|
);
|
|
|
|
w4.blitSub(
|
|
&sprites.frame,
|
|
152,
|
|
152,
|
|
8,
|
|
8,
|
|
16,
|
|
16,
|
|
sprites.frame_width,
|
|
w4.BlitFlags{.two_bits = true},
|
|
);
|
|
|
|
var i: u8 = 0;
|
|
while (i < 18) {
|
|
defer i += 1;
|
|
|
|
w4.blitSub(
|
|
&sprites.frame,
|
|
(i * 8) + 8,
|
|
128,
|
|
8,
|
|
8,
|
|
8,
|
|
0,
|
|
sprites.frame_width,
|
|
w4.BlitFlags{.two_bits = true},
|
|
);
|
|
|
|
w4.blitSub(
|
|
&sprites.frame,
|
|
(i * 8) + 8,
|
|
136,
|
|
8,
|
|
8,
|
|
8,
|
|
8,
|
|
sprites.frame_width,
|
|
w4.BlitFlags{.two_bits = true},
|
|
);
|
|
|
|
w4.blitSub(
|
|
&sprites.frame,
|
|
(i * 8) + 8,
|
|
144,
|
|
8,
|
|
8,
|
|
8,
|
|
8,
|
|
sprites.frame_width,
|
|
w4.BlitFlags{.two_bits = true},
|
|
);
|
|
|
|
w4.blitSub(
|
|
&sprites.frame,
|
|
(i * 8) + 8,
|
|
152,
|
|
8,
|
|
8,
|
|
8,
|
|
16,
|
|
sprites.frame_width,
|
|
w4.BlitFlags{.two_bits = true},
|
|
);
|
|
}
|
|
}
|
|
|
|
pub fn set_text(text: []const u8) void {
|
|
enabled = true;
|
|
curr_text = text;
|
|
text_index = 0;
|
|
text_counter = 15;
|
|
}
|
|
|
|
pub fn update(gamepad: w4.GamePad) void {
|
|
frame();
|
|
|
|
w4.m.colors._0 = .p3;
|
|
w4.m.colors._1 = .p0;
|
|
w4.text(curr_text[0..text_index], 12, 140);
|
|
|
|
if (gamepad.a) {
|
|
w4.trace("dismissing");
|
|
enabled = false;
|
|
text_index = 0;
|
|
curr_text = "";
|
|
}
|
|
|
|
if (text_index < curr_text.len) {
|
|
text_counter -= 1;
|
|
|
|
if (gamepad.b) {
|
|
text_counter = 0;
|
|
}
|
|
|
|
if (text_counter == 0) {
|
|
text_index += 1;
|
|
text_counter = 4;
|
|
}
|
|
}
|
|
} |