From e50c9f6e54b335e800f631a23527c5a239da6212 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Wed, 21 Apr 2021 18:36:20 +0200 Subject: [PATCH] feat: add interaction prompts Fixes : #92 --- .../scenes/overworld/actors/gizmo.lua | 2 ++ .../scenes/overworld/actors/loot/itembox.lua | 1 + .../scenes/overworld/actors/loot/ringbox.lua | 1 + .../scenes/overworld/actors/player/init.lua | 9 +++++++++ .../overworld/actors/player/interactions.lua | 15 +++++++++++---- .../scenes/overworld/actors/pnj.lua | 1 + .../scenes/overworld/actors/teleport.lua | 1 + sonic-radiance.love/scenes/overworld/init.lua | 2 ++ 8 files changed, 28 insertions(+), 4 deletions(-) diff --git a/sonic-radiance.love/scenes/overworld/actors/gizmo.lua b/sonic-radiance.love/scenes/overworld/actors/gizmo.lua index a1df771..72420b4 100644 --- a/sonic-radiance.love/scenes/overworld/actors/gizmo.lua +++ b/sonic-radiance.love/scenes/overworld/actors/gizmo.lua @@ -12,6 +12,7 @@ function Gizmo:new(world, x, y, w, h, overrides) self.overrides = overrides self.drawDebugBox = false self.event = defaultEvent + self.interactionName = "Talk" end function Gizmo:getUniqueId() @@ -48,6 +49,7 @@ function Gizmo:applyProperties() if (game.destroyedGizmo[self.uniqueId] == true) then self:destroy() end + self.interactionName = self.properties.interactionName or self.interactionName end function Gizmo:setDefaultProperties() diff --git a/sonic-radiance.love/scenes/overworld/actors/loot/itembox.lua b/sonic-radiance.love/scenes/overworld/actors/loot/itembox.lua index 392a8c0..7c5f61b 100644 --- a/sonic-radiance.love/scenes/overworld/actors/loot/itembox.lua +++ b/sonic-radiance.love/scenes/overworld/actors/loot/itembox.lua @@ -8,6 +8,7 @@ local overrides = { ["charDir"] = "right", ["destroy"] = "forever", ["needButton"] = true, + ["interactionName"] = "Take", } function ItemBox:new(world, x, y) diff --git a/sonic-radiance.love/scenes/overworld/actors/loot/ringbox.lua b/sonic-radiance.love/scenes/overworld/actors/loot/ringbox.lua index 3bc3598..56980a2 100644 --- a/sonic-radiance.love/scenes/overworld/actors/loot/ringbox.lua +++ b/sonic-radiance.love/scenes/overworld/actors/loot/ringbox.lua @@ -8,6 +8,7 @@ local overrides = { ["charDir"] = "down", ["destroy"] = "forever", ["needButton"] = true, + ["interactionName"] = "Take", } function RingBox:new(world, x, y) diff --git a/sonic-radiance.love/scenes/overworld/actors/player/init.lua b/sonic-radiance.love/scenes/overworld/actors/player/init.lua index ba17c93..7a702ce 100644 --- a/sonic-radiance.love/scenes/overworld/actors/player/init.lua +++ b/sonic-radiance.love/scenes/overworld/actors/player/init.lua @@ -42,6 +42,7 @@ function Player:new(world, x, y, id) end function Player:updateStart(dt) + self.interactionName = "" self.tweens:update(dt) self:updateTerrain() self:updateActiveCharacter() @@ -122,6 +123,14 @@ end function Player:drawHUD(id) self:drawHealth((424 - self.scene:getEmblemsPosition()) - 48, 168) self:drawEmblems(self.scene:getEmblemsPosition(), 24) + if (not utils.string.isEmpty(self.interactionName)) then + local w = self.assets.fonts["small"]:getWidth(self.interactionName) + 16 + love.graphics.setColor(0,0,0,0.5) + local x, y = 424 - w + 4, 240 - 24 + love.graphics.rectangle("fill", x - w/2, y + 1, w, 15, 8, 8) + utils.graphics.resetColor() + self.assets.fonts["small"]:draw(self.interactionName, x, y, -1, "center") + end end function Player:draw() diff --git a/sonic-radiance.love/scenes/overworld/actors/player/interactions.lua b/sonic-radiance.love/scenes/overworld/actors/player/interactions.lua index e040968..6fa9ccd 100644 --- a/sonic-radiance.love/scenes/overworld/actors/player/interactions.lua +++ b/sonic-radiance.love/scenes/overworld/actors/player/interactions.lua @@ -24,6 +24,7 @@ function PlayerInteractions:initInteractions() self.lastPos = {} self.lastPos.x = self.x self.lastPos.y = self.y + self.interactionName = "" end function PlayerInteractions:updateInteraction() @@ -35,10 +36,12 @@ end function PlayerInteractions:collideWithGizmo(other) if (other.needButton) then + self.interactionName = other.interactionName if (self.keys["A"].isPressed) then other:doAction() self.haveCollided = true self.lastCollision = other.creationID + self.interactionName = "" end else if (self.lastCollision ~= other.creationID) then @@ -50,10 +53,14 @@ function PlayerInteractions:collideWithGizmo(other) end function PlayerInteractions:talkToGizmo(other) - if (self.keys["A"].isPressed and (self:faceRightDirection(other))) then - other:doAction() - self.haveCollided = true - self.lastCollision = other.creationID + if (self:faceRightDirection(other)) then + self.interactionName = other.interactionName + if (self.keys["A"].isPressed) then + other:doAction() + self.haveCollided = true + self.lastCollision = other.creationID + self.interactionName = "" + end end end diff --git a/sonic-radiance.love/scenes/overworld/actors/pnj.lua b/sonic-radiance.love/scenes/overworld/actors/pnj.lua index d1a013f..a158f28 100644 --- a/sonic-radiance.love/scenes/overworld/actors/pnj.lua +++ b/sonic-radiance.love/scenes/overworld/actors/pnj.lua @@ -5,6 +5,7 @@ local overrides = { ["isSolid"] = true, ["destroy"] = "nope", ["needButton"] = true, + ["interactionName"] = "Talk", } function PNJ:new(world, x, y) diff --git a/sonic-radiance.love/scenes/overworld/actors/teleport.lua b/sonic-radiance.love/scenes/overworld/actors/teleport.lua index fa081b6..87e06c0 100644 --- a/sonic-radiance.love/scenes/overworld/actors/teleport.lua +++ b/sonic-radiance.love/scenes/overworld/actors/teleport.lua @@ -3,6 +3,7 @@ local Teleporter = Gizmo:extend() function Teleporter:new(world, x, y, w, h) Teleporter.super.new(self, world, x, y, w, h, nil) + self.interactionName = "Enter" end function Teleporter:applyProperties() diff --git a/sonic-radiance.love/scenes/overworld/init.lua b/sonic-radiance.love/scenes/overworld/init.lua index 553a0f8..4eb54f3 100644 --- a/sonic-radiance.love/scenes/overworld/init.lua +++ b/sonic-radiance.love/scenes/overworld/init.lua @@ -40,6 +40,8 @@ function OverWorld:new(area, playerx, playery) self.charsetManager = CharsetManager(self) self.assets:batchImport("game.modules.gui.assets") self.assets:batchImport("scenes.overworld.assets") + self.assets.fonts["small"]:setLineHeight(16/18) + self.assets.fonts["small"]:setFilter("shadow") self.tweens = TweenManager(self) self.screens = screens