diff --git a/assets/maps/wired.ldtk b/assets/maps/wired.ldtk index c58fc31..32dc4ad 100644 --- a/assets/maps/wired.ldtk +++ b/assets/maps/wired.ldtk @@ -3610,6 +3610,20 @@ "params": [ true ] }, null ] } ] + }, + { + "__identifier": "Coin", + "__grid": [8,5], + "__pivot": [0,0], + "__tags": [], + "__tile": { "tilesetUid": 1, "x": 32, "y": 0, "w": 8, "h": 8 }, + "__smartColor": "#E2D547", + "iid": "7c1eeee0-02f0-11ed-9529-a1263487e397", + "width": 8, + "height": 8, + "defUid": 61, + "px": [64,40], + "fieldInstances": [] } ] }, diff --git a/src/game.zig b/src/game.zig index 9322a6a..5d47fc8 100644 --- a/src/game.zig +++ b/src/game.zig @@ -141,7 +141,7 @@ fn randRangeF(min: f32, max: f32) f32 { } // Allocators -var fba_buf: [8192]u8 = undefined; +var fba_buf: [4096]u8 = undefined; var fba = std.heap.FixedBufferAllocator.init(&fba_buf); var alloc = fba.allocator(); @@ -149,7 +149,7 @@ var frame_fba_buf: [8192]u8 = undefined; var frame_fba = std.heap.FixedBufferAllocator.init(&frame_fba_buf); var frame_alloc = frame_fba.allocator(); -var db_fba_buf: [2046]u8 = undefined; +var db_fba_buf: [4096]u8 = undefined; var db_fba = std.heap.FixedBufferAllocator.init(&db_fba_buf); var db_alloc = db_fba.allocator(); @@ -357,7 +357,7 @@ fn moveLevel(direction: enum { L, R, U, D }) !void { const lvl = db.findLevel(x, y) orelse return error.NoLevelUp; try loadLevel(lvl); - player.pos.pos[1] = 160; + player.pos.pos[1] = 159; }, .D => { const x = level.world_x; @@ -365,7 +365,7 @@ fn moveLevel(direction: enum { L, R, U, D }) !void { const lvl = db.findLevel(x, y) orelse return error.NoLevelDown; try loadLevel(lvl); - player.pos.pos[1] = @intToFloat(f32, player.sprite.size[1]); + player.pos.pos[1] = @intToFloat(f32, player.sprite.size[1]) - 4; }, } player.pos.last = player.pos.pos - velocity; @@ -439,7 +439,7 @@ pub fn update(time: usize) !State { if (player.pos.pos[0] > 160 - 4) try moveLevel(.R); if (player.pos.pos[0] < 4) try moveLevel(.L); if (player.pos.pos[1] > 160) try moveLevel(.D); - if (player.pos.pos[1] < 8) try moveLevel(.U); + if (player.pos.pos[1] < 4) try moveLevel(.U); try kinematicProcess(1, &player.pos, &player.kinematic); controlAnimProcess(1, &player.sprite, &player.controlAnim, &player.control); @@ -461,7 +461,8 @@ pub fn update(time: usize) !State { try remove.append(i); music.playCollect(score); shouldSave = true; - const coord = world.Coordinate.fromVec2(util.world2cell(coin.pos.pos)); + const levelc = world.Coordinate.fromWorld(level.world_x, level.world_y); + const coord = world.Coordinate.fromVec2(util.world2cell(coin.pos.pos)).addC(levelc); db.collectCoin(coord); } } @@ -713,7 +714,7 @@ fn manipulationProcess(pos: *Pos, control: *Control) !void { }; const x = level.world_x * 20 + @intCast(i16, cell[0]); const y = level.world_y * 20 + @intCast(i16, cell[1]); - w4.tracef("---- Updating switch (%d, %d)", x, y); + db.setSwitch(Coord.init(.{ x, y }), new_state); } try updateCircuit(); @@ -744,8 +745,6 @@ fn updateCircuit() !void { @intCast(i16, cellEnd[1]), }).addC(topleft); - w4.tracef("p1 %d, %d \t p2 %d, %d", p1.val[0], p1.val[1], p2.val[0], p2.val[1]); - db.connectPlugs(p1, p2) catch { w4.tracef("connect plugs error"); }; diff --git a/src/map.zig b/src/map.zig index 6ec7391..6dacb38 100644 --- a/src/map.zig +++ b/src/map.zig @@ -73,7 +73,7 @@ pub fn set_cell(this: *@This(), cell: Cell, tile: u8) !void { pub fn get_cell(this: @This(), cell: Cell) ?u8 { const x = cell[0]; const y = cell[1]; - if (x < 0 or x > this.map_size[0] or y < 0 or y > this.map_size[1]) return null; + 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)]; } @@ -106,7 +106,7 @@ pub fn draw(this: @This(), offset: Vec2) void { /// pos should be in tile coordinates, not world coordinates fn getTile(this: @This(), x: i32, y: i32) ?u8 { - if (x < 0 or x > this.map_size[0] or y < 0 or y > this.map_size[1]) return null; + 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)]; }