Skip to content

Commit

Permalink
Cleaned up the "look around" functionality.
Browse files Browse the repository at this point in the history
  • Loading branch information
Trey Tomes committed Dec 21, 2023
1 parent bffa019 commit 1281dc9
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 11 deletions.
14 changes: 8 additions & 6 deletions src/factories/actions.ms
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
22 changes: 17 additions & 5 deletions src/factories/behaviors.ms
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions src/point.ms
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1281dc9

Please sign in to comment.