some upgrades

This commit is contained in:
Bruno Rybársky 2022-03-02 20:31:33 +01:00
parent f71db7a456
commit 022858330a
30 changed files with 45 additions and 33 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 MiB

Before

Width:  |  Height:  |  Size: 48 KiB

After

Width:  |  Height:  |  Size: 48 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 111 KiB

1
libs/hump Submodule

@ -0,0 +1 @@
Subproject commit 08937cc0ecf72d1a964a8de6cd552c5e136bf0d4

@ -4,12 +4,14 @@ peachy = require("libs/peachy")
--load player --load player
player = require("modules/player") player = require("modules/player")
--load hump camera
Camera = require("libs/hump/camera")
camera = Camera(player.x, player.y)
--load content_loader --load content_loader
local content_loader = require("modules/content_loader") local content_loader = require("modules/content_loader")
spritesheets = content_loader.spritesheets spritesheets = content_loader.spritesheets
sound_effects = content_loader.sound_effects sound_effects = content_loader.sound_effects
backgrounds = content_loader.backgrounds
music = content_loader.music
--load globals --load globals
local globals = require("modules/globals") local globals = require("modules/globals")
@ -25,10 +27,13 @@ update_mod = require("modules/update_callback")
local update_callback = update_mod.update local update_callback = update_mod.update
local updateinit = update_mod.updateinit local updateinit = update_mod.updateinit
drawerinit(spritesheets, player, game) drawerinit(spritesheets, player, game, camera)
updateinit(game) updateinit(game, camera)
player:init(sound_effects, spritesheets, game) player:init(sound_effects, spritesheets, game)
--play music for level
game:getcurlevel().music:play()
function love.draw() function love.draw()
draw_callback() draw_callback()
end end

