added draw functions for setScale, rehandled scale, animations now have multiple frame times (this breaks some minor stuff)

This commit is contained in:
lustlion 2022-02-24 04:15:35 +01:00
parent 00cec59351
commit 54f6a46428
19 changed files with 139 additions and 53 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 140 B

After

Width:  |  Height:  |  Size: 146 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 146 B

After

Width:  |  Height:  |  Size: 120 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 146 B

After

Width:  |  Height:  |  Size: 143 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 120 B

After

Width:  |  Height:  |  Size: 137 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 137 B

After

Width:  |  Height:  |  Size: 120 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 143 B

After

Width:  |  Height:  |  Size: 146 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 203 B

After

Width:  |  Height:  |  Size: 310 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 198 B

After

Width:  |  Height:  |  Size: 295 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 201 B

After

Width:  |  Height:  |  Size: 304 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 199 B

After

Width:  |  Height:  |  Size: 291 B

View File

@ -5,7 +5,6 @@ function Animation:New(anim_data)
o.path = anim_data.path o.path = anim_data.path
o.frames = anim_data.frames o.frames = anim_data.frames
o.speed = anim_data.speed
o.imgs = anim_data.imgs o.imgs = anim_data.imgs
o.subframe = 0 o.subframe = 0
o.frame = 1 o.frame = 1
@ -26,8 +25,8 @@ end
-- to manually handle what frame -- to manually handle what frame
function Animation:DrawFrame(frame, x, y, rotate, sx, sy) function Animation:DrawFrame(frame, x, y, rotate, sx, sy)
if frame > self.frames then if frame > #self.frames then
frame = self.frames frame = #self.frames
end end
local x = x or 0 local x = x or 0
local y = y or 0 local y = y or 0
@ -45,18 +44,18 @@ end
-- to linearly animate -- to linearly animate
function Animation:Animate() function Animation:Animate()
if self.speed ~= 0 then if self.frames[self.frame] ~= 0 then
-- try to animate -- try to animate
self.subframe = self.subframe + current_dt self.subframe = self.subframe + current_dt
if self.subframe > self.speed then if self.subframe > self.frames[self.frame] then
self.frame = self.frame + 1 self.subframe = self.subframe - self.frames[self.frame]
self.subframe = self.subframe - self.speed self.frame = self.frame + 1
end end
-- cycle -- cycle
if self.frame >= self.frames+1 then if self.frame >= #self.frames+1 then
self.frame = self.frame - self.frames self.frame = self.frame - #self.frames
end end
end end
end end

View File

@ -14,7 +14,7 @@ end
function Canvas:Recreate() function Canvas:Recreate()
self.canvas:release() self.canvas:release()
self = Canvas:New() self = Canvas:New(self.name)
end end
function Canvas:Reset() function Canvas:Reset()

View File

@ -1,4 +1,6 @@
function DebugUI() function DebugUI()
love.graphics.setScale()
local mouse_x, mouse_y = love.mouse.getPosition() local mouse_x, mouse_y = love.mouse.getPosition()
for _, light in pairs(LoadedObjects.Lights) do for _, light in pairs(LoadedObjects.Lights) do
love.graphics.print(light.pos.x,light.pos.x,light.pos.y) love.graphics.print(light.pos.x,light.pos.x,light.pos.y)
@ -24,11 +26,13 @@ function DebugUI()
end end
function DebugColisions() function DebugColisions()
love.graphics.setScale(game.scale)
-- DrawColisionTable() -- DrawColisionTable()
LoadedObjects.DrawCollisions() LoadedObjects.DrawCollisions()
end end
function DebugEntities() function DebugEntities()
love.graphics.setScale(game.scale)
for _, particle in pairs(LoadedParticles) do for _, particle in pairs(LoadedParticles) do
particle:Debug() particle:Debug()
end end

6
code/draw.lua Normal file
View File

