From 1281dc9319a28fa4f90196d6940ff2306fbc3abf Mon Sep 17 00:00:00 2001 From: Trey Tomes Date: Thu, 21 Dec 2023 15:29:35 -0600 Subject: [PATCH] Cleaned up the "look around" functionality. --- src/factories/actions.ms | 14 ++++++++------ src/factories/behaviors.ms | 22 +++++++++++++++++----- src/point.ms | 4 ++++ 3 files changed, 29 insertions(+), 11 deletions(-) diff --git a/src/factories/actions.ms b/src/factories/actions.ms index dd821db..415107a 100644 --- a/src/factories/actions.ms +++ b/src/factories/actions.ms @@ -192,12 +192,14 @@ examine = function(position) end if foundEntity = false - for e in entities - if e.examineOverride() then - foundEntity = true - break - end if - end for + if Service.world.player.position.subtract(position).length <= 1 then + for e in entities + if e.examineOverride() then + foundEntity = true + break + end if + end for + end if if not foundEntity then ui.examine(entities) diff --git a/src/factories/behaviors.ms b/src/factories/behaviors.ms index 02537f0..8500994 100644 --- a/src/factories/behaviors.ms +++ b/src/factories/behaviors.ms @@ -237,6 +237,7 @@ makeUserInput = function() return null // Cancel the action. end function + // TODO: Mismatch caused by different tile sizes. b.lookAround = function(entity, map) BLINK_SPEED = 300 / 1000 lastBlinkTime = time() @@ -253,14 +254,18 @@ makeUserInput = function() fg = Color.blue end if bg = Color.lerp(Color.black, Color.clear, 0.5) - ui.drawCell(Display.hud, renderOffset.x + pnt.x, renderOffset.y + pnt.y, fg, bg, "+") + + // ui.drawCell(Display.map, renderOffset.x + pnt.x, renderOffset.y + pnt.y, fg, bg, "+") + Display.map.setCell renderOffset.x + pnt.x, renderOffset.y + pnt.y, "+", fg, bg end function eraseCursor = function() - ui.drawCell(Display.hud, renderOffset.x + pnt.x, renderOffset.y + pnt.y, color.clear, color.clear, " ") + // ui.drawCell(Display.map, renderOffset.x + pnt.x, renderOffset.y + pnt.y, color.clear, color.clear, " ") + + Service.world.map.drawTile Display.map, pnt.x, pnt.y, renderOffset end function - descriptionBounds = rect.make(68 - 16, 26 - 3, 16, 3) + descriptionBounds = rect.make(constants.UI_DISPLAY_WIDTH - 16, constants.UI_DISPLAY_HEIGHT - 3, 16, 3) describe = function(map, pnt) if map.isVisible(pnt.x, pnt.y) then thing = map.getEntityAt(pnt) @@ -270,11 +275,13 @@ makeUserInput = function() text = "hidden" end if - ui.clearRect(Display.hud, descriptionBounds) + // ui.clearRect(Display.hud, descriptionBounds) width = math.max(16, text.len + 4) + clearBounds = rect.make(0, constants.UI_DISPLAY_HEIGHT - 3, constants.UI_DISPLAY_WIDTH, 3) + ui.clearRect(Display.hud, clearBounds, " ", color.clear, color.clear) - descriptionBounds = rect.make(68 - width, 26 - 3, width, 3) + descriptionBounds = rect.make(constants.UI_DISPLAY_WIDTH - width, constants.UI_DISPLAY_HEIGHT - 3, width, 3) ui.drawWindow(Display.hud, descriptionBounds) ui.drawCenteredText(Display.hud, descriptionBounds.left, descriptionBounds.right, descriptionBounds.top + 1, Color.yellow, Color.black, text) @@ -314,7 +321,12 @@ makeUserInput = function() showCursor = not showCursor lastBlinkTime = time() end if + + Service.world.map.clear(Display.map) + Service.world.map.draw_v1(Display.map, Service.world.player, renderOffset) + drawEntities(Display.map, Service.world.map, renderOffset) drawCursor() + Display.map.flip end while end function diff --git a/src/point.ms b/src/point.ms index a796a46..2177d68 100644 --- a/src/point.ms +++ b/src/point.ms @@ -42,6 +42,10 @@ Point.floor = function() return (new Point).init(floor(self.x), floor(self.y)) end function +Point.length = function() + return (self.x * self.x + self.y * self.y) ^ 0.5 +end function + zero = function() return (new Point).init(0, 0) end function