From 84bd3fa2774cd778997a8bd1f0149bd85ba92f70 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Tue, 13 Aug 2019 21:08:37 +0200 Subject: [PATCH] improvement: use gamecore integrated asset system as much as possible --- .../assets/backgrounds/borders.lua | 8 +++ .../assets/backgrounds/normaltile.lua | 8 +++ .../assets/backgrounds/specialtile.lua | 8 +++ .../assets/{gui => backgrounds}/tilemask.png | Bin .../assets/gui/cursor/ground.lua | 16 +++++ .../gui/{cursor.png => cursor/ground.png} | Bin .../gui/{cursor2.png => cursor/peak.png} | Bin .../assets/gui/fonts/hudnumbers.lua | 4 ++ .../assets/gui/{ => fonts}/hudnumbers.png | Bin .../assets/gui/fonts/hudsmallnumbers.lua | 4 ++ .../gui/{ => fonts}/hudsmallnumbers.png | Bin .../scenes/battlesystem/assets.lua | 25 +++++++ .../scenes/battlesystem/controller/actors.lua | 8 +-- .../battlesystem/controller/battlearena.lua | 65 +++++------------- .../scenes/battlesystem/controller/cursor.lua | 25 +------ .../scenes/battlesystem/controller/hud.lua | 24 ++----- .../scenes/battlesystem/controller/menu.lua | 1 - .../scenes/battlesystem/entities/base.lua | 2 +- .../scenes/battlesystem/init.lua | 2 + 19 files changed, 105 insertions(+), 95 deletions(-) create mode 100644 sonic-radiance.love/assets/backgrounds/borders.lua create mode 100644 sonic-radiance.love/assets/backgrounds/normaltile.lua create mode 100644 sonic-radiance.love/assets/backgrounds/specialtile.lua rename sonic-radiance.love/assets/{gui => backgrounds}/tilemask.png (100%) create mode 100644 sonic-radiance.love/assets/gui/cursor/ground.lua rename sonic-radiance.love/assets/gui/{cursor.png => cursor/ground.png} (100%) rename sonic-radiance.love/assets/gui/{cursor2.png => cursor/peak.png} (100%) create mode 100644 sonic-radiance.love/assets/gui/fonts/hudnumbers.lua rename sonic-radiance.love/assets/gui/{ => fonts}/hudnumbers.png (100%) create mode 100644 sonic-radiance.love/assets/gui/fonts/hudsmallnumbers.lua rename sonic-radiance.love/assets/gui/{ => fonts}/hudsmallnumbers.png (100%) create mode 100644 sonic-radiance.love/scenes/battlesystem/assets.lua diff --git a/sonic-radiance.love/assets/backgrounds/borders.lua b/sonic-radiance.love/assets/backgrounds/borders.lua new file mode 100644 index 0000000..7ec8cf0 --- /dev/null +++ b/sonic-radiance.love/assets/backgrounds/borders.lua @@ -0,0 +1,8 @@ +return { + metadata = { + width = 80, + height = 10, + ox = 0, + oy = 0, + } +} diff --git a/sonic-radiance.love/assets/backgrounds/normaltile.lua b/sonic-radiance.love/assets/backgrounds/normaltile.lua new file mode 100644 index 0000000..5d0744d --- /dev/null +++ b/sonic-radiance.love/assets/backgrounds/normaltile.lua @@ -0,0 +1,8 @@ +return { + metadata = { + width = 40, + height = 24, + ox = 0, + oy = 4, + } +} diff --git a/sonic-radiance.love/assets/backgrounds/specialtile.lua b/sonic-radiance.love/assets/backgrounds/specialtile.lua new file mode 100644 index 0000000..8d37c6e --- /dev/null +++ b/sonic-radiance.love/assets/backgrounds/specialtile.lua @@ -0,0 +1,8 @@ +return { + metadata = { + width = 40, + height = 26, + ox = 0, + oy = 6, + } +} diff --git a/sonic-radiance.love/assets/gui/tilemask.png b/sonic-radiance.love/assets/backgrounds/tilemask.png similarity index 100% rename from sonic-radiance.love/assets/gui/tilemask.png rename to sonic-radiance.love/assets/backgrounds/tilemask.png diff --git a/sonic-radiance.love/assets/gui/cursor/ground.lua b/sonic-radiance.love/assets/gui/cursor/ground.lua new file mode 100644 index 0000000..28e4e44 --- /dev/null +++ b/sonic-radiance.love/assets/gui/cursor/ground.lua @@ -0,0 +1,16 @@ +return { + metadata = { + width = 28, + height = 11, + defaultAnim = "default" + }, + animations = { + ["default"] = { + startAt = 1, + endAt = 3, + loop = 1, + speed = 3, + pauseAtEnd = false, + }, + } +} diff --git a/sonic-radiance.love/assets/gui/cursor.png b/sonic-radiance.love/assets/gui/cursor/ground.png similarity index 100% rename from sonic-radiance.love/assets/gui/cursor.png rename to sonic-radiance.love/assets/gui/cursor/ground.png diff --git a/sonic-radiance.love/assets/gui/cursor2.png b/sonic-radiance.love/assets/gui/cursor/peak.png similarity index 100% rename from sonic-radiance.love/assets/gui/cursor2.png rename to sonic-radiance.love/assets/gui/cursor/peak.png diff --git a/sonic-radiance.love/assets/gui/fonts/hudnumbers.lua b/sonic-radiance.love/assets/gui/fonts/hudnumbers.lua new file mode 100644 index 0000000..890f8a1 --- /dev/null +++ b/sonic-radiance.love/assets/gui/fonts/hudnumbers.lua @@ -0,0 +1,4 @@ +return { + glyphs = " 0123456789:/", + extraspacing = 1 +} diff --git a/sonic-radiance.love/assets/gui/hudnumbers.png b/sonic-radiance.love/assets/gui/fonts/hudnumbers.png similarity index 100% rename from sonic-radiance.love/assets/gui/hudnumbers.png rename to sonic-radiance.love/assets/gui/fonts/hudnumbers.png diff --git a/sonic-radiance.love/assets/gui/fonts/hudsmallnumbers.lua b/sonic-radiance.love/assets/gui/fonts/hudsmallnumbers.lua new file mode 100644 index 0000000..ef62441 --- /dev/null +++ b/sonic-radiance.love/assets/gui/fonts/hudsmallnumbers.lua @@ -0,0 +1,4 @@ +return { + glyphs = " 0123456789", + extraspacing = 0, +} diff --git a/sonic-radiance.love/assets/gui/hudsmallnumbers.png b/sonic-radiance.love/assets/gui/fonts/hudsmallnumbers.png similarity index 100% rename from sonic-radiance.love/assets/gui/hudsmallnumbers.png rename to sonic-radiance.love/assets/gui/fonts/hudsmallnumbers.png diff --git a/sonic-radiance.love/scenes/battlesystem/assets.lua b/sonic-radiance.love/scenes/battlesystem/assets.lua new file mode 100644 index 0000000..a6252d3 --- /dev/null +++ b/sonic-radiance.love/scenes/battlesystem/assets.lua @@ -0,0 +1,25 @@ +return { + ["tilesets"] = { + {"charicons", "assets/sprites/characters/charicons"}, + {"normaltiles", "assets/backgrounds/normaltile"}, + {"sptiles", "assets/backgrounds/specialtile"}, + {"borders", "assets/backgrounds/borders"}, + }, + ["sprites"] = { + {"cursorground", "assets/gui/cursor/ground"} + }, + ["textures"] = { + {"menucursor", "assets/gui/cursor-menulist.png"}, + {"statusbar", "assets/gui/status_bar.png"}, + {"cursorpeak", "assets/gui/cursor/peak.png"}, + {"actorsShadow", "assets/sprites/shadow.png"}, + {"emptytile", "assets/backgrounds/tilemask.png"} + }, + ["fonts"] = { + {"small", "assets/gui/fonts/PixelOperator.ttf", 16}, + }, + ["imagefonts"] = { + {"hudnbrs", "assets/gui/fonts/hudnumbers"}, + {"hudnbrs_small", "assets/gui/fonts/hudsmallnumbers"}, + } +} diff --git a/sonic-radiance.love/scenes/battlesystem/controller/actors.lua b/sonic-radiance.love/scenes/battlesystem/controller/actors.lua index 4e6738f..9318c3d 100644 --- a/sonic-radiance.love/scenes/battlesystem/controller/actors.lua +++ b/sonic-radiance.love/scenes/battlesystem/controller/actors.lua @@ -20,17 +20,12 @@ function ActorManager:new(controller) self.cursor = self.turns.current - self.controller.assets:addTileset("charicons", "assets/sprites/characters/charicons") for i, v in ipairs(game.characters.team) do self:addCharacter(POSITIONS[i].x, POSITIONS[i].y, v) end self:addEnnemy(10, 3, "motobug") self:addEnnemy(10, 5, "motobug") - - --print("entities") - self.cursorTexture = love.graphics.newImage("assets/gui/cursor-menulist.png") - end function ActorManager:generateActionList() @@ -135,8 +130,7 @@ function ActorManager:draw() for i,v in ipairs(self.actionlist) do v.actor:drawIcon(4 + (i-1)*(20), 6) end - - love.graphics.draw(self.cursorTexture, self.cursor * 20 - 6, 26, math.rad(-90), 1, 1, 4, 8) + self.controller.assets.images["menucursor"]:draw(self.cursor * 20 - 6, 26, math.rad(-90), 1, 1, 4, 8) end return ActorManager diff --git a/sonic-radiance.love/scenes/battlesystem/controller/battlearena.lua b/sonic-radiance.love/scenes/battlesystem/controller/battlearena.lua index 6d617b4..2539f76 100644 --- a/sonic-radiance.love/scenes/battlesystem/controller/battlearena.lua +++ b/sonic-radiance.love/scenes/battlesystem/controller/battlearena.lua @@ -16,6 +16,8 @@ _GROUND_Y = 90 function BattleArena:new(controller) self.controller = controller + self.assets = self.controller.assets + self:initArena() self.entities = {} @@ -34,41 +36,10 @@ function BattleArena:initArena(battlefile) self.datas.borders = 1 self.datas.terrains = EmptyArena - self:loadRessources() -end - -function BattleArena:loadRessources() - local backname = self.datas.background or "city" - local tileline = self.datas.tiles or 1 - local borderline = self.datas.borders or 1 - - self.textures = {} - self.textures.tiles = love.graphics.newImage("assets/backgrounds/normaltile.png") - self.textures.sptiles = love.graphics.newImage("assets/backgrounds/specialtile.png") - self.textures.back1 = love.graphics.newImage("assets/backgrounds/parallax/" .. backname .. "-back.png") - self.textures.back2 = love.graphics.newImage("assets/backgrounds/parallax/" .. backname .. "-fore.png") - self.textures.cliff = love.graphics.newImage("assets/backgrounds/parallax/" .. backname .. "-cliff.png") - self.textures.borders = love.graphics.newImage("assets/backgrounds/borders.png") - self.textures.shadow = love.graphics.newImage("assets/sprites/shadow.png") - - self.emptytile = love.graphics.newImage("assets/gui/tilemask.png") - - self.quads = {} - self.quads.tiles = {} - self.quads.sptiles = {} - - local w, h = self.textures.tiles:getDimensions() - self.quads.tiles[1] = love.graphics.newQuad( 0, tileline*24, 40, 24, w, h) - self.quads.tiles[2] = love.graphics.newQuad(40, tileline*24, 40, 24, w, h) - - local w, h = self.textures.sptiles:getDimensions() - local h2 = math.floor(h / 26) - for i=1, h2 do - self.quads.sptiles[i] = love.graphics.newQuad(0, (i-1)*26, 40, 26, w, h) - end - - local w, h = self.textures.borders:getDimensions() - self.quads.borders = love.graphics.newQuad(0, borderline*10, 80, 10, w, h) + local backpath = "assets/backgrounds/parallax/" .. self.datas.background + self.assets:addImage("back1", backpath .. "-back.png") + self.assets:addImage("back2", backpath .. "-fore.png") + self.assets:addImage("cliff", backpath .. "-cliff.png") end function BattleArena:gridToPixel(x, y, center) @@ -155,23 +126,24 @@ end function BattleArena:drawBackgrounds() local w, _ = core.screen:getDimensions() - local w2, h2 = self.textures.back1:getDimensions() + local w2, h2 = self.assets.images["back1"]:getDimensions() local imax = math.ceil(w / w2) + 1 for i=1, imax do - love.graphics.draw(self.textures.back1, (i-1)*w2, 0, 0, 1, 1) + self.assets.images["back1"]:draw((i-1)*w2, 0, 0, 1, 1) end - local w2, h2 = self.textures.back2:getDimensions() + local w2, h2 = self.assets.images["back2"]:getDimensions() local imax = math.ceil(w / w2) + 1 for i=1, imax do - love.graphics.draw(self.textures.back2, (i-1)*w2, _GROUND_Y-h2, 0, 1, 1) + self.assets.images["back2"]:draw((i-1)*w2, _GROUND_Y-h2, 0, 1, 1) end end function BattleArena:drawBorder() + local border = self.datas.borders + 1 for i=1, 7 do - love.graphics.draw(self.textures.borders, self.quads.borders, (i-1)*80, _GROUND_Y-10, 0, 1, 1) - love.graphics.draw(self.textures.borders, self.quads.borders, (i-1)*80, _GROUND_Y+20*7, 0, 1, 1) + self.assets.tileset["borders"]:drawTile(border, (i-1)*80, _GROUND_Y-10 , 0, 1, 1) + self.assets.tileset["borders"]:drawTile(border, (i-1)*80, _GROUND_Y+20*7, 0, 1, 1) end end @@ -194,10 +166,10 @@ function BattleArena:drawTerrains() else love.graphics.setColor(vhd, vhd, vhd, 1) end - self:drawTile(x, y - 4, terrain, k) + self:drawTile(x, y, terrain, k) else love.graphics.setColor(vd, vd, vd, 1) - self:drawTile(x, y - 4, 0, k) + self:drawTile(x, y, 0, k) end end end @@ -207,9 +179,10 @@ end function BattleArena:drawTile(x, y, type, variant) if type == 0 then - love.graphics.draw(self.textures.tiles, self.quads.tiles[variant], x, y) + local tiles = self.datas.tiles*2 + variant + self.assets.tileset["normaltiles"]:drawTile(tiles, x, y) else - love.graphics.draw(self.textures.sptiles, self.quads.sptiles[type], x, y-2) + self.assets.tileset["sptiles"]:drawTile(type, x, y) end end @@ -218,7 +191,7 @@ function BattleArena:showMask(ox, oy, shape, size, direction) for j=1,7 do if self:isInMask(i, j, ox, oy, shape, size, direction) then local x, y = self:gridToPixel(i, j) - love.graphics.draw(self.emptytile, x, y) + self.assets.images["emptytile"]:draw(x, y) end end end diff --git a/sonic-radiance.love/scenes/battlesystem/controller/cursor.lua b/sonic-radiance.love/scenes/battlesystem/controller/cursor.lua index 37154b0..5e614b6 100644 --- a/sonic-radiance.love/scenes/battlesystem/controller/cursor.lua +++ b/sonic-radiance.love/scenes/battlesystem/controller/cursor.lua @@ -16,26 +16,10 @@ function Cursor:new(controller) self.x = 1 self.y = 1 self.isActive = false - self.frame = 1 self.tx = 1 self.ty = 1 self.grid = EmptyGrid - - self:loadRessources() -end - -function Cursor:loadRessources() - - self.texture = love.graphics.newImage("assets/gui/cursor.png") - self.texture2 = love.graphics.newImage("assets/gui/cursor2.png") - - local w, h = self.texture:getDimensions() - self.sprite = {} - self.sprite[1] = love.graphics.newQuad(0, 0, 28, 11, w, h) - self.sprite[2] = love.graphics.newQuad(28, 0, 28, 11, w, h) - self.sprite[3] = love.graphics.newQuad(56, 0, 28, 11, w, h) - self.sprite[4] = love.graphics.newQuad(28, 0, 28, 11, w, h) end function Cursor:set(x, y) @@ -97,10 +81,6 @@ end function Cursor:update(dt) if (self.isActive) then - self.frame = self.frame + dt*4 - if (self.frame >= 4) then - self.frame = 1 - end local keys = self.controller.sources[1].keys if (keys["up"].isPressed) then @@ -144,9 +124,8 @@ function Cursor:drawBottom() if (self.isActive) then local x, y, frame x, y = self.controller.battlearena:gridToPixel(self.tx, self.ty, true) - frame = math.floor(self.frame) - love.graphics.draw(self.texture, self.sprite[frame], x, y, 0, 1, 1, 14, 6) + self.controller.assets.sprites["cursorground"]:drawAnimation(x, y, 0, 1, 1, 14, 6) end end @@ -157,7 +136,7 @@ function Cursor:drawTop() local x, y x, y = self.controller.battlearena:gridToPixel(self.tx, self.ty, true) - love.graphics.draw(self.texture2, x, y - 24, 0, 1, 1, 7, 26) + self.controller.assets.images["cursorpeak"]:draw(x, y - 24, 0, 1, 1, 7, 26) end end diff --git a/sonic-radiance.love/scenes/battlesystem/controller/hud.lua b/sonic-radiance.love/scenes/battlesystem/controller/hud.lua index 1dc90a7..fabbdb6 100644 --- a/sonic-radiance.love/scenes/battlesystem/controller/hud.lua +++ b/sonic-radiance.love/scenes/battlesystem/controller/hud.lua @@ -9,20 +9,11 @@ function BattleHUD:new(controller) end function BattleHUD:loadAssets() - self.hud1 = gui.newBorder(424, 30, 8) - - self.hud7 = love.graphics.newImage("assets/gui/status_bar.png") - - self.ring = love.graphics.newImage("assets/gui/ring.png") - - self.font = love.graphics.newImageFont("assets/gui/hudnumbers.png", " 0123456789:/", 1) - self.font2 = love.graphics.newImageFont("assets/gui/hudsmallnumbers.png", " 0123456789", 0) - - self.controller.assets:addTileset("lifeicon", "assets/sprites/characters/charicons") + self.frame = gui.newBorder(424, 30, 8) end function BattleHUD:destroy( ) - self.hud1:release( ) + self.frame:release( ) end function BattleHUD:update(dt) @@ -30,17 +21,16 @@ function BattleHUD:update(dt) end function BattleHUD:draw() - love.graphics.setFont( self.font ) + self.controller.assets.fonts["hudnbrs"]:set() self:drawFrame() --self.controller:resetFont( ) end function BattleHUD:drawFrame() - love.graphics.draw(self.hud1, 424, 20, 0, -1, -1) - love.graphics.draw(self.hud7, -8, 215) - love.graphics.draw(self.hud7, -8 + 128 + 24, 215) - love.graphics.draw(self.hud7, -8 + 256 + 48, 215) - --love.graphics.draw(self.hud2, 0, 200) + love.graphics.draw(self.frame, 424, 20, 0, -1, -1) + self.controller.assets.images["statusbar"]:draw(-8, 215) + self.controller.assets.images["statusbar"]:draw(-8 + 128 + 24, 215) + self.controller.assets.images["statusbar"]:draw(-8 + 256 + 48, 215) end return BattleHUD diff --git a/sonic-radiance.love/scenes/battlesystem/controller/menu.lua b/sonic-radiance.love/scenes/battlesystem/controller/menu.lua index 9fbed1c..846f88c 100644 --- a/sonic-radiance.love/scenes/battlesystem/controller/menu.lua +++ b/sonic-radiance.love/scenes/battlesystem/controller/menu.lua @@ -14,7 +14,6 @@ local MENU_ITEM_NUMBER = 6 function MenuConstructor:new( controller ) self.controller = controller - self.controller.assets:addFont("small", "assets/gui/fonts/PixelOperator.ttf", 16) end function MenuConstructor:reconstruct(character) diff --git a/sonic-radiance.love/scenes/battlesystem/entities/base.lua b/sonic-radiance.love/scenes/battlesystem/entities/base.lua index fcbd14c..4d626dd 100644 --- a/sonic-radiance.love/scenes/battlesystem/entities/base.lua +++ b/sonic-radiance.love/scenes/battlesystem/entities/base.lua @@ -55,7 +55,7 @@ end function BaseEntity:drawShadow() local x, y = self.controller.battlearena:gridToPixel(self.x, self.y, true) - love.graphics.draw(self.controller.battlearena.textures.shadow, x, y, 0, 1, 1, 12, 5) + self.controller.assets.images["actorsShadow"]:draw(x, y, 0, 1, 1, 12, 5) end return BaseEntity diff --git a/sonic-radiance.love/scenes/battlesystem/init.lua b/sonic-radiance.love/scenes/battlesystem/init.lua index afef77c..dd947cd 100644 --- a/sonic-radiance.love/scenes/battlesystem/init.lua +++ b/sonic-radiance.love/scenes/battlesystem/init.lua @@ -11,6 +11,8 @@ local MenuSystem = require "scenes.battlesystem.controller.menu" function BattleSystem:new() BattleSystem.super.new(self) + self.assets:batchImport("scenes.battlesystem.assets") + self:initManagers() self:register()