2022-04-24 09:46:36 +00:00
|
|
|
const w4 = @import("wasm4.zig");
|
2022-06-27 03:39:57 +00:00
|
|
|
const sh0rk = @import("sh0rk.zig");
|
|
|
|
const sprites = @import("sprites.zig");
|
2022-06-27 13:14:17 +00:00
|
|
|
const palette = @import("palette.zig");
|
2022-07-01 21:10:57 +00:00
|
|
|
const tframe = @import("tframe.zig");
|
|
|
|
|
|
|
|
const std = @import("std");
|
|
|
|
const fmt = std.fmt;
|
2022-04-24 09:46:36 +00:00
|
|
|
|
2022-06-27 03:39:57 +00:00
|
|
|
const Direction = sh0rk.Direction;
|
|
|
|
const Point = sh0rk.Point;
|
|
|
|
const Rect = sh0rk.Rect;
|
|
|
|
|
2022-07-01 22:05:55 +00:00
|
|
|
const map = @import("./maps/rpg.zig");
|
|
|
|
|
2022-06-27 03:39:57 +00:00
|
|
|
var frame_count: u32 = 0;
|
|
|
|
var mara_direction: Direction = Direction.Right;
|
|
|
|
var mara_frame: bool = false;
|
2022-07-01 22:05:55 +00:00
|
|
|
var mara_box: Rect = Rect{.base = map.start_point, .width = 16, .height = 16};
|
2022-06-27 03:39:57 +00:00
|
|
|
var mara_speed: i32 = 0;
|
|
|
|
var screen = Rect{.base = Point{.x = 0, .y = 0}, .width = 160, .height = 160};
|
|
|
|
|
2022-07-01 18:23:39 +00:00
|
|
|
var sound_timer: u8 = 0;
|
|
|
|
|
2022-07-01 17:11:52 +00:00
|
|
|
var textBuf: [160]u8 = undefined;
|
2022-07-01 21:10:57 +00:00
|
|
|
var done: bool = true;
|
|
|
|
|
2022-06-27 03:39:57 +00:00
|
|
|
export fn start() void {
|
2022-07-01 15:06:47 +00:00
|
|
|
palette.mist();
|
2022-06-27 03:39:57 +00:00
|
|
|
}
|
2022-04-24 09:46:36 +00:00
|
|
|
|
2022-07-01 17:11:52 +00:00
|
|
|
|
2022-07-01 18:23:39 +00:00
|
|
|
fn bonk() void {
|
|
|
|
if (sound_timer != 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
w4.tone(
|
|
|
|
w4.Tone.Frequency{.start = 220, .end = 40},
|
|
|
|
w4.Tone.Duration{
|
|
|
|
.attack = 0,
|
|
|
|
.decay = 0,
|
|
|
|
.sustain = 6,
|
|
|
|
.release = 6,
|
|
|
|
},
|
|
|
|
w4.Tone.Volume{
|
|
|
|
.sustain = 100,
|
|
|
|
.attack = 100,
|
|
|
|
},
|
|
|
|
w4.Tone.Flags{
|
|
|
|
.channel = .triangle,
|
2022-07-01 21:10:57 +00:00
|
|
|
.pulse_duty = .@"1/4",
|
2022-07-01 18:23:39 +00:00
|
|
|
},
|
|
|
|
);
|
|
|
|
|
|
|
|
sound_timer = 12;
|
|
|
|
}
|
|
|
|
|
2022-07-01 21:10:57 +00:00
|
|
|
const screen_width = 10;
|
|
|
|
const screen_height = 10;
|
|
|
|
|
2022-07-01 17:11:52 +00:00
|
|
|
fn drawMap() !void {
|
|
|
|
w4.m.colors.* = .{
|
2022-07-01 21:10:57 +00:00
|
|
|
._0 = .p3,
|
|
|
|
._1 = .p2,
|
|
|
|
._2 = .p1,
|
|
|
|
._3 = .p0,
|
2022-07-01 17:11:52 +00:00
|
|
|
};
|
|
|
|
|
2022-07-01 21:10:57 +00:00
|
|
|
var col: u32 = 0;
|
|
|
|
while (col < screen_width) {
|
|
|
|
var row: u32 = 0;
|
|
|
|
defer col += 1;
|
|
|
|
|
|
|
|
while (row < screen_height) {
|
|
|
|
defer row += 1;
|
|
|
|
|
|
|
|
var tile = map.data[col * map.width + row];
|
|
|
|
var tileX = tile % map.ts_width;
|
|
|
|
var tileY = tile / map.ts_width;
|
|
|
|
|
2022-07-01 22:05:55 +00:00
|
|
|
// if (!done) {
|
|
|
|
// var buf = fmt.bufPrint(&textBuf, "{},{}: {}: {},{}", .{col, row, tile, tileX, tileY}) catch unreachable;
|
|
|
|
// w4.trace(buf);
|
|
|
|
// }
|
2022-07-01 21:10:57 +00:00
|
|
|
|
|
|
|
w4.blitSub(
|
|
|
|
&sprites.kenney_rpg,
|
|
|
|
row * 16,
|
|
|
|
col * 16,
|
|
|
|
16,
|
|
|
|
16,
|
|
|
|
@intCast(u32, tileX) * 16,
|
|
|
|
@intCast(u32, tileY) * 16,
|
|
|
|
sprites.kenney_rpg_width,
|
|
|
|
w4.BlitFlags{.two_bits = true},
|
|
|
|
);
|
|
|
|
}
|
2022-07-01 17:11:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-01 18:23:39 +00:00
|
|
|
fn move_mara(gamepad: w4.GamePad) void {
|
2022-06-27 12:56:16 +00:00
|
|
|
mara_speed -= 1;
|
|
|
|
if (mara_speed < 0) {
|
|
|
|
mara_speed = 0;
|
|
|
|
}
|
2022-06-27 03:39:57 +00:00
|
|
|
if (gamepad.up) {
|
|
|
|
mara_direction = Direction.Up;
|
2022-07-01 15:06:47 +00:00
|
|
|
mara_speed = 1;
|
2022-06-27 03:39:57 +00:00
|
|
|
} else if (gamepad.down) {
|
|
|
|
mara_direction = Direction.Down;
|
2022-07-01 15:06:47 +00:00
|
|
|
mara_speed = 1;
|
2022-06-27 03:39:57 +00:00
|
|
|
} else if (gamepad.left) {
|
|
|
|
mara_direction = Direction.Left;
|
2022-07-01 15:06:47 +00:00
|
|
|
mara_speed = 1;
|
2022-06-27 03:39:57 +00:00
|
|
|
} else if (gamepad.right) {
|
|
|
|
mara_direction = Direction.Right;
|
2022-07-01 15:06:47 +00:00
|
|
|
mara_speed = 1;
|
2022-06-27 03:39:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (mara_direction) {
|
|
|
|
.Up => {
|
|
|
|
mara_box.base.y -= mara_speed;
|
|
|
|
},
|
|
|
|
.Down => {
|
|
|
|
mara_box.base.y += mara_speed;
|
|
|
|
},
|
|
|
|
.Left => {
|
|
|
|
mara_box.base.x -= mara_speed;
|
|
|
|
},
|
|
|
|
.Right => {
|
|
|
|
mara_box.base.x += mara_speed;
|
|
|
|
},
|
|
|
|
}
|
2022-07-01 18:23:39 +00:00
|
|
|
}
|
|
|
|
|
2022-07-01 21:10:57 +00:00
|
|
|
fn title() void {
|
|
|
|
w4.m.colors._0 = .p3;
|
|
|
|
w4.m.colors._1 = .p0;
|
|
|
|
w4.text("Mara 2:\nTamamo's Fury", 10, 10);
|
|
|
|
}
|
|
|
|
|
2022-07-01 18:23:39 +00:00
|
|
|
export fn update() void {
|
2022-07-01 21:10:57 +00:00
|
|
|
defer done = true;
|
2022-07-01 18:23:39 +00:00
|
|
|
if (sound_timer != 0) {
|
|
|
|
sound_timer -= 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
drawMap() catch unreachable;
|
|
|
|
|
|
|
|
const gamepad = w4.m.gamepads[0];
|
|
|
|
const old_speed = mara_speed;
|
2022-07-01 21:10:57 +00:00
|
|
|
|
2022-07-01 22:05:55 +00:00
|
|
|
if (!tframe.enabled) {
|
|
|
|
move_mara(gamepad);
|
|
|
|
} else {
|
|
|
|
tframe.update(gamepad);
|
2022-07-01 21:10:57 +00:00
|
|
|
}
|
|
|
|
|
2022-07-01 17:37:13 +00:00
|
|
|
for (map.coll) |box| {
|
|
|
|
if (mara_box.collides(box)) {
|
2022-07-01 18:23:39 +00:00
|
|
|
switch (mara_direction) {
|
|
|
|
.Up => {
|
|
|
|
mara_box.base.y += mara_speed;
|
|
|
|
},
|
|
|
|
.Down => {
|
|
|
|
mara_box.base.y -= mara_speed;
|
|
|
|
},
|
|
|
|
.Left => {
|
|
|
|
mara_box.base.x += mara_speed;
|
|
|
|
},
|
|
|
|
.Right => {
|
|
|
|
mara_box.base.x -= mara_speed;
|
|
|
|
},
|
|
|
|
}
|
2022-07-01 17:37:13 +00:00
|
|
|
mara_speed = 0;
|
2022-07-01 18:23:39 +00:00
|
|
|
bonk();
|
2022-07-01 17:37:13 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-07-01 22:05:55 +00:00
|
|
|
for (map.triggers) |trig| {
|
|
|
|
if (mara_box.collides(trig.aura) and mara_direction == trig.direction and gamepad.b) {
|
|
|
|
tframe.set_text(trig.dialogue);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-27 03:39:57 +00:00
|
|
|
if (mara_box.base.x < 0) {
|
|
|
|
mara_box.base.x = 0;
|
2022-07-01 21:10:57 +00:00
|
|
|
bonk();
|
2022-06-27 03:39:57 +00:00
|
|
|
} else if (mara_box.base.x > 160 - mara_box.width) {
|
|
|
|
mara_box.base.x = 160 - mara_box.width;
|
2022-07-01 21:10:57 +00:00
|
|
|
bonk();
|
2022-06-27 03:39:57 +00:00
|
|
|
}
|
|
|
|
if (mara_box.base.y < 0) {
|
|
|
|
mara_box.base.y = 0;
|
2022-07-01 21:10:57 +00:00
|
|
|
bonk();
|
2022-06-27 03:39:57 +00:00
|
|
|
} else if (mara_box.base.y > 160 - mara_box.height) {
|
|
|
|
mara_box.base.y = 160 - mara_box.height;
|
2022-07-01 21:10:57 +00:00
|
|
|
bonk();
|
2022-04-24 09:46:36 +00:00
|
|
|
}
|
|
|
|
|
2022-07-01 15:06:47 +00:00
|
|
|
var flags: w4.BlitFlags = w4.BlitFlags {
|
|
|
|
.two_bits = true,
|
|
|
|
};
|
|
|
|
|
2022-07-01 17:11:52 +00:00
|
|
|
// w4.m.colors._0 = .p0;
|
|
|
|
// w4.m.colors._1 = .p1;
|
|
|
|
// w4.m.colors._2 = .p2;
|
|
|
|
// w4.m.colors._3 = .p3;
|
2022-07-01 15:06:47 +00:00
|
|
|
|
2022-07-01 17:11:52 +00:00
|
|
|
// w4.blit(&sprites.tamamotitle, 60, 60, sprites.tamamotitle_width, sprites.tamamotitle_height, flags);
|
2022-07-01 15:06:47 +00:00
|
|
|
|
2022-07-01 17:11:52 +00:00
|
|
|
// w4.m.colors._0 = .p0;
|
|
|
|
// w4.m.colors._1 = .p1;
|
|
|
|
// w4.m.colors._2 = .p3;
|
|
|
|
// w4.m.colors._3 = .transparent;
|
2022-07-01 15:06:47 +00:00
|
|
|
|
2022-07-01 21:10:57 +00:00
|
|
|
// w4.blit(&sprites.glaceon, 0, 0, sprites.glaceon_width, sprites.glaceon_height, flags);
|
2022-07-01 15:06:47 +00:00
|
|
|
|
2022-07-01 17:11:52 +00:00
|
|
|
w4.m.colors.* = .{
|
|
|
|
._0 = .transparent,
|
|
|
|
._1 = .p0,
|
|
|
|
._2 = .p1,
|
|
|
|
._3 = .p3,
|
|
|
|
};
|
2022-06-27 03:39:57 +00:00
|
|
|
|
|
|
|
if (mara_direction == Direction.Left) {
|
|
|
|
flags.flip_x = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (frame_count % 15 == 0 and mara_speed > 0) {
|
|
|
|
mara_frame = !mara_frame;
|
|
|
|
}
|
2022-06-27 12:56:16 +00:00
|
|
|
|
|
|
|
if (old_speed != mara_speed) {
|
|
|
|
mara_frame = !mara_frame;
|
|
|
|
}
|
|
|
|
|
2022-06-27 03:39:57 +00:00
|
|
|
var frame: u32 = switch (mara_direction) {
|
|
|
|
.Left => 4,
|
|
|
|
.Right => 4,
|
|
|
|
.Up => 2,
|
|
|
|
.Down => 0,
|
|
|
|
};
|
|
|
|
var step: u32 = if (mara_frame) 1 else 0;
|
|
|
|
|
|
|
|
w4.blitSub(&sprites.Mara, @intCast(u32, mara_box.base.x), @intCast(u32, mara_box.base.y), 16, 16, 16 * (frame + step), 0, 96, flags);
|
|
|
|
|
|
|
|
frame_count += 1;
|
2022-04-24 09:46:36 +00:00
|
|
|
}
|
2022-06-27 03:39:57 +00:00
|
|
|
|