src: remove the old assets manager
This commit is contained in:
parent
35a44a0640
commit
443aeb82ea
|
@ -24,7 +24,6 @@ datas = require "datas"
|
|||
|
||||
utils = require "libs.loveutils"
|
||||
menus = require "modules.menus"
|
||||
assets = require "modules.assets"
|
||||
|
||||
scenes = require "scenes"
|
||||
|
||||
|
@ -40,7 +39,6 @@ function love.load() -- On charge la scene de départ (pour l'instant le menu, b
|
|||
game = Game()
|
||||
game.pigmanager:addPig("cochon")
|
||||
|
||||
assets:init()
|
||||
scenes.MainMenu()
|
||||
end
|
||||
|
||||
|
|
|
@ -1,43 +0,0 @@
|
|||
Font = Object:extend()
|
||||
|
||||
function Assets:clearFonts()
|
||||
self.fonts = {}
|
||||
end
|
||||
|
||||
function Font:new(filename, glyphs, extraspacing)
|
||||
local filename = "assets/fonts/" .. filename .. ".png"
|
||||
self.font = love.graphics.newImageFont(filename, glyphs, extraspacing)
|
||||
end
|
||||
|
||||
function Font:set()
|
||||
love.graphics.setFont(self.font)
|
||||
end
|
||||
|
||||
function Assets:addFont(filename, glyphs, extraspacing)
|
||||
local font = Font(filename, glyphs, extraspacing)
|
||||
self.fonts[filename] = font
|
||||
end
|
||||
|
||||
function Assets:addFontFromFile(filename)
|
||||
local data = require("assets/fonts/" .. filename .. ".lua")
|
||||
local font = Font(data.filename, data.glyphs, data.extraspacing)
|
||||
self.fonts[filename] = font
|
||||
end
|
||||
|
||||
function Assets:getFont(filename)
|
||||
return self.fonts[filename]
|
||||
end
|
||||
|
||||
function Font:getHeight()
|
||||
local font = self.font
|
||||
return font:getHeight()
|
||||
end
|
||||
|
||||
function Font:getWidth(string)
|
||||
local width = self.font:getWidth(string)
|
||||
return width
|
||||
end
|
||||
|
||||
function Font:setLineHeight(height)
|
||||
self.font:setLineHeight(height)
|
||||
end
|
|
@ -1,91 +0,0 @@
|
|||
local e =
|
||||
{
|
||||
class = 'assets',
|
||||
}
|
||||
e.__index = e
|
||||
e.new = function()
|
||||
local t =
|
||||
{
|
||||
sprites = {},
|
||||
background = nil,
|
||||
fonts = {}
|
||||
}
|
||||
return setmetatable(t,e)
|
||||
end
|
||||
|
||||
-- Ceci est un test
|
||||
|
||||
Assets = Object:extend()
|
||||
|
||||
require "modules.assets.sprites"
|
||||
require "modules.assets.fonts"
|
||||
require "modules.assets.textbox"
|
||||
require "modules.assets.progressbar"
|
||||
|
||||
function Assets:new()
|
||||
self.sprites = {}
|
||||
self.sfx = {}
|
||||
self.fonts = {}
|
||||
self.textbox = {}
|
||||
self.progressbar= {}
|
||||
self.music = nil
|
||||
self.background = nil
|
||||
self:clearFonts()
|
||||
end
|
||||
|
||||
function Assets:init()
|
||||
self.sprites = {}
|
||||
self.sfx = {}
|
||||
self.fonts = {}
|
||||
self.textbox = {}
|
||||
self.progressbar= {}
|
||||
self.music = nil
|
||||
self.background = nil
|
||||
self:clearFonts()
|
||||
end
|
||||
|
||||
function Assets:update(dt)
|
||||
self:animationsUpdate(dt)
|
||||
end
|
||||
|
||||
function Assets:newSFX(filename)
|
||||
self.sfx[filename] = love.audio.newSource( "assets/sfx/" .. filename .. ".wav", "static" )
|
||||
end
|
||||
|
||||
function Assets:clearSFX()
|
||||
love.audio.stop( )
|
||||
self.sfx = {}
|
||||
end
|
||||
|
||||
function Assets:setMusic(filename)
|
||||
love.audio.stop( )
|
||||
self.music = love.audio.newSource( "assets/music/" .. filename, "stream" )
|
||||
end
|
||||
|
||||
function Assets:playSFX(filename)
|
||||
if not (self.sfx[filename] == nil) then
|
||||
self.sfx[filename]:stop()
|
||||
love.audio.play( self.sfx[filename] )
|
||||
end
|
||||
end
|
||||
|
||||
function Assets:playMusic()
|
||||
if not (self.music == nil) then
|
||||
love.audio.play(self.music)
|
||||
end
|
||||
end
|
||||
|
||||
function Assets:silence()
|
||||
love.audio.stop()
|
||||
end
|
||||
|
||||
function Assets:setBackground(background)
|
||||
self.background = love.graphics.newImage("assets/backgrounds/".. background ..".png")
|
||||
end
|
||||
|
||||
function Assets:drawBackground()
|
||||
utils.graphics.resetColor()
|
||||
love.graphics.draw(self.background, 0, 0)
|
||||
end
|
||||
|
||||
return Assets
|
|
@ -1,69 +0,0 @@
|
|||
ProgressBar = Object:extend()
|
||||
|
||||
function Assets:addProgressBar(sprite, outerfont, innerfont)
|
||||
self.progressbar[sprite] = ProgressBar(sprite, outerfont, innerfont)
|
||||
end
|
||||
|
||||
function Assets:clearProgressBar()
|
||||
self.progressbar = {}
|
||||
end
|
||||
|
||||
function ProgressBar:new(sprite, outerfont, innerfont)
|
||||
self.sprite = Sprite(sprite, 1, 12, "gui/progressbar/")
|
||||
self.sprite:newAnimation(1, 1, 0.8)
|
||||
self.sprite:newAnimation(2, 1, 0.8)
|
||||
self.sprite:newAnimation(3, 1, 0.8)
|
||||
self.sprite:newAnimation(4, 1, 0.8)
|
||||
self.sprite:newAnimation(5, 1, 0.8)
|
||||
|
||||
self.backsprite = Sprite("backbar", 1, 12, "gui/progressbar/")
|
||||
self.backsprite:newAnimation(1, 1, 0.8)
|
||||
self.backsprite:newAnimation(2, 1, 0.8)
|
||||
self.backsprite:newAnimation(3, 1, 0.8)
|
||||
self.backsprite:newAnimation(4, 1, 0.8)
|
||||
self.backsprite:newAnimation(5, 1, 0.8)
|
||||
|
||||
self.outerfont = assets.fonts[outerfont]
|
||||
self.innerfont = assets.fonts[innerfont]
|
||||
end
|
||||
|
||||
function ProgressBar:draw(label, x, y, w, stat, innerlabel)
|
||||
utils.graphics.resetColor()
|
||||
|
||||
local wLabel = self.outerfont:getWidth(label)
|
||||
local hLabel = self.outerfont:getHeight()
|
||||
love.graphics.printf(label, x - wLabel, y + 7, wLabel, "right", 0, 1, 1, 0, hLabel/2)
|
||||
|
||||
|
||||
local innerlabel = innerlabel or ""
|
||||
local stat = math.min(1, stat)
|
||||
local w2 = math.ceil(w * stat)
|
||||
for i=1, w do
|
||||
if (i == 1) then
|
||||
self.backsprite:draw(1, x+i, y)
|
||||
elseif (i == 2) then
|
||||
self.backsprite:draw(2, x+i, y)
|
||||
elseif (i == (w-1)) then
|
||||
self.backsprite:draw(4, x+i, y)
|
||||
elseif (i == (w)) then
|
||||
self.backsprite:draw(5, x+i, y)
|
||||
else
|
||||
self.backsprite:draw(3, x+i, y)
|
||||
end
|
||||
end
|
||||
|
||||
for i=1, w2 do
|
||||
if (i == 1) then
|
||||
self.sprite:draw(1, x+i, y)
|
||||
elseif (i == 2) then
|
||||
self.sprite:draw(2, x+i, y)
|
||||
elseif (i == (w2-1)) then
|
||||
self.sprite:draw(4, x+i, y)
|
||||
elseif (i == (w2)) then
|
||||
self.sprite:draw(5, x+i, y)
|
||||
else
|
||||
self.sprite:draw(3, x+i, y)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
|
@ -1,74 +0,0 @@
|
|||
Sprite = Object:extend()
|
||||
|
||||
function Assets:addSprite(name, width, height, subfolder)
|
||||
self.sprites[name] = Sprite(name, width, height, subfolder)
|
||||
end
|
||||
|
||||
function Assets:clearSprites()
|
||||
self.sprites = {}
|
||||
end
|
||||
|
||||
function Assets:animationsUpdate(dt)
|
||||
for i,v in pairs(self.sprites) do
|
||||
v:update(dt)
|
||||
end
|
||||
end
|
||||
|
||||
function Sprite:new(name, width, heigth, subfolder)
|
||||
self.name = name
|
||||
self.subfolder = subfolder or ""
|
||||
self.image = love.graphics.newImage( 'assets/sprites/' .. self.subfolder .. self.name .. '.png')
|
||||
self.width = width
|
||||
self.height = height
|
||||
self.grid = anim8.newGrid(width, heigth,
|
||||
self.image:getWidth(), self.image:getHeight())
|
||||
self.animations = {}
|
||||
end
|
||||
|
||||
function Sprite:newAnimation(x, y, speed, onLoop)
|
||||
local onLoop = onLoop or nil
|
||||
table.insert( self.animations,
|
||||
anim8.newAnimation(self.grid(x,y), speed, onLoop) )
|
||||
end
|
||||
|
||||
function Sprite:update(dt)
|
||||
for i=1, #self.animations do
|
||||
self.animations[i]:update(dt)
|
||||
end
|
||||
end
|
||||
|
||||
function Sprite:resetAnimation(id)
|
||||
self.animations[id]:gotoFrame(1)
|
||||
self.animations[id]:resume()
|
||||
end
|
||||
|
||||
function Sprite:cloneAnimation(id)
|
||||
local clone = self.animations[id]:clone()
|
||||
|
||||
return clone
|
||||
end
|
||||
|
||||
function Sprite:draw(id, x, y, angle, sx, sy, ox, oy, kx, ky)
|
||||
local angle = angle or 0
|
||||
local sx = sx or 1
|
||||
local sy = sy or 1
|
||||
local ox = ox or 0
|
||||
local ox = ox or 0
|
||||
local kx = kx or 0
|
||||
local kx = kx or 0
|
||||
local angle = math.rad(angle)
|
||||
x, y = utils.math.floorCoord(x, y)
|
||||
self.animations[id]:draw(self.image, x, y, angle, sx, sy, ox, oy, kx, ky)
|
||||
end
|
||||
|
||||
function Sprite:drawIcon(id, x, y, angle, sx, sy, ox, oy, kx, ky)
|
||||
love.graphics.setColor(0, 0, 0)
|
||||
self:draw(id, x+1, y+1, angle, sx, sy, ox, oy, kx, ky)
|
||||
utils.graphics.resetColor()
|
||||
self:draw(id, x, y, angle, sx, sy, ox, oy, kx, ky)
|
||||
end
|
||||
|
||||
|
||||
function Sprite:getAnimationDuration(id)
|
||||
return self.animations[id].intervals[#self.animations[id].intervals]
|
||||
end
|
|
@ -1,57 +0,0 @@
|
|||
TextBox = Object:extend()
|
||||
|
||||
function Assets:addTextBox(sprite)
|
||||
self.textbox[sprite] = TextBox(sprite)
|
||||
end
|
||||
|
||||
function Assets:clearTextBox()
|
||||
self.textbox = {}
|
||||
end
|
||||
|
||||
|
||||
function TextBox:new(sprite)
|
||||
self.sprite = Sprite(sprite, 8, 8, "gui/textbox/")
|
||||
self.sprite:newAnimation(1, 1, 0.8)
|
||||
self.sprite:newAnimation(2, 1, 0.8)
|
||||
self.sprite:newAnimation(3, 1, 0.8)
|
||||
|
||||
self.sprite:newAnimation(1, 2, 0.8)
|
||||
self.sprite:newAnimation(2, 2, 0.8)
|
||||
self.sprite:newAnimation(3, 2, 0.8)
|
||||
|
||||
self.sprite:newAnimation(1, 3, 0.8)
|
||||
self.sprite:newAnimation(2, 3, 0.8)
|
||||
self.sprite:newAnimation(3, 3, 0.8)
|
||||
end
|
||||
|
||||
function TextBox:draw(x, y, w, h)
|
||||
utils.graphics.resetColor()
|
||||
local w = math.floor(w / 8) * 8
|
||||
local h = math.floor(h / 8) * 8
|
||||
local x1, x2, y1, y2
|
||||
x1 = x - 8
|
||||
x2 = x + w
|
||||
y1 = y - 8
|
||||
y2 = y + h
|
||||
|
||||
self.sprite:draw(1, x1, y1)
|
||||
self.sprite:draw(7, x1, y2)
|
||||
self.sprite:draw(3, x2, y1)
|
||||
self.sprite:draw(9, x2, y2)
|
||||
local w2, h2
|
||||
w2 = math.floor((w) / 8)
|
||||
h2 = math.floor((h) / 8)
|
||||
for i=1, w2 do
|
||||
self.sprite:draw(2, x1+i*8, y1)
|
||||
self.sprite:draw(8, x1+i*8, y2)
|
||||
for j=1,h2 do
|
||||
self.sprite:draw(5, x1+i*8, y1+j*8)
|
||||
end
|
||||
end
|
||||
|
||||
for i=1, h2 do
|
||||
self.sprite:draw(4, x1, y1+i*8)
|
||||
self.sprite:draw(6, x2, y1+i*8)
|
||||
end
|
||||
|
||||
end
|
|
@ -65,8 +65,6 @@ function Level:loadSounds()
|
|||
end
|
||||
|
||||
function Level:loadSprites()
|
||||
assets:clearSprites()
|
||||
|
||||
self.assets:addSprite("coin", "assets/sprites/items/coin")
|
||||
self.assets:addSprite("coin5", "assets/sprites/items/coin5")
|
||||
self.assets:addSprite("coin10", "assets/sprites/items/coin10")
|
||||
|
@ -114,7 +112,6 @@ function Level:update(dt)
|
|||
if (self.pause == false) then
|
||||
self.playermanager:update(dt)
|
||||
self.world:update(dt)
|
||||
assets:update(dt)
|
||||
self.camera:update(dt)
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue