Begin using world coordinates for everything

master
Louis Pearson 2022-01-22 18:08:53 -07:00
parent 19a1b8cad7
commit 73cb53e5e3
8 changed files with 223 additions and 124 deletions

File diff suppressed because one or more lines are too long

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<map version="1.5" tiledversion="1.7.2" orientation="orthogonal" renderorder="right-down" width="60" height="60" tilewidth="8" tileheight="8" infinite="0" nextlayerid="4" nextobjectid="3">
<map version="1.5" tiledversion="1.7.2" orientation="orthogonal" renderorder="right-down" width="60" height="60" tilewidth="8" tileheight="8" infinite="0" nextlayerid="4" nextobjectid="5">
<editorsettings>
<chunksize width="20" height="20"/>
<export target="map.json" format="json"/>
@ -57,20 +57,21 @@
39,0,0,20,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,21,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
39,0,0,20,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,37,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
39,0,0,20,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,37,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
39,0,0,68,19,19,19,19,19,19,19,19,19,19,19,19,19,19,19,36,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
39,0,0,20,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,37,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
39,0,0,51,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,37,0,0,0,0,0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,0,0,0,0,0,0,0,
0,22,22,22,22,22,22,22,22,22,22,22,23,0,0,0,0,37,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,54,54,54,54,0,0,36,52,0,0,0,37,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,39,0,0,0,0,37,0,39,0,0,0,0,37,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,54,54,54,54,65,52,0,0,37,0,39,0,0,0,50,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
54,55,0,0,0,0,51,0,0,0,37,0,39,0,0,0,0,53,54,54,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,50,54,54,66,52,0,0,0,0,0,49,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,0,0,0,0,3,0,0,0,0,0,0,0,35,51,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,22,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
</data>
</layer>
<layer id="2" name="conduit" width="60" height="60">
<data encoding="csv">
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,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,0,0,0,0,0,27,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,24,46,0,0,47,74,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,27,0,0,0,0,45,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,27,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
0,40,26,26,26,26,26,26,26,26,41,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
</data>
</layer>
<objectgroup id="3" name="objects">
@ -140,5 +140,12 @@
<object id="2" type="source" x="4" y="332">
<point/>
</object>
<object id="3" type="wire" x="44" y="452">
<properties>
<property name="anchor1" type="bool" value="false"/>
</properties>
<polyline points="0,0 -24,0"/>
</object>
<object id="4" type="focus" x="0" y="424" width="96" height="56"/>
</objectgroup>
</map>

File diff suppressed because one or more lines are too long

View File

@ -1,4 +1,4 @@
#!/usr/bin/env bash
w4 png2src --template assets/assets-template --zig assets/tiles.png -o assets/tiles.zig
zig run map2src.zig -- assets/maps/map.zig assets/maps/test.json
zig run map2src.zig -- assets/maps/map.zig assets/maps/map.json

View File