@ -0,0 +1,6 @@
function love.graphics.setScale(scale_x, scale_y)
local scale_x = scale_x or 1
local scale_y = scale_y or scale_x
love.graphics.origin()
love.graphics.scale(scale_x,scale_y)
end

View File

@ -87,7 +87,7 @@ function GameDraw()
GameworldDrawEnd() GameworldDrawEnd()
-- hud -- hud
textScale = 0.5 textScale = 1
-- debug -- debug
if debug then DebugUI() end if debug then DebugUI() end

View File

@ -5,7 +5,7 @@ function GameworldDrawPrepare()
Canvas.Darkness.Recreate() Canvas.Darkness.Recreate()
end end
pcr, pcg, pcb, pca = love.graphics.getColor() pcr, pcg, pcb, pca = love.graphics.getColor()
love.graphics.scale(game.scale,game.scale) love.graphics.setScale(game.scale,game.scale)
love.graphics.setColor(1,1,1,1) love.graphics.setColor(1,1,1,1)
end end

View File

@ -1,8 +1,9 @@
function MenuDraw(menu) function MenuDraw(menu)
local font = love.graphics.getFont() local font = love.graphics.getFont()
love.graphics.setFont(LocaleFont) love.graphics.setFont(LocaleFont)
-- Set scale to 1
love.graphics.scale(0.5,0.5) -- reset scale
love.graphics.setScale()
if menu == "pause" then if menu == "pause" then
MenuDrawPauseScreen() MenuDrawPauseScreen()
@ -13,8 +14,7 @@ function MenuDraw(menu)
for _, element in pairs(UIElement) do for _, element in pairs(UIElement) do
element:Draw() element:Draw()
end end
-- Reset scale
love.graphics.scale(2,2)
love.graphics.setFont(font) love.graphics.setFont(font)
end end

View File

@ -8,6 +8,7 @@ require "code/locale"
-- support functions -- support functions
require "code/math" require "code/math"
require "code/draw"
require "code/hex" require "code/hex"
require "code/in_out" require "code/in_out"

View File

