feat: add interaction prompts

Fixes : #92
This commit is contained in:
Kazhnuz 2021-04-21 18:36:20 +02:00
parent 15bc5ae874
commit e50c9f6e54
8 changed files with 28 additions and 4 deletions

View file

@ -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()

View file

@ -8,6 +8,7 @@ local overrides = {
["charDir"] = "right",
["destroy"] = "forever",
["needButton"] = true,
["interactionName"] = "Take",
}
function ItemBox:new(world, x, y)

View file

@ -8,6 +8,7 @@ local overrides = {
["charDir"] = "down",
["destroy"] = "forever",
["needButton"] = true,
["interactionName"] = "Take",
}
function RingBox:new(world, x, y)

View file

@ -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()

View file

@ -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

View file

@ -5,6 +5,7 @@ local overrides = {
["isSolid"] = true,
["destroy"] = "nope",
["needButton"] = true,
["interactionName"] = "Talk",
}
function PNJ:new(world, x, y)

View file

@ -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()

View file

@ -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