From db0b1f207b09d7fbf84c0ad3e9c9acd4a20a8b76 Mon Sep 17 00:00:00 2001 From: rainlizard <15337628+rainlizard@users.noreply.github.com> Date: Tue, 30 Jul 2024 00:14:05 +1000 Subject: [PATCH] fixed torches attaching to correct wall --- Autoload/Utils.gd | 2 +- Scenes/Instances.gd | 20 ++++++++------------ Scenes/OverheadGraphics.gd | 12 +++++++++--- 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/Autoload/Utils.gd b/Autoload/Utils.gd index 5a4906c8..6e9c6300 100644 --- a/Autoload/Utils.gd +++ b/Autoload/Utils.gd @@ -39,7 +39,7 @@ func load_external_texture(path): var img = Image.new() img.load(path) var texture = ImageTexture.new() - texture.create_from_image(img) + texture.create_from_image(img, Texture.FLAG_MIPMAPS+Texture.FLAG_ANISOTROPIC_FILTER) return texture func get_filetype_in_directory(directory_path: String, file_extension: String) -> Array: diff --git a/Scenes/Instances.gd b/Scenes/Instances.gd index 872552a0..c456115e 100644 --- a/Scenes/Instances.gd +++ b/Scenes/Instances.gd @@ -264,18 +264,14 @@ func place_new_thing(newThingType, newSubtype, newPosition, newOwnership): # Pla elif id.subtype == 133: # Mysterious Box id.boxNumber = oPlacingSettings.boxNumber elif id.subtype in [2,7]: # Torch and Unlit Torch - if Slabs.data[oDataSlab.get_cell(xSlab+1,ySlab)][Slabs.IS_SOLID] == true: - id.locationX += 0.25 - id.parentTile = (xSlab+1) + ((ySlab) * M.xSize) # Should this be M.ySize ??? - if Slabs.data[oDataSlab.get_cell(xSlab-1,ySlab)][Slabs.IS_SOLID] == true: - id.locationX -= 0.25 - id.parentTile = (xSlab-1) + ((ySlab) * M.xSize) # Should this be M.ySize ??? - if Slabs.data[oDataSlab.get_cell(xSlab,ySlab+1)][Slabs.IS_SOLID] == true: - id.locationY += 0.25 - id.parentTile = (xSlab) + ((ySlab+1) * M.xSize) # Should this be M.ySize ??? - if Slabs.data[oDataSlab.get_cell(xSlab,ySlab-1)][Slabs.IS_SOLID] == true: - id.locationY -= 0.25 - id.parentTile = (xSlab) + ((ySlab-1) * M.xSize) # Should this be M.ySize ??? + for direction in [Vector2(1, 0), Vector2(-1, 0), Vector2(0, 1), Vector2(0, -1)]: + var getParentSlabX = floor((newPosition.x + direction.x) / 3) + var getParentSlabY = floor((newPosition.y + direction.y) / 3) + if Slabs.data[oDataSlab.get_cell(getParentSlabX, getParentSlabY)][Slabs.IS_SOLID] == true: + id.locationX += direction.x * 0.25 + id.locationY += direction.y * 0.25 + id.parentTile = getParentSlabX + (getParentSlabY * M.xSize) + break # We only want to adjust for one solid slab update_stray_torch_height(id) elif id.subtype in Things.LIST_OF_GOLDPILES: match id.subtype: diff --git a/Scenes/OverheadGraphics.gd b/Scenes/OverheadGraphics.gd index f5873d3a..ed2b183b 100644 --- a/Scenes/OverheadGraphics.gd +++ b/Scenes/OverheadGraphics.gd @@ -50,6 +50,12 @@ func overhead2d_update_rect_single_threaded(shapePositionArray): overheadTexData.create_from_image(overheadImgData, 0) emit_signal("column_graphics_completed") +const subtile3x3 = [ + Vector2(0,0), Vector2(1,0), Vector2(2,0), + Vector2(0,1), Vector2(1,1), Vector2(2,1), + Vector2(0,2), Vector2(1,2), Vector2(2,2) +] + func generate_pixel_data(pixData, shapePositionArray): var CODETIME_START = OS.get_ticks_msec() var width = M.xSize * 3 @@ -61,9 +67,9 @@ func generate_pixel_data(pixData, shapePositionArray): var basePosX = pos.x * 3 var basePosY = pos.y * 3 var slabID = oDataSlab.get_cellv(pos) - for i in range(9): # 3x3 subtiles - var x = basePosX + (i % 3) - var y = basePosY + (i / 3) + for offset in subtile3x3: # 3x3 subtiles + var x = basePosX + offset.x + var y = basePosY + offset.y var clmIndex = oDataClmPos.get_cell_clmpos(x, y) var cubeFace = oDataClm.get_top_cube_face(clmIndex, slabID) var pixelIndex = ((y * width) + x) * 3