@ -5,118 +5,194 @@ animation = {}
animation.cursed_book = {} animation.cursed_book = {}
animation.cursed_book.attack_loop = { animation.cursed_book.attack_loop = {
path = "assets/entities/cursed_book/attack_loop", path = "assets/entities/cursed_book/attack_loop",
frames = 1, frames = {
speed = 0 0
}
} }
animation.cursed_book.attack_transition = { animation.cursed_book.attack_transition = {
path = "assets/entities/cursed_book/attack_transition", path = "assets/entities/cursed_book/attack_transition",
frames = 5, frames = {
speed = 1/16 1/16,
1/16,
1/16,
1/16,
1/16
}
} }
animation.cursed_book.flying = { animation.cursed_book.flying = {
path = "assets/entities/cursed_book/flying", path = "assets/entities/cursed_book/flying",
frames = 11, frames = {
speed = 1/16 2/16,
2/16,
1/16,
1/16,
1/16,
1/16,
1/16,
2/16
}
} }
animation.cursed_book.spawn = { animation.cursed_book.spawn = {
path = "assets/entities/cursed_book/spawn", path = "assets/entities/cursed_book/spawn",
frames = 5, frames = {
speed = 0 0,
0,
0,
0,
0
}
} }
-- particles -- particles
animation.particle = {} animation.particle = {}
animation.particle.simple = { animation.particle.simple = {
path = "assets/entities/particle/simple", path = "assets/entities/particle/simple",
frames = 4, frames = {
speed = 1/4 1/4,
1/4,
1/4,
1/4
}
} }
-- fairy -- fairy
animation.fairy = {} animation.fairy = {}
animation.fairy.flying = { animation.fairy.flying = {
path = "assets/entities/fairy/flying", path = "assets/entities/fairy/flying",
frames = 2, frames = {
speed = 1/30 1/32,
1/32
}
} }
-- decoration -- decoration
animation.decoration = {} animation.decoration = {}
animation.decoration.candelabra = { animation.decoration.candelabra = {
path = "assets/entities/decoration/candelabra", path = "assets/entities/decoration/candelabra",
frames = 8, frames = {
speed = 1/6 1/8,
1/8,
1/8,
1/8,
1/8,
1/8,
1/8,
1/8
}
} }
-- kupo -- kupo
animation.kupo = {} animation.kupo = {}
animation.kupo.body = { animation.kupo.body = {
path = "assets/entities/kupo/kupo", path = "assets/entities/kupo/kupo",
frames = 4, frames = {
speed = 1/8 1/8,
1/8,
1/8,
1/8
}
} }
animation.kupo.bow = { animation.kupo.bow = {
path = "assets/entities/kupo/kupo_bow", path = "assets/entities/kupo/kupo_bow",
frames = 6, frames = {
speed = 1/10 1/10,
1/10,
1/10,
1/10,
1/10,
1/10
}
} }
animation.kupo.arrow = { animation.kupo.arrow = {
path = "assets/entities/kupo/kupo_arrow", path = "assets/entities/kupo/kupo_arrow",
frames = 1, frames = {
speed = 0 0
}
} }
-- moth mask -- moth mask
animation.moth_mask = {} animation.moth_mask = {}
animation.moth_mask.idle = { animation.moth_mask.idle = {
path = "assets/entities/nancy/moth_mask/idle", path = "assets/entities/nancy/moth_mask/idle",
frames = 4, frames = {
speed = 1/8 1/8,
1/8,
1/8,
1/8
}
} }
animation.moth_mask.run = { animation.moth_mask.run = {
path = "assets/entities/nancy/moth_mask/run", path = "assets/entities/nancy/moth_mask/run",
frames = 6, frames = {
speed = 1/8 1/8,
1/8,
1/8,
1/8,
1/8,
1/8
}
} }
animation.moth_mask.fall = { animation.moth_mask.fall = {
path = "assets/entities/nancy/moth_mask/fall", path = "assets/entities/nancy/moth_mask/fall",
frames = 3, frames = {
speed = 1/8 1/8,
1/8,
1/8
}
} }
animation.moth_mask.jump = { animation.moth_mask.jump = {
path = "assets/entities/nancy/moth_mask/jump", path = "assets/entities/nancy/moth_mask/jump",
frames = 3, frames = {
speed = 1/8 1/8,
1/8,
1/8
}
} }
-- nancy -- nancy
animation.nancy = {} animation.nancy = {}
animation.nancy.idle = { animation.nancy.idle = {
path = "assets/entities/nancy/idle", path = "assets/entities/nancy/idle",
frames = 4, frames = {
speed = 1/8 1/8,
1/8,
1/8,
1/8
}
} }
animation.nancy.run = { animation.nancy.run = {
path = "assets/entities/nancy/run", path = "assets/entities/nancy/run",
frames = 6, frames = {
speed = 1/8 1/8,
1/8,
1/8,
1/8,
1/8,
1/8
}
} }
animation.nancy.fall = { animation.nancy.fall = {
path = "assets/entities/nancy/fall", path = "assets/entities/nancy/fall",
frames = 3, frames = {
speed = 1/8 1/8,
1/8,
1/8
}
} }
animation.nancy.jump = { animation.nancy.jump = {
path = "assets/entities/nancy/jump", path = "assets/entities/nancy/jump",
frames = 3, frames = {
speed = 1/8 1/8,
1/8,
1/8
}
} }
-- animation initializer -- animation initializer
for _, object in pairs(animation) do for _, object in pairs(animation) do
for _, anim in pairs(object) do for _, anim in pairs(object) do
anim.imgs = {} anim.imgs = {}
for i = 1, anim.frames do for i = 1, #anim.frames do
table.insert(anim.imgs,love.graphics.newImage(anim.path..tostring(i)..".png")) table.insert(anim.imgs,love.graphics.newImage(anim.path..tostring(i)..".png"))
end end
end end