Add humming when near active circuits
parent
d73f8d16bb
commit
199c206a6d
17
src/main.zig
17
src/main.zig
|
@ -155,6 +155,7 @@ var circuit: Circuit = undefined;
|
||||||
var particles: ParticleSystem = undefined;
|
var particles: ParticleSystem = undefined;
|
||||||
var prng = std.rand.DefaultPrng.init(0);
|
var prng = std.rand.DefaultPrng.init(0);
|
||||||
var random = prng.random();
|
var random = prng.random();
|
||||||
|
var player: ?usize = null;
|
||||||
|
|
||||||
const anim_store = struct {
|
const anim_store = struct {
|
||||||
const stand = Anim.frame(0);
|
const stand = Anim.frame(0);
|
||||||
|
@ -193,7 +194,7 @@ export fn start() void {
|
||||||
|
|
||||||
// w4.trace("{}, {}, {}", .{ assets.spawn, mapPos, assets.spawn - mapPos });
|
// 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 }),
|
.pos = Pos.init(util.vec2ToVec2f((assets.spawn - mapPos) * Map.tile_size) + Vec2f{ 4, 8 }),
|
||||||
.control = .{ .controller = .player, .state = .stand },
|
.control = .{ .controller = .player, .state = .stand },
|
||||||
.sprite = .{ .offset = .{ -4, -8 }, .size = .{ 8, 8 }, .index = 0, .flags = .{ .bpp = .b1 } },
|
.sprite = .{ .offset = .{ -4, -8 }, .size = .{ 8, 8 }, .index = 0, .flags = .{ .bpp = .b1 } },
|
||||||
|
@ -289,6 +290,18 @@ export fn update() void {
|
||||||
particles.update();
|
particles.update();
|
||||||
particles.draw();
|
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| {
|
if (indicator) |details| {
|
||||||
const pos = details.pos;
|
const pos = details.pos;
|
||||||
const stage = @divTrunc((time % 60), 30);
|
const stage = @divTrunc((time % 60), 30);
|
||||||
|
@ -299,7 +312,7 @@ export fn update() void {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (details.active) {
|
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;
|
w4.DRAW_COLORS.* = 0x0020;
|
||||||
} else {
|
} else {
|
||||||
w4.DRAW_COLORS.* = 0x0030;
|
w4.DRAW_COLORS.* = 0x0030;
|
||||||
|
|
14
src/util.zig
14
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 Vec2 = std.meta.Vector(2, i32);
|
||||||
pub const Cell = Vec2;
|
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 {
|
pub fn distance(a: Vec2, b: Vec2) i32 {
|
||||||
var subbed = a - b;
|
var subbed = a - b;
|
||||||
subbed[0] = std.math.absInt(subbed[0]) catch unreachable;
|
subbed[0] = std.math.absInt(subbed[0]) catch unreachable;
|
||||||
|
|
Loading…
Reference in New Issue