@ -13,16 +13,16 @@ const Point = struct {
};
const Object = struct {
height: u64 = 0,
height: f64 = 0,
id: u64 = 0,
name: []const u8,
point: bool = false,
polyline: []Point = &.{},
properties: []Property = &.{},
rotation: f64 = 0,
@"type": enum { wire, source, door, spawn },
@"type": enum { wire, source, door, spawn, focus },
visible: bool = true,
width: u64 = 0,
width: f64 = 0,
x: f64 = 0,
y: f64 = 0,
};
@ -108,6 +108,7 @@ pub fn do() !void {
try outlist.appendSlice("const std = @import(\"std\");\n");
try outlist.appendSlice("const Vec2 = std.meta.Vector(2,i32);\n");
try outlist.appendSlice("const AABB = struct {pos: Vec2, size: Vec2};\n");
try outlist.appendSlice("const Wire = struct { p1: Vec2, p2: Vec2, a1: bool, a2: bool };\n");
var outbuffer: [16 * KB]u8 = undefined;
@ -131,11 +132,15 @@ pub fn do() !void {
var sourcelist = std.ArrayList(Object).init(alloc);
defer sourcelist.deinit();
var focilist = std.ArrayList(Object).init(alloc);
defer focilist.deinit();
for (layer.objects) |obj| {
switch (obj.@"type") {
.wire => try wirelist.append(obj),
.door => try doorlist.append(obj),
.source => try sourcelist.append(obj),
.focus => try focilist.append(obj),
.spawn => try appendSpawn(&outlist, obj),
}
}
@ -143,6 +148,7 @@ pub fn do() !void {
try appendWires(&outlist, wirelist);
try appendDoors(&outlist, doorlist);
try appendSources(&outlist, sourcelist);
try appendFoci(&outlist, focilist);
},
}
}
@ -199,6 +205,27 @@ pub fn appendSources(outlist: *std.ArrayList(u8), sourcelist: std.ArrayList(Obje
try outlist.appendSlice("};\n");
}
pub fn appendFoci(outlist: *std.ArrayList(u8), sourcelist: std.ArrayList(Object)) !void {
var outbuffer: [4 * KB]u8 = undefined;
var outcontent = try std.fmt.bufPrint(&outbuffer, "pub const focus: [{}]AABB = [_]AABB{{", .{sourcelist.items.len});
try outlist.appendSlice(outcontent);
for (sourcelist.items) |obj| {
var sourcef = try std.fmt.bufPrint(
&outbuffer,
"AABB{{ .pos = Vec2{{ {}, {} }}, .size = Vec2{{ {}, {} }} }}",
.{
@floatToInt(i32, @divTrunc(obj.x, 8)),
@floatToInt(i32, @divTrunc(obj.y, 8)),
@floatToInt(i32, @divTrunc(obj.width, 8)),
@floatToInt(i32, @divTrunc(obj.height, 8)),
},
);
try outlist.appendSlice(sourcef);
}
try outlist.appendSlice("};\n");
}
pub fn appendSpawn(outlist: *std.ArrayList(u8), spawn: Object) !void {
var outbuffer: [4 * KB]u8 = undefined;
var outcontent = try std.fmt.bufPrint(

View File

@ -20,7 +20,7 @@ pub fn is_conduit(tile: u8) bool {
}
pub fn is_switch(tile: u8) bool {
return tile >= 27 and tile <= 28;
return tile == 27 and tile == 28;
}
pub fn toggle_switch(tile: u8) u8 {
@ -48,8 +48,8 @@ fn get_inputs(tile: u8) Current {
// Corners
23 => .{ false, true, true, false },
24 => .{ false, false, true, true },
39 => .{ true, false, false, true },
40 => .{ true, true, false, false },
39 => .{ true, true, false, false },
40 => .{ true, false, false, true },
// Straight
25 => .{ false, true, false, true },
26 => .{ true, false, true, false },
@ -92,7 +92,8 @@ fn get_plugs(tile: u8) Plugs {
};
}
pub fn get_cell(this: @This(), c: Cell) ?u8 {
pub fn get_cell(this: @This(), cell: Cell) ?u8 {
const c = cell - this.offset;
if (c[0] < 0 or c[0] > 19 or c[1] > 19 or c[1] < 0) return null;
const i = @intCast(usize, @mod(c[0], 20) + (c[1] * 20));
return if (this.cells[i].tile != 0) this.cells[i].tile - 1 else null;
@ -116,18 +117,21 @@ fn cell2index(c: Cell) ?usize {
const CellState = struct { enabled: bool = false, tile: u8 };
const MAXCELLS = 400;
const MAXBRIDGES = 10;
const MAXSOURCES = 10;
const CellMap = [MAXCELLS]CellState;
const BridgeState = struct { cells: [2]Cell, id: usize, enabled: bool };
offset: Cell,
cells: CellMap,
bridges: std.BoundedArray(BridgeState, MAXBRIDGES),
sources: std.BoundedArray(Cell, MAXSOURCES),
pub fn init() @This() {
var this = @This(){
.offset = Cell{ 0, 0 },
.cells = undefined,
.bridges = std.BoundedArray(BridgeState, MAXBRIDGES).init(0) catch unreachable,
.sources = std.BoundedArray(Cell, MAXSOURCES).init(0) catch unreachable,
};
return this;
}
@ -163,6 +167,12 @@ pub fn bridge(this: *@This(), cells: [2]Cell, bridgeID: usize) void {
}
}
pub fn addSource(this: *@This(), cell: Cell) void {
if (this.indexOf(cell)) |_| {
this.sources.append(cell) catch unreachable;
}
}
pub fn enabledBridges(this: @This()) std.BoundedArray(usize, MAXBRIDGES) {
var items = std.BoundedArray(usize, MAXBRIDGES).init(0) catch unreachable;
for (this.bridges.constSlice()) |b| {
@ -178,7 +188,8 @@ pub fn isEnabled(this: @This(), cell: Cell) bool {
return false;
}
pub fn toggle(this: *@This(), cell: Cell) void {
pub fn toggle(this: *@This(), c: Cell) void {
const cell = c - this.offset;
if (this.get_cell(cell)) |tile| {
if (is_switch(tile)) {
this.set_cell(cell, toggle_switch(tile));
@ -193,14 +204,21 @@ pub fn clear(this: *@This()) void {
this.bridges.resize(0) catch unreachable;
}
pub fn reset(this: *@This()) void {
this.clear();
this.sources.resize(0) catch unreachable;
}
const w4 = @import("wasm4.zig");
// Returns number of cells filled
pub fn fill(this: *@This(), rootRaw: Cell) usize {
pub fn fill(this: *@This()) usize {
const Queue = util.Queue(Cell, MAXCELLS);
var count: usize = 0;
const root = rootRaw - this.offset;
var visited: [MAXCELLS]bool = [_]bool{false} ** MAXCELLS;
var q = Queue.init();
q.insert(root);
for (this.sources.slice()) |source| {
q.insert(source);
}
while (q.remove()) |cell| {
const index = this.indexOf(cell) orelse continue;
const tile = this.get_cell(cell) orelse continue;

View File

@ -193,8 +193,11 @@ export fn start() void {
circuit.load(mapPos, &assets.conduit, assets.conduit_size);
map.load(mapPos, &assets.solid, assets.solid_size);
const tile_size = Vec2{ 8, 8 };
const offset = Vec2{ 4, 8 };
player = .{
.pos = Pos.init(util.vec2ToVec2f((assets.spawn - mapPos) * Map.tile_size) + Vec2f{ 4, 8 }),
.pos = Pos.init(util.vec2ToVec2f(assets.spawn * tile_size + offset)),
.control = .{ .controller = .player, .state = .stand },
.sprite = .{ .offset = .{ -4, -8 }, .size = .{ 8, 8 }, .index = 8, .flags = .{ .bpp = .b2 } },
.physics = .{ .friction = Vec2f{ 0.15, 0.1 }, .gravity = Vec2f{ 0, 0.25 } },
@ -222,45 +225,18 @@ export fn start() void {
const w = Wire{ .nodes = nodes };
wires.append(w) catch unreachable;
}
for (assets.sources) |source| {
circuit.addSource(source);
}
updateCircuit();
}
var indicator: ?struct { pos: Vec2, t: enum { wire, plug, lever }, active: bool = false } = null;
var time: usize = 0;
export fn update() void {
{
// Doing this before clearing the screen since the stack
// reaches the screen during this block
circuit.clear();
for (wires.slice()) |*wire, wireID| {
const nodes = wire.nodes.constSlice();
const cellBegin = util.world2cell(nodes[0].pos);
const cellEnd = util.world2cell(nodes[nodes.len - 1].pos);
circuit.bridge(.{ cellBegin, cellEnd }, wireID);
}
var count: usize = 0;
for (assets.sources) |source| {
count += circuit.fill(source);
}
if (count < 30) {
music.newIntensity = .calm;
} else if (count < 60) {
music.newIntensity = .active;
} else {
music.newIntensity = .danger;
}
var enabledWires = circuit.enabledBridges();
for (enabledWires.slice()) |wireID| {
var wire = &wires.slice()[wireID];
wire.enabled = true;
if (time % 60 == 0) {
if (!wire.begin().pinned) particles.createNRandom(wire.begin().pos, 8);
if (!wire.end().pinned) particles.createNRandom(wire.end().pos, 8);
}
}
}
for (wires.slice()) |*wire| {
wirePhysicsProcess(1, wire);
}
@ -361,6 +337,7 @@ fn manipulationProcess(pos: *Pos, control: *Control) void {
indicator = .{ .t = .lever, .pos = cell * @splat(2, @as(i32, 8)) + Vec2{ 4, 4 } };
if (input.btnp(.one, .two)) {
circuit.toggle(cell);
updateCircuit();
}
}
}
@ -390,6 +367,8 @@ fn manipulationProcess(pos: *Pos, control: *Control) void {
if (interactWireID) |wireID| {
if (input.btnp(.one, .two)) {
control.grabbing = .{ .id = wireID, .which = which };
wires.slice()[wireID].nodes.slice()[which].pos = pos.pos + Vec2f{ 0, -4 };
updateCircuit();
}
}
} else if (control.grabbing) |details| {
@ -402,9 +381,11 @@ fn manipulationProcess(pos: *Pos, control: *Control) void {
if (length > maxLength * 1.5) {
nodes[details.which].pinned = false;
control.grabbing = null;
return;
// updateCircuit = true;
// return;
} else {
nodes[details.which].pos = pos.pos + Vec2f{ 0, -4 };
// updateCircuit = true;
}
if (Circuit.is_plug(circuit.get_cell(cell) orelse 0)) {
@ -414,10 +395,40 @@ fn manipulationProcess(pos: *Pos, control: *Control) void {
nodes[details.which].pinned = true;
nodes[details.which].pos = vec2tovec2f(indicator.?.pos);
control.grabbing = null;
updateCircuit();
}
} else if (input.btnp(.one, .two)) {
nodes[details.which].pinned = false;
control.grabbing = null;
// updateCircuit = true;
}
}
}
fn updateCircuit() void {
circuit.clear();
for (wires.slice()) |*wire, wireID| {
const nodes = wire.nodes.constSlice();
const cellBegin = util.world2cell(nodes[0].pos);
const cellEnd = util.world2cell(nodes[nodes.len - 1].pos);
circuit.bridge(.{ cellBegin, cellEnd }, wireID);
}
var count = circuit.fill();
if (count < 30) {
music.newIntensity = .calm;
} else if (count < 60) {
music.newIntensity = .active;
} else {
music.newIntensity = .danger;
}
var enabledWires = circuit.enabledBridges();
for (enabledWires.slice()) |wireID| {
var wire = &wires.slice()[wireID];
wire.enabled = true;
if (time % 60 == 0) {
if (!wire.begin().pinned) particles.createNRandom(wire.begin().pos, 8);
if (!wire.end().pinned) particles.createNRandom(wire.end().pos, 8);
}
}
}
@ -497,7 +508,7 @@ fn vec2ftovec2(vec2f: Vec2f) w4.Vec2 {
fn drawProcess(_: f32, pos: *Pos, sprite: *Sprite) void {
w4.DRAW_COLORS.* = 0x0010;
const fpos = pos.pos + sprite.offset;
const ipos = w4.Vec2{ @floatToInt(i32, fpos[0]), @floatToInt(i32, fpos[1]) };
const ipos = w4.Vec2{ @floatToInt(i32, fpos[0]), @floatToInt(i32, fpos[1]) } - map.offset * Map.tile_size;
const index = sprite.index;
const t = w4.Vec2{ @intCast(i32, (index * 8) % 128), @intCast(i32, (index * 8) / 128) };
w4.blitSub(&assets.tiles, ipos, sprite.size, t, 128, sprite.flags);

View File

@ -20,30 +20,24 @@ const tilemap_height = 16;
const tilemap_stride = 128;
alloc: std.mem.Allocator,
tiles: []u8,
tiles: []const u8,
offset: Cell,
map_size: Vec2,
pub fn init(alloc: std.mem.Allocator) !@This() {
var tiles = try alloc.alloc(u8, MAXCELLS);
var this = @This(){
.alloc = alloc,
.offset = Cell{ 0, 0 },
.tiles = tiles,
.tiles = &assets.solid,
.map_size = assets.solid_size,
};
return this;
}
pub fn load(this: *@This(), offset: Cell, map: []const u8, map_size: Vec2) void {
this.offset = offset;
var y: usize = 0;
while (y < height) : (y += 1) {
var x: usize = 0;
while (x < width) : (x += 1) {
const i = x + y * 20;
const a = (@intCast(usize, offset[0]) + x) + (@intCast(usize, offset[1]) + y) * @intCast(usize, map_size[0]);
this.tiles[i] = map[a];
}
}
this.tiles = map;
this.map_size = map_size;
}
pub fn deinit(this: @This()) void {
@ -52,32 +46,35 @@ pub fn deinit(this: @This()) void {
pub fn draw(this: @This()) void {
w4.DRAW_COLORS.* = 0x0210;
for (this.tiles) |tilePlus, i| {
if (tilePlus == 0) continue;
const tile = tilePlus - 1;
const t = Vec2{
@intCast(i32, (tile % tilemap_width) * tile_width),
@intCast(i32, (tile / tilemap_width) * tile_width),
};
const pos = Vec2{
@intCast(i32, (i % width) * tile_width),
@intCast(i32, (i / width) * tile_width),
};
w4.blitSub(
&assets.tiles,
pos,
.{ tile_width, tile_height },
t,
tilemap_stride,
.{ .bpp = .b2 },
);
var y: usize = 0;
while (y < height) : (y += 1) {
var x: usize = 0;
while (x < width) : (x += 1) {
const pos = Vec2{ @intCast(i32, x), @intCast(i32, y) } * tile_size;
const a = (@intCast(usize, this.offset[0]) + x) + (@intCast(usize, this.offset[1]) + y) * @intCast(usize, this.map_size[0]);
const tilePlus = this.tiles[a];
if (tilePlus == 0) continue;
const tile = tilePlus - 1;
const t = Vec2{
@intCast(i32, (tile % tilemap_width) * tile_width),
@intCast(i32, (tile / tilemap_width) * tile_width),
};
w4.blitSub(
&assets.tiles,
pos,
.{ tile_width, tile_height },
t,
tilemap_stride,
.{ .bpp = .b2 },
);
}
}
}
/// pos should be in tile coordinates, not world coordinates
fn getTile(this: @This(), x: i32, y: i32) ?u8 {
if (x < 0 or x > 19 or y < 0 or y > 19) return null;
const i = x + y * 20;
if (x < 0 or x > this.map_size[0] or y < 0 or y > this.map_size[1]) return null;
const i = x + y * this.map_size[0];
return this.tiles[@intCast(u32, i)];
}