diff --git a/src/main.zig b/src/main.zig index f897122..bc537cc 100644 --- a/src/main.zig +++ b/src/main.zig @@ -155,6 +155,7 @@ var circuit: Circuit = undefined; var particles: ParticleSystem = undefined; var prng = std.rand.DefaultPrng.init(0); var random = prng.random(); +var player: ?usize = null; const anim_store = struct { const stand = Anim.frame(0); @@ -193,7 +194,7 @@ export fn start() void { // w4.trace("{}, {}, {}", .{ assets.spawn, mapPos, assets.spawn - mapPos }); - _ = world.create(.{ + player = world.create(.{ .pos = Pos.init(util.vec2ToVec2f((assets.spawn - mapPos) * Map.tile_size) + Vec2f{ 4, 8 }), .control = .{ .controller = .player, .state = .stand }, .sprite = .{ .offset = .{ -4, -8 }, .size = .{ 8, 8 }, .index = 0, .flags = .{ .bpp = .b1 } }, @@ -289,6 +290,18 @@ export fn update() void { particles.update(); particles.draw(); + if (player) |p| { + const pos = util.world2cell(world.get(p).pos.?.pos); + const shouldHum = circuit.isEnabled(pos) or + circuit.isEnabled(pos + util.Dir.up) or + circuit.isEnabled(pos + util.Dir.down) or + circuit.isEnabled(pos + util.Dir.left) or + circuit.isEnabled(pos + util.Dir.right); + if (shouldHum) { + w4.tone(.{ .start = 60 }, .{ .release = 255, .sustain = 0 }, 1, .{ .channel = .pulse1, .mode = .p50 }); + } + } + if (indicator) |details| { const pos = details.pos; const stage = @divTrunc((time % 60), 30); @@ -299,7 +312,7 @@ export fn update() void { } if (details.active) { - w4.tone(.{ .start = 60, .end = 1 }, .{ .release = 30, .sustain = 0 }, 10, .{ .channel = .triangle }); + w4.tone(.{ .start = 60 }, .{ .release = 255, .sustain = 0 }, 10, .{ .channel = .pulse1, .mode = .p50 }); w4.DRAW_COLORS.* = 0x0020; } else { w4.DRAW_COLORS.* = 0x0030; diff --git a/src/util.zig b/src/util.zig index 74fb573..9bdc789 100644 --- a/src/util.zig +++ b/src/util.zig @@ -4,6 +4,20 @@ pub const Vec2f = std.meta.Vector(2, f32); pub const Vec2 = std.meta.Vector(2, i32); pub const Cell = Vec2; +pub const Dir = struct { + pub const up = Vec2{ 0, -1 }; + pub const down = Vec2{ 0, 1 }; + pub const left = Vec2{ -1, 0 }; + pub const right = Vec2{ 1, 0 }; +}; + +pub const DirF = struct { + pub const up = Vec2f{ 0, -1 }; + pub const down = Vec2f{ 0, 1 }; + pub const left = Vec2f{ -1, 0 }; + pub const right = Vec2f{ 1, 0 }; +}; + pub fn distance(a: Vec2, b: Vec2) i32 { var subbed = a - b; subbed[0] = std.math.absInt(subbed[0]) catch unreachable;