From 70029ba7bde69f18d9625d47a6fb240c6d335778 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Mon, 5 Apr 2021 16:29:51 +0200 Subject: [PATCH] feat: Finish PNJ system Fixes #4 --- .../datas/gamedata/maps/sti/plain/test2.lua | 114 +++++++++++++++++- .../datas/gamedata/maps/sti/plain/test2.tmx | 17 ++- .../scenes/overworld/actors/gizmo.lua | 9 +- .../scenes/overworld/actors/init.lua | 2 + .../scenes/overworld/actors/pnj.lua | 50 ++++++++ 5 files changed, 181 insertions(+), 11 deletions(-) create mode 100644 sonic-radiance.love/scenes/overworld/actors/pnj.lua diff --git a/sonic-radiance.love/datas/gamedata/maps/sti/plain/test2.lua b/sonic-radiance.love/datas/gamedata/maps/sti/plain/test2.lua index 9c649f4..e7a46f5 100644 --- a/sonic-radiance.love/datas/gamedata/maps/sti/plain/test2.lua +++ b/sonic-radiance.love/datas/gamedata/maps/sti/plain/test2.lua @@ -8,8 +8,8 @@ return { height = 40, tilewidth = 16, tileheight = 16, - nextlayerid = 7, - nextobjectid = 19, + nextlayerid = 8, + nextobjectid = 21, properties = {}, tilesets = { { @@ -316,6 +316,42 @@ return { id = 102, type = "solid" }, + { + id = 108, + type = "solid" + }, + { + id = 109, + type = "solid" + }, + { + id = 110, + type = "solid" + }, + { + id = 116, + type = "solid" + }, + { + id = 117, + type = "solid" + }, + { + id = 118, + type = "solid" + }, + { + id = 124, + type = "solid" + }, + { + id = 125, + type = "solid" + }, + { + id = 126, + type = "solid" + }, { id = 129, type = "solid" @@ -323,6 +359,54 @@ return { { id = 130, type = "solid" + }, + { + id = 132, + type = "solid" + }, + { + id = 133, + type = "solid" + }, + { + id = 134, + type = "solid" + }, + { + id = 140, + type = "solid" + }, + { + id = 141, + type = "solid" + }, + { + id = 142, + type = "solid" + }, + { + id = 148, + type = "solid" + }, + { + id = 149, + type = "solid" + }, + { + id = 150, + type = "solid" + }, + { + id = 156, + type = "solid" + }, + { + id = 157, + type = "solid" + }, + { + id = 158, + type = "solid" } } } @@ -660,9 +744,21 @@ return { offsetx = 0, offsety = 0, properties = {}, + objects = {} + }, + { + type = "objectgroup", + draworder = "topdown", + id = 7, + name = "pnj", + visible = true, + opacity = 1, + offsetx = 0, + offsety = 0, + properties = {}, objects = { { - id = 16, + id = 20, name = "", type = "", shape = "rectangle", @@ -676,7 +772,17 @@ return { ["charDir"] = "right", ["charId"] = 5, ["charset"] = "perso", - ["isSolid"] = true + ["isSolid"] = true, + ["message1"] = "Sonic, you should stop doing stupid stuff and focus on defeating badnics.", + ["message2"] = "What did I say ? Stop fooling around.", + ["message4"] = "Seriously Sonic ?", + ["message5"] = "STOP. TALKING.", + ["message6"] = "You'll do the whole list of message, don't you ?", + ["message7"] = "...", + ["message8"] = "Well, so I'll give you some information. The story of this game will be shitty.", + ["message9"] = "Especially the name. Sonic Radiance ? Is it a friggin Fire Emblem game ?", + ["messageType"] = "list", + ["title"] = "Shadow" } } } diff --git a/sonic-radiance.love/datas/gamedata/maps/sti/plain/test2.tmx b/sonic-radiance.love/datas/gamedata/maps/sti/plain/test2.tmx index 0f95342..7aee811 100644 --- a/sonic-radiance.love/datas/gamedata/maps/sti/plain/test2.tmx +++ b/sonic-radiance.love/datas/gamedata/maps/sti/plain/test2.tmx @@ -1,5 +1,5 @@ - + @@ -110,13 +110,24 @@ - - + + + + + + + + + + + + + diff --git a/sonic-radiance.love/scenes/overworld/actors/gizmo.lua b/sonic-radiance.love/scenes/overworld/actors/gizmo.lua index 207017b..c355349 100644 --- a/sonic-radiance.love/scenes/overworld/actors/gizmo.lua +++ b/sonic-radiance.love/scenes/overworld/actors/gizmo.lua @@ -69,10 +69,11 @@ end function Gizmo:doAction() self:action() - if (self.properties.destroy ~= "none") then - if (self.properties.destroy == "forever") then - game.destroyedGizmo[self.uniqueId] = true - end + if (self.properties.destroy == "forever") then + game.destroyedGizmo[self.uniqueId] = true + self:destroy() + end + if (self.properties.destroy == "temp") then self:destroy() end end diff --git a/sonic-radiance.love/scenes/overworld/actors/init.lua b/sonic-radiance.love/scenes/overworld/actors/init.lua index 35ea3d6..4342783 100644 --- a/sonic-radiance.love/scenes/overworld/actors/init.lua +++ b/sonic-radiance.love/scenes/overworld/actors/init.lua @@ -9,6 +9,7 @@ Obj.ItemBox = require(cwd .. "itembox") Obj.RingBox = require(cwd .. "ringbox") Obj.Encounter = require(cwd .. "encounter") Obj.Teleporter = require(cwd .. "teleport") +Obj.PNJ = require(cwd .. "pnj") Obj.index = {} Obj.index["player"] = Obj.Player @@ -18,6 +19,7 @@ Obj.index["itembox"] = Obj.ItemBox Obj.index["ringbox"] = Obj.RingBox Obj.index["encounter"] = Obj.Encounter Obj.index["teleporter"] = Obj.Teleporter +Obj.index["pnj"] = Obj.PNJ Obj.collisions = {} Obj.collisions["wall"] = require(cwd .. "wall") diff --git a/sonic-radiance.love/scenes/overworld/actors/pnj.lua b/sonic-radiance.love/scenes/overworld/actors/pnj.lua new file mode 100644 index 0000000..578235e --- /dev/null +++ b/sonic-radiance.love/scenes/overworld/actors/pnj.lua @@ -0,0 +1,50 @@ +local cwd = (...):gsub('%.pnj$', '') .. "." +local Gizmo = require(cwd .. "gizmo") +local PNJ = Gizmo:extend() + +local overrides = { + ["isSolid"] = true, + ["destroy"] = "nope", + ["needButton"] = true, +} + +function PNJ:new(world, x, y) + PNJ.super.new(self, world, x, y, 16, 16, overrides) +end + +function PNJ:applyProperties() + PNJ.super.applyProperties(self) + self.messages = {} + for i = 1, 9, 1 do + local message = self.properties["message" .. i] + if (message ~= nil) then + table.insert(self.messages, message) + end + end + self.messageType = self.properties.messageType or "random" + self.currentMessage = 1 +end + +function PNJ:setMessage() + local message = self.messages[1] + if (self.messageType == "random") then + message = self.messages[math.random(#self.messages)] + elseif (self.messageType == "list") then + message = self.messages[self.currentMessage] + self.currentMessage = self.currentMessage + 1 + if (self.currentMessage > #self.messages) then + self.currentMessage = 1 + end + end + self.event = { + {"dialogBox", "", message, self.properties.title, ""}, + } +end + +function PNJ:action() + self:setMessage() + PNJ.super.action(self) +end + + +return PNJ \ No newline at end of file