diff --git a/maps/RPGmap.json b/maps/RPGmap.json index 7fbaf27..f74b858 100644 --- a/maps/RPGmap.json +++ b/maps/RPGmap.json @@ -222,7 +222,7 @@ { "name":"dialogue", "type":"string", - "value":"18 chars per line\\nallowed. Or else!" + "value":"Kanar News\\nThe mayor is\\nacting weird today." }, { "name":"direction", diff --git a/maps/RPGmap.tmx b/maps/RPGmap.tmx index cb72c01..bf30e93 100644 --- a/maps/RPGmap.tmx +++ b/maps/RPGmap.tmx @@ -69,7 +69,7 @@ - + diff --git a/src/main.zig b/src/main.zig index 898f413..be21c66 100644 --- a/src/main.zig +++ b/src/main.zig @@ -3,6 +3,7 @@ const sh0rk = @import("./sh0rk.zig"); const sprites = @import("./sprites.zig"); const palette = @import("./palette.zig"); const tframe = @import("./tframe.zig"); +const overhead = @import("./overhead.zig"); const std = @import("std"); const fmt = std.fmt; @@ -29,9 +30,7 @@ var sound_timer: u8 = 0; var textBuf: [160]u8 = undefined; var done: bool = false; -var camera = Point{ .x = 32, .y = 0 }; - -var state: sh0rk.State = .Gameplay; +var camera = Point{ .x = 0, .y = 0 }; fn world_to_screen(p: Point) Point { return p.sub(camera); @@ -42,7 +41,11 @@ fn screen_to_world(p: Point) Point { } export fn start() void { - palette.mist(); + if (sh0rk.state == .Gameplay) { + palette.mist(); + } else { + palette.tamtam(); + } } fn bonk() void { @@ -192,106 +195,45 @@ fn move_mara(gamepad: w4.GamePad) void { switch (mara_direction) { .Up => { - camera.y -= mara_speed; - mara_box.base.y -= mara_speed; + if (camera.y == 0 or camera.y == (map.width * tile_size) - (20 * tile_size)) { + mara_box.base.y -= mara_speed; + } else { + camera.y -= mara_speed; + } }, .Down => { - camera.y += mara_speed; - mara_box.base.y += mara_speed; + if (camera.y == 0 or camera.y == (map.width * tile_size) - (20 * tile_size)) { + mara_box.base.y += mara_speed; + } else { + camera.y += mara_speed; + } }, .Left => { - camera.x -= mara_speed; - mara_box.base.x -= mara_speed; + if (camera.x == 0 or camera.x == (map.width * tile_size) - (20 * tile_size)) { + mara_box.base.x -= mara_speed; + } else { + camera.x -= mara_speed; + } }, .Right => { - camera.x += mara_speed; - mara_box.base.x += mara_speed; + if (camera.x == 0 or camera.x == (map.width * tile_size) - (20 * tile_size)) { + mara_box.base.x += mara_speed; + } else { + camera.x += mara_speed; + } }, } } -fn title() !void { - w4.m.colors._0 = .p3; - w4.m.colors._1 = .p0; - w4.text("Mara 2:\nTamamo's Fury", 28, 8); - w4.text("Press z or x", 32, 136); - w4.text("From Within 2022", 16, 152); - - w4.m.colors._0 = .p0; - w4.m.colors._1 = .p1; - w4.m.colors._2 = .p2; - w4.m.colors._3 = .p3; - - w4.blit(&sprites.tamamotitle, 48, 60, sprites.tamamotitle_width, sprites.tamamotitle_height, w4.BlitFlags{ .two_bits = true }); - - const gamepad = w4.m.gamepads[0]; - if (gamepad.a or gamepad.b) { - state = .StoryDump; - } -} - -const story = "After defeating\nthe evil mage,\nMalto was at\npeace.\n\nOne day Mara was\nwalking along the\nbeach when she saw\nthe killing stone\nwas split in two.\nTamamo-no-Mae was\nfree to wreak havoc\nacross the land.\n\nHelp us again Mara!\nSave Kanar from\nTamamo-no-Mae!\n\nPress x."; -var story_idx: u16 = 0; -var story_counter: u8 = 4; - -fn storydump() !void { - w4.m.colors._0 = .p3; - w4.m.colors._1 = .p0; - - w4.text(story[0..story_idx], 4, 4); - - const gamepad = w4.m.gamepads[0]; - if (gamepad.b) { - state = .Gameplay; - palette.mist(); - } - - if (story_idx < story.len) { - story_counter -= 1; - - if (gamepad.a) { - story_counter = 0; - } - - if (story_counter == 0) { - story_idx += 1; - story_counter = 4; - - w4.tone( - w4.Tone.Frequency{ .start = 280, .end = 310 }, - w4.Tone.Duration{ - .attack = 0, - .decay = 0, - .sustain = 2, - .release = 0, - }, - w4.Tone.Volume{ - .sustain = 100, - .attack = 100, - }, - w4.Tone.Flags{ - .channel = .triangle, - .pulse_duty = .@"1/4", - }, - ); - } - } else { - if (gamepad.a) { - state = .Gameplay; - palette.mist(); - } - } -} - export fn update() void { defer frame_count += 1; if (frame_count % 60 == 0) { done = false; } - switch (state) { - .Title => title() catch unreachable, - .StoryDump => storydump() catch unreachable, + switch (sh0rk.state) { + .Title => overhead.title() catch unreachable, + .StoryDump => overhead.storydump() catch unreachable, .Gameplay => gameplay() catch unreachable, } } @@ -393,18 +335,6 @@ fn draw_mara() void { }; var step: u32 = if (mara_frame) 1 else 0; - w4.blitSub( - &sprites.Mara, - mara_box.base.x, - mara_box.base.y, - 16, - 16, - 16 * (frame + step), - 0, - 96, - flags, - ); - var scr = world_to_screen(mara_box.base); w4.blitSub( diff --git a/src/maps/overworld.zig b/src/maps/overworld.zig index db094ff..45c31d0 100644 --- a/src/maps/overworld.zig +++ b/src/maps/overworld.zig @@ -192,7 +192,7 @@ pub const coll = [_]Rect{ }; pub const triggers = [_]Trigger{ - Trigger{ .aura = Rect{ .base = Point{ .x = 16, .y = 96 }, .width = 16, .height = 20 }, .direction = Direction.Up, .dialogue = "18 chars per line\nallowed. Or else!" }, // sign + Trigger{ .aura = Rect{ .base = Point{ .x = 16, .y = 96 }, .width = 16, .height = 20 }, .direction = Direction.Up, .dialogue = "Kanar News\nThe mayor is\nacting weird today." }, // sign Trigger{ .aura = Rect{ .base = Point{ .x = 83, .y = 103 }, .width = 7, .height = 16 }, .direction = Direction.Up, .dialogue = "Ded." }, // gravestone 1 Trigger{ .aura = Rect{ .base = Point{ .x = 96, .y = 103 }, .width = 7, .height = 16 }, .direction = Direction.Up, .dialogue = "Moar ded." }, // gravestone 2 }; diff --git a/src/overhead.zig b/src/overhead.zig new file mode 100644 index 0000000..2885f29 --- /dev/null +++ b/src/overhead.zig @@ -0,0 +1,77 @@ +const palette = @import("./palette.zig"); +const sh0rk = @import("./sh0rk.zig"); +const sprites = @import("./sprites.zig"); +const w4 = @import("./wasm4.zig"); + +pub fn title() !void { + w4.m.colors._0 = .p3; + w4.m.colors._1 = .p0; + w4.text("Mara 2:\nTamamo's Fury", 28, 8); + w4.text("Press z or x", 32, 136); + w4.text("From Within 2022", 16, 152); + + w4.m.colors._0 = .p0; + w4.m.colors._1 = .p1; + w4.m.colors._2 = .p2; + w4.m.colors._3 = .p3; + + w4.blit(&sprites.tamamotitle, 48, 60, sprites.tamamotitle_width, sprites.tamamotitle_height, w4.BlitFlags{ .two_bits = true }); + + const gamepad = w4.m.gamepads[0]; + if (gamepad.a or gamepad.b) { + sh0rk.state = .StoryDump; + } +} + +const story = "After defeating\nthe evil mage,\nMalto was at\npeace.\n\nOne day Mara was\nwalking along the\nbeach when she saw\nthe killing stone\nwas split in two.\nTamamo-no-Mae was\nfree to wreak havoc\nacross the land.\n\nHelp us again Mara!\nSave Malto from\nTamamo-no-Mae!\n\nPress x."; +var story_idx: u16 = 0; +var story_counter: u8 = 4; + +pub fn storydump() !void { + w4.m.colors._0 = .p3; + w4.m.colors._1 = .p0; + + w4.text(story[0..story_idx], 4, 4); + + const gamepad = w4.m.gamepads[0]; + if (gamepad.b) { + sh0rk.state = .Gameplay; + palette.mist(); + } + + if (story_idx < story.len) { + story_counter -= 1; + + if (gamepad.a) { + story_counter = 0; + } + + if (story_counter == 0) { + story_idx += 1; + story_counter = 4; + + w4.tone( + w4.Tone.Frequency{ .start = 280, .end = 310 }, + w4.Tone.Duration{ + .attack = 0, + .decay = 0, + .sustain = 2, + .release = 0, + }, + w4.Tone.Volume{ + .sustain = 100, + .attack = 100, + }, + w4.Tone.Flags{ + .channel = .triangle, + .pulse_duty = .@"1/4", + }, + ); + } + } else { + if (gamepad.a) { + sh0rk.state = .Gameplay; + palette.mist(); + } + } +} \ No newline at end of file diff --git a/src/sh0rk.zig b/src/sh0rk.zig index f245343..155dbc7 100644 --- a/src/sh0rk.zig +++ b/src/sh0rk.zig @@ -83,4 +83,6 @@ pub const State = enum { Title, StoryDump, Gameplay, -}; \ No newline at end of file +}; + +pub var state: State = .Gameplay; \ No newline at end of file