@ -15,22 +15,13 @@ spritesheets["player_die"] = peachy.new("assets/images/spritesheets/player.json"
--load player DEFAULT --load player DEFAULT
spritesheets["player_default"] = peachy.new("assets/images/spritesheets/player.json", love.graphics.newImage("assets/images/spritesheets/player.png"), "Default") spritesheets["player_default"] = peachy.new("assets/images/spritesheets/player.json", love.graphics.newImage("assets/images/spritesheets/player.png"), "Default")
--load backgrounds
local backgrounds = {}
for i, file in ipairs(love.filesystem.getDirectoryItems("assets/images/backgrounds")) do
if file:find(".png") then
--load backgrounds
print(i)
backgrounds[i] = love.graphics.newImage("assets/images/backgrounds/"..file)
end
end
--load sound effects --load sound effects
local sound_effects = {} local sound_effects = {}
for i, file in ipairs(love.filesystem.getDirectoryItems("assets/sounds/effects")) do for i, file in ipairs(love.filesystem.getDirectoryItems("assets/audio/effects")) do
if file:find(".ogg") then if file:find(".ogg") then
--load sound effects --load sound effects
local keyname = file:gsub(".ogg", "") local keyname = file:gsub(".ogg", "")
sound = love.audio.newSource("assets/sounds/effects/"..file, "static") sound = love.audio.newSource("assets/audio/effects/"..file, "static")
sound_effects[keyname] = {} sound_effects[keyname] = {}
sound_effects[keyname].volume = 1 sound_effects[keyname].volume = 1
sound_effects[keyname].timer = love.timer.getTime() sound_effects[keyname].timer = love.timer.getTime()
@ -48,17 +39,7 @@ for i, file in ipairs(love.filesystem.getDirectoryItems("assets/sounds/effects")
end end
end end
end end
--load music
local music = {}
for i, file in ipairs(love.filesystem.getDirectoryItems("assets/sounds/music")) do
if file:find(".ogg") then
--load music
music[file:sub(1, -5)] = love.audio.newSource("assets/sounds/music/"..file, "stream")
end
end
return { return {
spritesheets = spritesheets, spritesheets = spritesheets,
backgrounds = backgrounds,
sound_effects = sound_effects, sound_effects = sound_effects,
music = music
} }

@ -1,16 +1,19 @@
local spritesheets = {} local spritesheets = {}
local player = {} local player = {}
local game = {} local game = {}
local camera = {}
function drawerinit(spritesheetst, playert, gamex) function drawerinit(spritesheetst, playert, gamex, camerax)
spritesheets = spritesheetst spritesheets = spritesheetst
player = playert player = playert
game = gamex game = gamex
camera = camerax
end end
local function draw() local function draw()
camera:attach()
--draw background --draw background
love.graphics.draw(backgrounds[game.level], 0, 0) love.graphics.draw(game.levels[game.level].background, 0, 0)
--draw player_animation --draw player_animation
player.animation:draw(player.x, player.y) player.animation:draw(player.x, player.y)
if player.state == "idle" then if player.state == "idle" then
@ -26,6 +29,7 @@ local function draw()
else else
spritesheets["player_default"]:draw(player.x, player.y) spritesheets["player_default"]:draw(player.x, player.y)
end end
camera:detach()
end end
return { return {
drawerinit = drawerinit, drawerinit = drawerinit,

@ -6,6 +6,19 @@ game.title = "Weeeeeeeee"
game.version = "0.0.1" game.version = "0.0.1"
game.fullscreen = false game.fullscreen = false
game.level = 1 game.level = 1
game.level_count = 1
game.levels = {}
game.getcurlevel = function(self)
return self.levels[self.level]
end
for i = 1, game.level_count, 1 do
game.levels[i] = {}
game.levels[i].background = love.graphics.newImage("assets/images/backgrounds/level".. i .."_hires.png")
game.levels[i].width = game.levels[i].background:getWidth()
game.levels[i].height = game.levels[i].background:getHeight()
game.levels[i].music = love.audio.newSource("assets/audio/music/track".. i ..".ogg", "static")
game.levels[i].music:setLooping(true)
end
return { return {
game = game game = game

@ -14,11 +14,13 @@ player.init = function(self, sound_effects, spritesheets, game)
self.sound_effects = sound_effects self.sound_effects = sound_effects
self.spritesheets = spritesheets self.spritesheets = spritesheets
self.game = game self.game = game
self.x = self.game.width / 2 + 8
self.y = self.game.height + 8
player.animation = spritesheets["player_idle"] player.animation = spritesheets["player_idle"]
end end
player.walk_right = function(self, dt) player.walk_right = function(self, dt)
if self.x < self.game.width - self.width and self.alive then if self.x < self.game:getcurlevel().width - self.width - self.game.width - 8 and self.alive then
self.x = self.x + self.speed * dt self.x = self.x + self.speed * dt
self.state = "walk_right" self.state = "walk_right"
self.direction = "right" self.direction = "right"
@ -26,7 +28,7 @@ player.walk_right = function(self, dt)
end end
end end
player.walk_left = function(self, dt) player.walk_left = function(self, dt)
if self.x > 0 and self.alive then if self.x > self.game.width / 2 + 8 and self.alive then
self.x = self.x - self.speed * dt self.x = self.x - self.speed * dt
self.state = "walk_left" self.state = "walk_left"
self.direction = "left" self.direction = "left"
@ -34,7 +36,7 @@ player.walk_left = function(self, dt)
end end
end end
player.jump = function(self, dt) player.jump = function(self, dt)
if self.y > 0 and self.alive then if self.y > self.game.height / 2 + 8 and self.alive then
self.y = self.y - self.jump_height * dt self.y = self.y - self.jump_height * dt
self.state = "jump" self.state = "jump"
self.animation = self.spritesheets["player_jump"] self.animation = self.spritesheets["player_jump"]
@ -42,7 +44,7 @@ player.jump = function(self, dt)
end end
end end
player.down = function(self, dt) player.down = function(self, dt)
if self.y < self.game.height - self.height and self.alive then if self.y < self.game:getcurlevel().height - self.height - self.game.height / 2 - 8 and self.alive then
self.y = self.y + self.jump_height * dt self.y = self.y + self.jump_height * dt
self.state = "jump" self.state = "jump"
self.animation = self.spritesheets["player_jump"] self.animation = self.spritesheets["player_jump"]

@ -1,7 +1,8 @@
local game = {} local game = {}
local camera = {}
local function updateinit(gamex) local function updateinit(gamex, camerax)
game = gamex game = gamex
camera = camerax
end end
local function update(dt) local function update(dt)
@ -49,7 +50,12 @@ local function update(dt)
player.spritesheets["player_die"]:setFrame(1) player.spritesheets["player_die"]:setFrame(1)
player:revive(dt) player:revive(dt)
end end
if key("x") then
print("x: \""..player.x.."\"; y: \""..player.y.."\"")
end
end end
local dx,dy = (player.x - camera.x) / 2, (player.y - camera.y) / 2
camera:move(dx, dy)
end end
return { return {
update = update, update = update,