improvement: use gamecore integrated asset system as much as possible

This commit is contained in:
Kazhnuz 2019-08-13 21:08:37 +02:00
parent b95f899c75
commit 84bd3fa277
19 changed files with 105 additions and 95 deletions

View file

@ -0,0 +1,8 @@
return {
metadata = {
width = 80,
height = 10,
ox = 0,
oy = 0,
}
}

View file

@ -0,0 +1,8 @@
return {
metadata = {
width = 40,
height = 24,
ox = 0,
oy = 4,
}
}

View file

@ -0,0 +1,8 @@
return {
metadata = {
width = 40,
height = 26,
ox = 0,
oy = 6,
}
}

View file

Before

Width:  |  Height:  |  Size: 222 B

After

Width:  |  Height:  |  Size: 222 B

View file

@ -0,0 +1,16 @@
return {
metadata = {
width = 28,
height = 11,
defaultAnim = "default"
},
animations = {
["default"] = {
startAt = 1,
endAt = 3,
loop = 1,
speed = 3,
pauseAtEnd = false,
},
}
}

View file

Before

Width:  |  Height:  |  Size: 582 B

After

Width:  |  Height:  |  Size: 582 B

View file

Before

Width:  |  Height:  |  Size: 457 B

After

Width:  |  Height:  |  Size: 457 B

View file

@ -0,0 +1,4 @@
return {
glyphs = " 0123456789:/",
extraspacing = 1
}

View file

Before

Width:  |  Height:  |  Size: 649 B

After

Width:  |  Height:  |  Size: 649 B

View file

@ -0,0 +1,4 @@
return {
glyphs = " 0123456789",
extraspacing = 0,
}

View file

Before

Width:  |  Height:  |  Size: 521 B

After

Width:  |  Height:  |  Size: 521 B

View file

@ -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"},
}
}

View file

@ -20,17 +20,12 @@ function ActorManager:new(controller)
self.cursor = self.turns.current self.cursor = self.turns.current
self.controller.assets:addTileset("charicons", "assets/sprites/characters/charicons")
for i, v in ipairs(game.characters.team) do for i, v in ipairs(game.characters.team) do
self:addCharacter(POSITIONS[i].x, POSITIONS[i].y, v) self:addCharacter(POSITIONS[i].x, POSITIONS[i].y, v)
end end
self:addEnnemy(10, 3, "motobug") self:addEnnemy(10, 3, "motobug")
self:addEnnemy(10, 5, "motobug") self:addEnnemy(10, 5, "motobug")
--print("entities")
self.cursorTexture = love.graphics.newImage("assets/gui/cursor-menulist.png")
end end
function ActorManager:generateActionList() function ActorManager:generateActionList()
@ -135,8 +130,7 @@ function ActorManager:draw()
for i,v in ipairs(self.actionlist) do for i,v in ipairs(self.actionlist) do
v.actor:drawIcon(4 + (i-1)*(20), 6) v.actor:drawIcon(4 + (i-1)*(20), 6)
end end
self.controller.assets.images["menucursor"]:draw(self.cursor * 20 - 6, 26, math.rad(-90), 1, 1, 4, 8)
love.graphics.draw(self.cursorTexture, self.cursor * 20 - 6, 26, math.rad(-90), 1, 1, 4, 8)
end end
return ActorManager return ActorManager

View file

