Persist collection of coins to memory
parent
240587344d
commit
1404d6067e
|
@ -418,6 +418,8 @@ pub fn update(time: usize) !State {
|
||||||
try remove.append(i);
|
try remove.append(i);
|
||||||
music.playCollect(score);
|
music.playCollect(score);
|
||||||
shouldSave = true;
|
shouldSave = true;
|
||||||
|
const coord = world.Coordinate.fromVec2(util.world2cell(coin.pos.pos));
|
||||||
|
db.collectCoin(coord);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
while (remove.popOrNull()) |i| {
|
while (remove.popOrNull()) |i| {
|
||||||
|
@ -661,7 +663,7 @@ fn manipulationProcess(pos: *Pos, control: *Control) !void {
|
||||||
const new_switch = circuit.toggle(cell);
|
const new_switch = circuit.toggle(cell);
|
||||||
if (new_switch) |tile| {
|
if (new_switch) |tile| {
|
||||||
const T = world.Tiles;
|
const T = world.Tiles;
|
||||||
const new_state: u8 = switch(tile) {
|
const new_state: u8 = switch (tile) {
|
||||||
T.SwitchTeeWestOn, T.SwitchTeeEastOn, T.SwitchVerticalOn => 1,
|
T.SwitchTeeWestOn, T.SwitchTeeEastOn, T.SwitchVerticalOn => 1,
|
||||||
else => 0,
|
else => 0,
|
||||||
};
|
};
|
||||||
|
|
|
@ -216,6 +216,10 @@ pub const Coordinate = struct {
|
||||||
} };
|
} };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn fromVec2(vec: @Vector(2, i32)) Coordinate {
|
||||||
|
return .{ .val = .{ @intCast(i16, vec[0]), @intCast(i16, vec[1]) } };
|
||||||
|
}
|
||||||
|
|
||||||
pub fn toLevelTopLeft(coord: Coordinate) Coordinate {
|
pub fn toLevelTopLeft(coord: Coordinate) Coordinate {
|
||||||
const worldc = coord.toWorld();
|
const worldc = coord.toWorld();
|
||||||
return .{ .val = .{
|
return .{ .val = .{
|
||||||
|
@ -431,6 +435,7 @@ pub const EntityKind = enum(u8) {
|
||||||
WireEndAnchor,
|
WireEndAnchor,
|
||||||
Door,
|
Door,
|
||||||
Trapdoor,
|
Trapdoor,
|
||||||
|
Collected,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const Entity = struct {
|
pub const Entity = struct {
|
||||||
|
@ -714,6 +719,18 @@ pub const Database = struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Entity functions
|
// Entity functions
|
||||||
|
pub fn getEntityID(database: *Database, coord: Coordinate) ?usize {
|
||||||
|
for (database.entities) |entity, i| {
|
||||||
|
if (!entity.coord.eq(coord)) continue;
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn collectCoin(db: *Database, coord: Coordinate) void {
|
||||||
|
const coin = db.getEntityID(coord) orelse return;
|
||||||
|
db.entities[coin].kind = .Collected;
|
||||||
|
}
|
||||||
|
|
||||||
pub fn getWire(database: *Database, level: Level, num: usize) ?[2]Entity {
|
pub fn getWire(database: *Database, level: Level, num: usize) ?[2]Entity {
|
||||||
const nw = Coord.fromWorld(level.world_x, level.world_y);
|
const nw = Coord.fromWorld(level.world_x, level.world_y);
|
||||||
|
|
Loading…
Reference in New Issue