try to make movement work, fail miserably

Signed-off-by: Christine Dodrill <me@christine.website>
This commit is contained in:
Cadey Ratio 2022-07-02 14:18:06 -04:00
parent 6641e29997
commit d8ec754e37
6 changed files with 113 additions and 104 deletions

View File

@ -222,7 +222,7 @@
{ {
"name":"dialogue", "name":"dialogue",
"type":"string", "type":"string",
"value":"18 chars per line\\nallowed. Or else!" "value":"Kanar News\\nThe mayor is\\nacting weird today."
}, },
{ {
"name":"direction", "name":"direction",

View File

@ -69,7 +69,7 @@
<objectgroup id="3" name="act"> <objectgroup id="3" name="act">
<object id="30" name="sign" x="16" y="96" width="16" height="20"> <object id="30" name="sign" x="16" y="96" width="16" height="20">
<properties> <properties>
<property name="dialogue" value="18 chars per line\nallowed. Or else!"/> <property name="dialogue" value="Kanar News\nThe mayor is\nacting weird today."/>
<property name="direction" value="Up"/> <property name="direction" value="Up"/>
</properties> </properties>
</object> </object>

View File

@ -3,6 +3,7 @@ const sh0rk = @import("./sh0rk.zig");
const sprites = @import("./sprites.zig"); const sprites = @import("./sprites.zig");
const palette = @import("./palette.zig"); const palette = @import("./palette.zig");
const tframe = @import("./tframe.zig"); const tframe = @import("./tframe.zig");
const overhead = @import("./overhead.zig");
const std = @import("std"); const std = @import("std");
const fmt = std.fmt; const fmt = std.fmt;
@ -29,9 +30,7 @@ var sound_timer: u8 = 0;
var textBuf: [160]u8 = undefined; var textBuf: [160]u8 = undefined;
var done: bool = false; var done: bool = false;
var camera = Point{ .x = 32, .y = 0 }; var camera = Point{ .x = 0, .y = 0 };
var state: sh0rk.State = .Gameplay;
fn world_to_screen(p: Point) Point { fn world_to_screen(p: Point) Point {
return p.sub(camera); return p.sub(camera);
@ -42,7 +41,11 @@ fn screen_to_world(p: Point) Point {
} }
export fn start() void { export fn start() void {
palette.mist(); if (sh0rk.state == .Gameplay) {
palette.mist();
} else {
palette.tamtam();
}
} }
fn bonk() void { fn bonk() void {
@ -192,106 +195,45 @@ fn move_mara(gamepad: w4.GamePad) void {
switch (mara_direction) { switch (mara_direction) {
.Up => { .Up => {
camera.y -= mara_speed; if (camera.y == 0 or camera.y == (map.width * tile_size) - (20 * tile_size)) {
mara_box.base.y -= mara_speed; mara_box.base.y -= mara_speed;
} else {
camera.y -= mara_speed;
}
}, },
.Down => { .Down => {
camera.y += mara_speed; if (camera.y == 0 or camera.y == (map.width * tile_size) - (20 * tile_size)) {
mara_box.base.y += mara_speed; mara_box.base.y += mara_speed;
} else {
camera.y += mara_speed;
}
}, },
.Left => { .Left => {
camera.x -= mara_speed; if (camera.x == 0 or camera.x == (map.width * tile_size) - (20 * tile_size)) {
mara_box.base.x -= mara_speed; mara_box.base.x -= mara_speed;
} else {
camera.x -= mara_speed;
}
}, },
.Right => { .Right => {
camera.x += mara_speed; if (camera.x == 0 or camera.x == (map.width * tile_size) - (20 * tile_size)) {
mara_box.base.x += mara_speed; 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 { export fn update() void {
defer frame_count += 1; defer frame_count += 1;
if (frame_count % 60 == 0) { if (frame_count % 60 == 0) {
done = false; done = false;
} }
switch (state) { switch (sh0rk.state) {
.Title => title() catch unreachable, .Title => overhead.title() catch unreachable,
.StoryDump => storydump() catch unreachable, .StoryDump => overhead.storydump() catch unreachable,
.Gameplay => gameplay() catch unreachable, .Gameplay => gameplay() catch unreachable,
} }
} }
@ -393,18 +335,6 @@ fn draw_mara() void {
}; };
var step: u32 = if (mara_frame) 1 else 0; 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); var scr = world_to_screen(mara_box.base);
w4.blitSub( w4.blitSub(

View File

@ -192,7 +192,7 @@ pub const coll = [_]Rect{
}; };
pub const triggers = [_]Trigger{ 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 = 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 Trigger{ .aura = Rect{ .base = Point{ .x = 96, .y = 103 }, .width = 7, .height = 16 }, .direction = Direction.Up, .dialogue = "Moar ded." }, // gravestone 2
}; };

77
src/overhead.zig Normal file
View File

@ -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();
}
}
}

View File

@ -83,4 +83,6 @@ pub const State = enum {
Title, Title,
StoryDump, StoryDump,
Gameplay, Gameplay,
}; };
pub var state: State = .Gameplay;