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-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;
|
|
|
|
|
|
|
|
var frame_count: u32 = 0;
|
|
|
|
var mara_direction: Direction = Direction.Right;
|
|
|
|
var mara_frame: bool = false;
|
|
|
|
var mara_box: Rect = Rect{.base = Point{.x = 60, .y = 60}, .width = 16, .height = 16};
|
|
|
|
var mara_speed: i32 = 0;
|
|
|
|
var screen = Rect{.base = Point{.x = 0, .y = 0}, .width = 160, .height = 160};
|
|
|
|
|
|
|
|
export fn start() void {
|
|
|
|
w4.m.palette.* = .{
|
|
|
|
w4.Color{.blue = 0xAF, .green = 0xB0, .red = 0xD9},
|
|
|
|
//0xD9B0AF,
|
|
|
|
w4.Color{.blue = 0x83, .green = 0x63, .red = 0xAA},
|
|
|
|
//0xAA6383,
|
|
|
|
w4.Color{.blue = 0x83, .green = 0x3C, .red = 0xAA},
|
|
|
|
//0x6A3C4F,
|
|
|
|
w4.Color{.blue = 0x2D, .green = 0x23, .red = 0x36},
|
|
|
|
//0x36232D,
|
|
|
|
};
|
|
|
|
}
|
2022-04-24 09:46:36 +00:00
|
|
|
|
|
|
|
export fn update() void {
|
2022-06-27 03:39:57 +00:00
|
|
|
w4.m.colors._0 = .p3;
|
|
|
|
w4.m.colors._1 = .p0;
|
|
|
|
w4.text("Mara 2:\nTamamo's Fury", 10, 10);
|
|
|
|
|
|
|
|
const gamepad = w4.m.gamepads[0];
|
|
|
|
if (gamepad.a) {
|
|
|
|
w4.m.colors._0 = .p2;
|
|
|
|
}
|
2022-04-24 09:46:36 +00:00
|
|
|
|
2022-06-27 03:39:57 +00:00
|
|
|
mara_speed = 0;
|
|
|
|
if (gamepad.up) {
|
|
|
|
mara_direction = Direction.Up;
|
|
|
|
mara_speed = 2;
|
|
|
|
} else if (gamepad.down) {
|
|
|
|
mara_direction = Direction.Down;
|
|
|
|
mara_speed = 2;
|
|
|
|
} else if (gamepad.left) {
|
|
|
|
mara_direction = Direction.Left;
|
|
|
|
mara_speed = 2;
|
|
|
|
} else if (gamepad.right) {
|
|
|
|
mara_direction = Direction.Right;
|
|
|
|
mara_speed = 2;
|
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mara_box.base.x < 0) {
|
|
|
|
mara_box.base.x = 0;
|
|
|
|
} else if (mara_box.base.x > 160 - mara_box.width) {
|
|
|
|
mara_box.base.x = 160 - mara_box.width;
|
|
|
|
}
|
|
|
|
if (mara_box.base.y < 0) {
|
|
|
|
mara_box.base.y = 0;
|
|
|
|
} else if (mara_box.base.y > 160 - mara_box.height) {
|
|
|
|
mara_box.base.y = 160 - mara_box.height;
|
2022-04-24 09:46:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
w4.text("Press X to blink", 16, 90);
|
2022-06-27 03:39:57 +00:00
|
|
|
|
|
|
|
w4.m.colors._0 = .transparent;
|
|
|
|
w4.m.colors._1 = .p0;
|
|
|
|
w4.m.colors._2 = .p1;
|
|
|
|
w4.m.colors._3 = .p3;
|
|
|
|
|
|
|
|
var flags: w4.BlitFlags = w4.BlitFlags {
|
|
|
|
.two_bits = true,
|
|
|
|
};
|
|
|
|
|
|
|
|
if (mara_direction == Direction.Left) {
|
|
|
|
flags.flip_x = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (frame_count % 15 == 0 and mara_speed > 0) {
|
|
|
|
mara_frame = !mara_frame;
|
|
|
|
}
|
|
|
|
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
|
|
|
|