From 8768e363347ac00ec61a7ef1df7a15130a559ffe Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sat, 1 Aug 2020 16:57:12 +0200 Subject: [PATCH] feat: add bases of the future overworld system --- .../scenes/debug/menu/init.lua | 1 + sonic-radiance.love/scenes/init.lua | 1 + .../scenes/overworld/actors/init.lua | 13 ++++++ .../scenes/overworld/actors/parent.lua | 13 ++++++ .../scenes/overworld/actors/player.lua | 35 ++++++++++++++ .../scenes/overworld/actors/wall.lua | 14 ++++++ sonic-radiance.love/scenes/overworld/init.lua | 46 +++++++++++++++---- .../scenes/overworld/world.lua | 11 +++++ 8 files changed, 126 insertions(+), 8 deletions(-) create mode 100644 sonic-radiance.love/scenes/overworld/actors/init.lua create mode 100644 sonic-radiance.love/scenes/overworld/actors/parent.lua create mode 100644 sonic-radiance.love/scenes/overworld/actors/player.lua create mode 100644 sonic-radiance.love/scenes/overworld/actors/wall.lua create mode 100644 sonic-radiance.love/scenes/overworld/world.lua diff --git a/sonic-radiance.love/scenes/debug/menu/init.lua b/sonic-radiance.love/scenes/debug/menu/init.lua index 5d11638..e7790e1 100644 --- a/sonic-radiance.love/scenes/debug/menu/init.lua +++ b/sonic-radiance.love/scenes/debug/menu/init.lua @@ -21,6 +21,7 @@ end function DebugMenu:buildOverworldMenu() self:addSubMenu("overworld", "BaseMenu", "Overworld") + menu.commons.SceneWidget(self, "overworld", scenes.overworld, "Launch Overworld") menu.commons.SubMenuWidget(self, "overworld", "BaseMenu", "Back") end diff --git a/sonic-radiance.love/scenes/init.lua b/sonic-radiance.love/scenes/init.lua index 0f611e0..d2e42d8 100644 --- a/sonic-radiance.love/scenes/init.lua +++ b/sonic-radiance.love/scenes/init.lua @@ -5,4 +5,5 @@ return { cbs = require "scenes.battlesystem", debug = require "scenes.debug", options = require "scenes.options", + overworld = require "scenes.overworld" } diff --git a/sonic-radiance.love/scenes/overworld/actors/init.lua b/sonic-radiance.love/scenes/overworld/actors/init.lua new file mode 100644 index 0000000..9d67a55 --- /dev/null +++ b/sonic-radiance.love/scenes/overworld/actors/init.lua @@ -0,0 +1,13 @@ +local Obj = {} + +-- On charge toutes les différentes types d'acteurs +local cwd = (...):gsub('%.init$', '') .. "." +Obj.Player = require(cwd .. "player") + +Obj.index = {} +Obj.index["player"] = Obj.Player + +Obj.collisions = {} +Obj.collisions["wall"] = require(cwd .. "wall") + +return Obj diff --git a/sonic-radiance.love/scenes/overworld/actors/parent.lua b/sonic-radiance.love/scenes/overworld/actors/parent.lua new file mode 100644 index 0000000..4a7e397 --- /dev/null +++ b/sonic-radiance.love/scenes/overworld/actors/parent.lua @@ -0,0 +1,13 @@ +local Base = require "core.modules.world.actors.actor2D" +local Parent = Base:extend() + +function Parent:new(world, type, x, y, w, h, isSolid) + self.scene = world.scene + Parent.super.new(self, world, type, x, y, w, h, isSolid) +end + +function Parent:draw() + love.graphics.rectangle("fill", math.floor(self.x), math.floor(self.y), self.w, self.h) +end + +return Parent diff --git a/sonic-radiance.love/scenes/overworld/actors/player.lua b/sonic-radiance.love/scenes/overworld/actors/player.lua new file mode 100644 index 0000000..9e80089 --- /dev/null +++ b/sonic-radiance.love/scenes/overworld/actors/player.lua @@ -0,0 +1,35 @@ +local cwd = (...):gsub('%.player$', '') .. "." +local Parent = require(cwd .. "parent") +local Player = Parent:extend() + +function Player:new(world, x, y, id) + Player.super.new(self, world, "player", x, y, 16, 16, true) + +end + +function Player:updateStart(dt) + self.xfrc, self.yfrc = 480*3, 480*3 + + if self.keys["up"].isDown then + self.ysp = -120 + end + if self.keys["down"].isDown then + self.ysp = 120 + end + if self.keys["left"].isDown then + self.xsp = -120 + end + if self.keys["right"].isDown then + self.xsp = 120 + end +end + +function Player:draw() + Player.super.draw(self) +end + +function Player:drawHUD(id) + love.graphics.print(id .. " test", 4, 4) +end + +return Player diff --git a/sonic-radiance.love/scenes/overworld/actors/wall.lua b/sonic-radiance.love/scenes/overworld/actors/wall.lua new file mode 100644 index 0000000..7e4f18e --- /dev/null +++ b/sonic-radiance.love/scenes/overworld/actors/wall.lua @@ -0,0 +1,14 @@ +local Base = require "core.modules.world.actors.actor2D" +local Wall = Base:extend() + +function Wall:new(world, x, y, w, h) + Wall.super.new(self, world, "wall", x, y, w, h, true) + self:setDebugColor(0,0,0) +end + +function Wall:draw() + --self:drawHitbox() + --utils.graphics.resetColor( ) +end + +return Wall diff --git a/sonic-radiance.love/scenes/overworld/init.lua b/sonic-radiance.love/scenes/overworld/init.lua index b42be75..7dff1d5 100644 --- a/sonic-radiance.love/scenes/overworld/init.lua +++ b/sonic-radiance.love/scenes/overworld/init.lua @@ -1,15 +1,45 @@ +-- scenes/moveplayer :: a basic player movement example + +--[[ + Copyright © 2019 Kazhnuz + + Permission is hereby granted, free of charge, to any person obtaining a copy of + this software and associated documentation files (the "Software"), to deal in + the Software without restriction, including without limitation the rights to + use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of + the Software, and to permit persons to whom the Software is furnished to do so, + subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS + FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR + COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER + IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN + CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +]] + local Scene = require "core.modules.scenes" -local OverWorld = Scene:extend() +local MovePlayer = Scene:extend() -function OverWorld:new() - OverWorld.super.new(self) +local World = require "scenes.overworld.world" + +function MovePlayer:new() + MovePlayer.super.new(self) + + World(self, "test", "map") + self.world:setPlayerNumber(1) + self.world:loadMap() end -function OverWorld:update(dt) -end - -function OverWorld:draw() +function MovePlayer:update(dt) end -return OverWorld +function MovePlayer:draw() + +end + +return MovePlayer diff --git a/sonic-radiance.love/scenes/overworld/world.lua b/sonic-radiance.love/scenes/overworld/world.lua new file mode 100644 index 0000000..c5f108c --- /dev/null +++ b/sonic-radiance.love/scenes/overworld/world.lua @@ -0,0 +1,11 @@ +local World = require "core.modules.world.world2D" +local RPGWorld = World:extend() +local objFile = "scenes.overworld.actors" +local mapFolder = "datas/gamedata/maps/sti/" + +function RPGWorld:new(scene, folder, map, playerx, playery) + local mapFile = mapFolder .. folder .. "/" .. map .. ".lua" + RPGWorld.super.new(self, scene, objFile, mapFile) +end + +return RPGWorld