Wires work properly again
parent
a458426bed
commit
d8f624a838
File diff suppressed because one or more lines are too long
|
@ -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="5">
|
||||
<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="7">
|
||||
<editorsettings>
|
||||
<chunksize width="20" height="20"/>
|
||||
<export target="map.json" format="json"/>
|
||||
|
@ -60,10 +60,10 @@
|
|||
39,0,0,53,19,19,19,19,19,19,19,19,19,19,19,19,19,65,22,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,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,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,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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,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,44,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,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,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,12 +140,19 @@
|
|||
<object id="2" type="source" x="4" y="332">
|
||||
<point/>
|
||||
</object>
|
||||
<object id="3" type="wire" x="44" y="452">
|
||||
<object id="3" type="wire" x="52" y="460">
|
||||
<properties>
|
||||
<property name="anchor1" type="bool" value="false"/>
|
||||
<property name="anchor1" type="bool" value="true"/>
|
||||
<property name="anchor2" type="bool" value="false"/>
|
||||
</properties>
|
||||
<polyline points="0,0 -24,0"/>
|
||||
<polyline points="0,-8 -50,10"/>
|
||||
</object>
|
||||
<object id="4" type="focus" x="0" y="424" width="96" height="56"/>
|
||||
<object id="5" type="wire" x="20" y="436">
|
||||
<polyline points="0,0 16,0"/>
|
||||
</object>
|
||||
<object id="6" type="door" x="84" y="468">
|
||||
<point/>
|
||||
</object>
|
||||
</objectgroup>
|
||||
</map>
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -151,7 +151,6 @@ const CellMap = struct {
|
|||
|
||||
const BridgeState = struct { cells: [2]Cell, id: usize, enabled: bool };
|
||||
|
||||
offset: Cell,
|
||||
map: []const u8,
|
||||
map_size: Vec2,
|
||||
cell_map: CellMap,
|
||||
|
@ -160,7 +159,6 @@ sources: std.BoundedArray(Cell, MAXSOURCES),
|
|||
|
||||
pub fn init() @This() {
|
||||
var this = @This(){
|
||||
.offset = Cell{ 0, 0 },
|
||||
.map = &assets.conduit,
|
||||
.map_size = assets.conduit_size,
|
||||
.cell_map = CellMap.init(),
|
||||
|
@ -170,19 +168,9 @@ pub fn init() @This() {
|
|||
return this;
|
||||
}
|
||||
|
||||
pub fn load(this: *@This(), offset: Cell, map: []const u8, map_size: Vec2) void {
|
||||
this.offset = offset;
|
||||
pub fn load(this: *@This(), map: []const u8, map_size: Vec2) void {
|
||||
this.map = map;
|
||||
this.map_size = map_size;
|
||||
// var y: usize = 0;
|
||||
// while (y < 20) : (y += 1) {
|
||||
// var x: usize = 0;
|
||||
// while (x < 20) : (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.cells[i].tile = map[a];
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
||||
pub fn indexOf(this: @This(), cell: Cell) ?usize {
|
||||
|
@ -295,16 +283,16 @@ const tilemap_width = 16;
|
|||
const tilemap_height = 16;
|
||||
const tilemap_stride = 128;
|
||||
|
||||
pub fn draw(this: @This()) void {
|
||||
pub fn draw(this: @This(), offset: Vec2) void {
|
||||
var y: usize = 0;
|
||||
while (y < height) : (y += 1) {
|
||||
var x: usize = 0;
|
||||
while (x < width) : (x += 1) {
|
||||
const cell = Vec2{ @intCast(i32, x), @intCast(i32, y) };
|
||||
const pos = cell * tile_size;
|
||||
const tile = this.get_cell(cell + this.offset) orelse continue;
|
||||
const tile = this.get_cell(cell + offset) orelse continue;
|
||||
if (tile == 0) continue;
|
||||
if (this.isEnabled(cell + this.offset)) w4.DRAW_COLORS.* = 0x0210 else w4.DRAW_COLORS.* = 0x0310;
|
||||
if (this.isEnabled(cell + offset)) w4.DRAW_COLORS.* = 0x0210 else w4.DRAW_COLORS.* = 0x0310;
|
||||
const t = Vec2{
|
||||
@intCast(i32, (tile % tilemap_width) * tile_size[0]),
|
||||
@intCast(i32, (tile / tilemap_width) * tile_size[0]),
|
||||
|
|
44
src/main.zig
44
src/main.zig
|
@ -114,7 +114,7 @@ const ParticleSystem = struct {
|
|||
pub fn draw(this: @This()) void {
|
||||
for (this.particles.constSlice()) |*part| {
|
||||
w4.DRAW_COLORS.* = 0x0002;
|
||||
w4.oval(util.vec2fToVec2(part.pos.pos), Vec2{ 2, 2 });
|
||||
w4.oval(util.vec2fToVec2(part.pos.pos) - camera * Map.tile_size, Vec2{ 2, 2 });
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -157,6 +157,7 @@ var random = prng.random();
|
|||
var player: Player = undefined;
|
||||
var music = Music.Procedural.init(.C3, &Music.Minor, 83);
|
||||
var wires = std.BoundedArray(Wire, 10).init(0) catch unreachable;
|
||||
var camera = Vec2{ 0, 0 };
|
||||
|
||||
const anim_store = struct {
|
||||
const stand = Anim.frame(8);
|
||||
|
@ -189,9 +190,9 @@ export fn start() void {
|
|||
circuit = Circuit.init();
|
||||
map = Map.init(fba.allocator()) catch showErr("Init map");
|
||||
|
||||
const mapPos = @divTrunc(assets.spawn, @splat(2, @as(i32, 20))) * @splat(2, @as(i32, 20));
|
||||
circuit.load(mapPos, &assets.conduit, assets.conduit_size);
|
||||
map.load(mapPos, &assets.solid, assets.solid_size);
|
||||
camera = @divTrunc(assets.spawn, @splat(2, @as(i32, 20))) * @splat(2, @as(i32, 20));
|
||||
circuit.load(&assets.conduit, assets.conduit_size);
|
||||
map.load(&assets.solid, assets.solid_size);
|
||||
|
||||
const tile_size = Vec2{ 8, 8 };
|
||||
const offset = Vec2{ 4, 8 };
|
||||
|
@ -239,6 +240,12 @@ var time: usize = 0;
|
|||
export fn update() void {
|
||||
for (wires.slice()) |*wire| {
|
||||
wirePhysicsProcess(1, wire);
|
||||
if (wire.enabled) {
|
||||
if (time % 60 == 0) {
|
||||
if (!wire.begin().pinned) particles.createNRandom(wire.begin().pos, 8);
|
||||
if (!wire.end().pinned) particles.createNRandom(wire.end().pos, 8);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
velocityProcess(1, &player.pos);
|
||||
|
@ -254,8 +261,8 @@ export fn update() void {
|
|||
w4.rect(.{ 0, 0 }, .{ 160, 160 });
|
||||
drawProcess(1, &player.pos, &player.sprite);
|
||||
|
||||
map.draw();
|
||||
circuit.draw();
|
||||
map.draw(camera);
|
||||
circuit.draw(camera);
|
||||
|
||||
for (wires.slice()) |*wire| {
|
||||
wireDrawProcess(1, wire);
|
||||
|
@ -279,7 +286,7 @@ export fn update() void {
|
|||
}
|
||||
|
||||
if (indicator) |details| {
|
||||
const pos = details.pos - (map.offset * Map.tile_size);
|
||||
const pos = details.pos - (camera * Map.tile_size);
|
||||
const stage = @divTrunc((time % 60), 30);
|
||||
var size = Vec2{ 0, 0 };
|
||||
switch (stage) {
|
||||
|
@ -361,6 +368,7 @@ fn manipulationProcess(pos: *Pos, control: *Control) void {
|
|||
if (input.btnp(.one, .two)) {
|
||||
control.grabbing = .{ .id = wireID, .which = which };
|
||||
wires.slice()[wireID].nodes.slice()[which].pos = pos.pos + Vec2f{ 0, -4 };
|
||||
wires.slice()[wireID].nodes.slice()[which].pinned = false;
|
||||
updateCircuit();
|
||||
}
|
||||
}
|
||||
|
@ -401,6 +409,8 @@ fn manipulationProcess(pos: *Pos, control: *Control) void {
|
|||
fn updateCircuit() void {
|
||||
circuit.clear();
|
||||
for (wires.slice()) |*wire, wireID| {
|
||||
wire.enabled = false;
|
||||
if (!wire.begin().pinned or !wire.end().pinned) continue;
|
||||
const nodes = wire.nodes.constSlice();
|
||||
const cellBegin = util.world2cell(nodes[0].pos);
|
||||
const cellEnd = util.world2cell(nodes[nodes.len - 1].pos);
|
||||
|
@ -415,14 +425,13 @@ fn updateCircuit() void {
|
|||
} 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| {
|
||||
const begin = wire.begin();
|
||||
const end = wire.end();
|
||||
if (!begin.pinned and !end.pinned) continue;
|
||||
const cellBegin = util.world2cell(begin.pos);
|
||||
const cellEnd = util.world2cell(end.pos);
|
||||
if (circuit.isEnabled(cellBegin) or circuit.isEnabled(cellEnd)) wire.enabled = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -485,10 +494,9 @@ fn wireDrawProcess(_: f32, wire: *Wire) void {
|
|||
w4.DRAW_COLORS.* = if (wire.enabled) 0x0002 else 0x0003;
|
||||
for (nodes) |node, i| {
|
||||
if (i == 0) continue;
|
||||
const offset = (map.offset * Map.tile_size);
|
||||
const offset = (camera * Map.tile_size);
|
||||
w4.line(vec2ftovec2(nodes[i - 1].pos) - offset, vec2ftovec2(node.pos) - offset);
|
||||
}
|
||||
wire.enabled = false;
|
||||
}
|
||||
|
||||
fn vec2tovec2f(vec2: w4.Vec2) Vec2f {
|
||||
|
@ -502,7 +510,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]) } - map.offset * Map.tile_size;
|
||||
const ipos = w4.Vec2{ @floatToInt(i32, fpos[0]), @floatToInt(i32, fpos[1]) } - camera * 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);
|
||||
|
|
|
@ -21,21 +21,18 @@ const tilemap_stride = 128;
|
|||
|
||||
alloc: std.mem.Allocator,
|
||||
tiles: []const u8,
|
||||
offset: Cell,
|
||||
map_size: Vec2,
|
||||
|
||||
pub fn init(alloc: std.mem.Allocator) !@This() {
|
||||
var this = @This(){
|
||||
.alloc = alloc,
|
||||
.offset = Cell{ 0, 0 },
|
||||
.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;
|
||||
pub fn load(this: *@This(), map: []const u8, map_size: Vec2) void {
|
||||
this.tiles = map;
|
||||
this.map_size = map_size;
|
||||
}
|
||||
|
@ -44,14 +41,14 @@ pub fn deinit(this: @This()) void {
|
|||
this.alloc.free(this.tiles);
|
||||
}
|
||||
|
||||
pub fn draw(this: @This()) void {
|
||||
pub fn draw(this: @This(), offset: Vec2) void {
|
||||
w4.DRAW_COLORS.* = 0x0210;
|
||||
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 a = (@intCast(usize, offset[0]) + x) + (@intCast(usize, offset[1]) + y) * @intCast(usize, this.map_size[0]);
|
||||
const tilePlus = this.tiles[a];
|
||||
if (tilePlus == 0) continue;
|
||||
const tile = tilePlus - 1;
|
||||
|
|
Loading…
Reference in New Issue