Weeeeee/modules/content_loader.lua

45 lines
2.2 KiB
Lua
Raw Normal View History

2022-03-02 18:36:52 +01:00
--import media
--import spritesheets
local spritesheets = {}
--load jsons
--load player jumping
spritesheets["player_jump"] = peachy.new("assets/images/spritesheets/player.json", love.graphics.newImage("assets/images/spritesheets/player.png"), "Jump")
--load player walking left
spritesheets["player_walk_left"] = peachy.new("assets/images/spritesheets/player.json", love.graphics.newImage("assets/images/spritesheets/player.png"), "Walk_left")
--load player walking right
spritesheets["player_walk_right"] = peachy.new("assets/images/spritesheets/player.json", love.graphics.newImage("assets/images/spritesheets/player.png"), "Walk_right")
--load player idle
spritesheets["player_idle"] = peachy.new("assets/images/spritesheets/player.json", love.graphics.newImage("assets/images/spritesheets/player.png"), "Idle")
--load player dying
spritesheets["player_die"] = peachy.new("assets/images/spritesheets/player.json", love.graphics.newImage("assets/images/spritesheets/player.png"), "Die")
--load player DEFAULT
spritesheets["player_default"] = peachy.new("assets/images/spritesheets/player.json", love.graphics.newImage("assets/images/spritesheets/player.png"), "Default")
--load sound effects
local sound_effects = {}
2022-03-02 20:31:33 +01:00
for i, file in ipairs(love.filesystem.getDirectoryItems("assets/audio/effects")) do
2022-03-02 18:36:52 +01:00
if file:find(".ogg") then
--load sound effects
local keyname = file:gsub(".ogg", "")
2022-03-02 20:31:33 +01:00
sound = love.audio.newSource("assets/audio/effects/"..file, "static")
2022-03-02 18:36:52 +01:00
sound_effects[keyname] = {}
sound_effects[keyname].volume = 1
sound_effects[keyname].timer = love.timer.getTime()
sound_effects[keyname].first_play = true
sound_effects[keyname].sound = sound
sound_effects[keyname].duration = sound:getDuration()
sound_effects[keyname].timer_min = sound:getDuration() * 2
sound_effects[keyname].play = function(self)
if (love.timer.getTime() - self.timer) >= self.timer_min or self.first_play then
self.timer = love.timer.getTime()
self.first_play = false
self.sound:setVolume(self.volume)
self.sound:play()
end
end
end
end
return {
spritesheets = spritesheets,
sound_effects = sound_effects,
}