@ -16,6 +16,8 @@ _GROUND_Y = 90
function BattleArena:new(controller) function BattleArena:new(controller)
self.controller = controller self.controller = controller
self.assets = self.controller.assets
self:initArena() self:initArena()
self.entities = {} self.entities = {}
@ -34,41 +36,10 @@ function BattleArena:initArena(battlefile)
self.datas.borders = 1 self.datas.borders = 1
self.datas.terrains = EmptyArena self.datas.terrains = EmptyArena
self:loadRessources() local backpath = "assets/backgrounds/parallax/" .. self.datas.background
end self.assets:addImage("back1", backpath .. "-back.png")
self.assets:addImage("back2", backpath .. "-fore.png")
function BattleArena:loadRessources() self.assets:addImage("cliff", backpath .. "-cliff.png")
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)
end end
function BattleArena:gridToPixel(x, y, center) function BattleArena:gridToPixel(x, y, center)
@ -155,23 +126,24 @@ end
function BattleArena:drawBackgrounds() function BattleArena:drawBackgrounds()
local w, _ = core.screen:getDimensions() 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 local imax = math.ceil(w / w2) + 1
for i=1, imax do 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 end
local w2, h2 = self.textures.back2:getDimensions() local w2, h2 = self.assets.images["back2"]:getDimensions()
local imax = math.ceil(w / w2) + 1 local imax = math.ceil(w / w2) + 1
for i=1, imax do 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
end end
function BattleArena:drawBorder() function BattleArena:drawBorder()
local border = self.datas.borders + 1
for i=1, 7 do for i=1, 7 do
love.graphics.draw(self.textures.borders, self.quads.borders, (i-1)*80, _GROUND_Y-10, 0, 1, 1) self.assets.tileset["borders"]:drawTile(border, (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+20*7, 0, 1, 1)
end end
end end
@ -194,10 +166,10 @@ function BattleArena:drawTerrains()
else else
love.graphics.setColor(vhd, vhd, vhd, 1) love.graphics.setColor(vhd, vhd, vhd, 1)
end end
self:drawTile(x, y - 4, terrain, k) self:drawTile(x, y, terrain, k)
else else
love.graphics.setColor(vd, vd, vd, 1) love.graphics.setColor(vd, vd, vd, 1)
self:drawTile(x, y - 4, 0, k) self:drawTile(x, y, 0, k)
end end
end end
end end
@ -207,9 +179,10 @@ end
function BattleArena:drawTile(x, y, type, variant) function BattleArena:drawTile(x, y, type, variant)
if type == 0 then 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 else
love.graphics.draw(self.textures.sptiles, self.quads.sptiles[type], x, y-2) self.assets.tileset["sptiles"]:drawTile(type, x, y)
end end
end end
@ -218,7 +191,7 @@ function BattleArena:showMask(ox, oy, shape, size, direction)
for j=1,7 do for j=1,7 do
if self:isInMask(i, j, ox, oy, shape, size, direction) then if self:isInMask(i, j, ox, oy, shape, size, direction) then
local x, y = self:gridToPixel(i, j) local x, y = self:gridToPixel(i, j)
love.graphics.draw(self.emptytile, x, y) self.assets.images["emptytile"]:draw(x, y)
end end
end end
end end

View file

@ -16,26 +16,10 @@ function Cursor:new(controller)
self.x = 1 self.x = 1
self.y = 1 self.y = 1
self.isActive = false self.isActive = false
self.frame = 1
self.tx = 1 self.tx = 1
self.ty = 1 self.ty = 1
self.grid = EmptyGrid 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 end
function Cursor:set(x, y) function Cursor:set(x, y)
@ -97,10 +81,6 @@ end
function Cursor:update(dt) function Cursor:update(dt)
if (self.isActive) then 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 local keys = self.controller.sources[1].keys
if (keys["up"].isPressed) then if (keys["up"].isPressed) then
@ -144,9 +124,8 @@ function Cursor:drawBottom()
if (self.isActive) then if (self.isActive) then
local x, y, frame local x, y, frame
x, y = self.controller.battlearena:gridToPixel(self.tx, self.ty, true) 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
end end
@ -157,7 +136,7 @@ function Cursor:drawTop()
local x, y local x, y
x, y = self.controller.battlearena:gridToPixel(self.tx, self.ty, true) 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
end end

View file

@ -9,20 +9,11 @@ function BattleHUD:new(controller)
end end
function BattleHUD:loadAssets() function BattleHUD:loadAssets()
self.hud1 = gui.newBorder(424, 30, 8) self.frame = 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")
end end
function BattleHUD:destroy( ) function BattleHUD:destroy( )
self.hud1:release( ) self.frame:release( )
end end
function BattleHUD:update(dt) function BattleHUD:update(dt)
@ -30,17 +21,16 @@ function BattleHUD:update(dt)
end end
function BattleHUD:draw() function BattleHUD:draw()
love.graphics.setFont( self.font ) self.controller.assets.fonts["hudnbrs"]:set()
self:drawFrame() self:drawFrame()
--self.controller:resetFont( ) --self.controller:resetFont( )
end end
function BattleHUD:drawFrame() function BattleHUD:drawFrame()
love.graphics.draw(self.hud1, 424, 20, 0, -1, -1) love.graphics.draw(self.frame, 424, 20, 0, -1, -1)
love.graphics.draw(self.hud7, -8, 215) self.controller.assets.images["statusbar"]:draw(-8, 215)
love.graphics.draw(self.hud7, -8 + 128 + 24, 215) self.controller.assets.images["statusbar"]:draw(-8 + 128 + 24, 215)
love.graphics.draw(self.hud7, -8 + 256 + 48, 215) self.controller.assets.images["statusbar"]:draw(-8 + 256 + 48, 215)
--love.graphics.draw(self.hud2, 0, 200)
end end
return BattleHUD return BattleHUD

View file

@ -14,7 +14,6 @@ local MENU_ITEM_NUMBER = 6
function MenuConstructor:new( controller ) function MenuConstructor:new( controller )
self.controller = controller self.controller = controller
self.controller.assets:addFont("small", "assets/gui/fonts/PixelOperator.ttf", 16)
end end
function MenuConstructor:reconstruct(character) function MenuConstructor:reconstruct(character)

View file

@ -55,7 +55,7 @@ end
function BaseEntity:drawShadow() function BaseEntity:drawShadow()
local x, y = self.controller.battlearena:gridToPixel(self.x, self.y, true) 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 end
return BaseEntity return BaseEntity

View file

@ -11,6 +11,8 @@ local MenuSystem = require "scenes.battlesystem.controller.menu"
function BattleSystem:new() function BattleSystem:new()
BattleSystem.super.new(self) BattleSystem.super.new(self)
self.assets:batchImport("scenes.battlesystem.assets")
self:initManagers() self:initManagers()
self:register() self:register()