Peak stability, fixed all the song positions and note positions
This commit is contained in:
parent
0736af3a5f
commit
4f6082b037
@ -181,8 +181,7 @@ local function state(songName, songDifficulty)
|
||||
|
||||
local currentTime = socket.gettime()
|
||||
|
||||
actualElapsed = (currentTime - startTime) * 1000 - pauseTime
|
||||
elapsed = actualElapsed > 100 and actualElapsed - 100 or 0
|
||||
elapsed = (currentTime - startTime) * 1000 - pauseTime
|
||||
|
||||
conductor.songPosition = elapsed
|
||||
|
||||
@ -224,18 +223,6 @@ local function state(songName, songDifficulty)
|
||||
|
||||
myTypes.updateSprites(dt)
|
||||
|
||||
for index, note in next, notes do
|
||||
if note.position - conductor.songPosition < 0 then
|
||||
if note.mustPress then
|
||||
note:destroy()
|
||||
miss:stop()
|
||||
miss:play()
|
||||
characters.bf:PlayAnimation("sing"..directions[note.direction].."miss")
|
||||
notes[index] = nil
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
for name, character in next, characters do
|
||||
if name ~= "gf" and character.sprite.animation ~= "idle" and character.sprite.ended then
|
||||
character:PlayAnimation("idle")
|
||||
@ -255,9 +242,12 @@ local function state(songName, songDifficulty)
|
||||
|
||||
for index, note in next, notes do
|
||||
if note.spawned then
|
||||
note.sprite.position = myTypes.Vector2(400 + 65 * (note.direction - 1), settings.Downscroll and 430 - (note.position-elapsed-100) or note.position - elapsed-100)
|
||||
note.sprite.position = myTypes.Vector2(400 + 65 * (note.direction - 1), settings.Downscroll and 430 - (note.position-elapsed) or note.position - elapsed)
|
||||
if note.position - elapsed < -150 then
|
||||
note:destroy()
|
||||
miss:stop()
|
||||
miss:play()
|
||||
characters.bf:PlayAnimation("sing"..directions[note.direction].."miss")
|
||||
notes[index] = nil
|
||||
end
|
||||
else
|
||||
@ -371,5 +361,4 @@ local function state(songName, songDifficulty)
|
||||
return state
|
||||
end
|
||||
|
||||
|
||||
return state
|
||||
return state -- vscode doesnt like this but idrc
|
@ -13,6 +13,8 @@ Vector2.__index = Vector2
|
||||
local Sprite = {}
|
||||
Sprite.__index = Sprite
|
||||
|
||||
local cachedQuads = {}
|
||||
|
||||
local Sprites = {}
|
||||
local Rects = {}
|
||||
|
||||
@ -41,59 +43,77 @@ function module.Vector2(x, y)
|
||||
end
|
||||
|
||||
function module.Sprite(image, sheet)
|
||||
local sheetString = files.read_file(sheet)
|
||||
if not cachedQuads[sheet] then
|
||||
local sheetString = files.read_file(sheet)
|
||||
|
||||
|
||||
if not sheetString then
|
||||
error("Failed to load", sheet)
|
||||
end
|
||||
|
||||
local atlas = json.parse(sheetString).TextureAtlas.SubTexture
|
||||
|
||||
local animations = {}
|
||||
|
||||
local quads = {}
|
||||
|
||||
local newSprite = setmetatable({
|
||||
animations = animations,
|
||||
image = love.graphics.newImage(image),
|
||||
quads = quads,
|
||||
elapsed = 0,
|
||||
fps = 10,
|
||||
animation = nil,
|
||||
frame = 0,
|
||||
position = module.Vector2(200, 100), -- changeable
|
||||
looping = false,
|
||||
extraOffset = module.Vector2(0,0),
|
||||
rect = false
|
||||
}, Sprite)
|
||||
|
||||
for index, sprite in next, atlas do
|
||||
local x = sprite._x
|
||||
local y = sprite._y
|
||||
local width = sprite._width
|
||||
local height = sprite._height
|
||||
local frameX = sprite._frameX
|
||||
local frameY = sprite._frameY
|
||||
local frameW = sprite._frameWidth
|
||||
local frameH = sprite._frameHeight
|
||||
|
||||
local name = sprite._name
|
||||
|
||||
local num = tonumber(string.sub(name, name:len() - 3, name:len()))
|
||||
|
||||
if not quads[name:sub(0, name:len() - 4)] then
|
||||
quads[name:sub(0, name:len() - 4)] = {}
|
||||
if not sheetString then
|
||||
error("Failed to load", sheet)
|
||||
end
|
||||
|
||||
quads[name:sub(0, name:len() - 4)][num] = {quad = love.graphics.newQuad(x, y, width, height, newSprite.image), offset = module.Vector2(frameX or 0, frameY or 0), resize = module.Vector2(.8,1)}
|
||||
local atlas = json.parse(sheetString).TextureAtlas.SubTexture
|
||||
|
||||
local quads = {}
|
||||
|
||||
local newSprite = setmetatable({
|
||||
image = love.graphics.newImage(image),
|
||||
quads = quads,
|
||||
elapsed = 0,
|
||||
fps = 10,
|
||||
animation = nil,
|
||||
frame = 0,
|
||||
position = module.Vector2(200, 100), -- changeable
|
||||
looping = false,
|
||||
extraOffset = module.Vector2(0,0),
|
||||
rect = false
|
||||
}, Sprite)
|
||||
|
||||
for index, sprite in next, atlas do
|
||||
local x = sprite._x
|
||||
local y = sprite._y
|
||||
local width = sprite._width
|
||||
local height = sprite._height
|
||||
local frameX = sprite._frameX
|
||||
local frameY = sprite._frameY
|
||||
local frameW = sprite._frameWidth
|
||||
local frameH = sprite._frameHeight
|
||||
|
||||
local name = sprite._name
|
||||
|
||||
local num = tonumber(string.sub(name, name:len() - 3, name:len()))
|
||||
|
||||
if not quads[name:sub(0, name:len() - 4)] then
|
||||
quads[name:sub(0, name:len() - 4)] = {}
|
||||
end
|
||||
|
||||
quads[name:sub(0, name:len() - 4)][num] = {quad = love.graphics.newQuad(x, y, width, height, newSprite.image), offset = module.Vector2(frameX or 0, frameY or 0), resize = module.Vector2(.8,1)}
|
||||
end
|
||||
|
||||
newSprite.quads = quads
|
||||
cachedQuads[sheet] = quads
|
||||
|
||||
Sprites[#Sprites+1] = newSprite
|
||||
|
||||
return newSprite
|
||||
else
|
||||
|
||||
local newSprite = setmetatable({
|
||||
image = love.graphics.newImage(image),
|
||||
quads = cachedQuads[sheet],
|
||||
elapsed = 0,
|
||||
fps = 10,
|
||||
animation = nil,
|
||||
frame = 0,
|
||||
position = module.Vector2(200, 100), -- changeable
|
||||
looping = false,
|
||||
extraOffset = module.Vector2(0,0),
|
||||
rect = false
|
||||
}, Sprite)
|
||||
|
||||
Sprites[#Sprites+1] = newSprite
|
||||
|
||||
return newSprite
|
||||
end
|
||||
|
||||
newSprite.quads = quads
|
||||
|
||||
Sprites[#Sprites+1] = newSprite
|
||||
|
||||
return newSprite
|
||||
end
|
||||
|
||||
function Sprite:PlayAnimation(name, fps, loop)
|
||||
@ -162,98 +182,110 @@ end
|
||||
|
||||
function module.drawSprites()
|
||||
for index, sprite in next, Sprites do
|
||||
if not sprite.animation or not sprite.quads or not sprite.quads[sprite.animation] then goto continue end -- For some reason OG LUA doesnt have continue
|
||||
-- So im forced to use goto ::continue:: since it goes straight to the last point of the cycle
|
||||
if sprite.animation and sprite.quads and sprite.quads[sprite.animation] then
|
||||
local quad = sprite.quads[sprite.animation][sprite.frame] or sprite.quads[sprite.animation][0]
|
||||
if quad then
|
||||
if quad.offset.x == 0 and quad.offset.y == 0 and sprite.quads[sprite.animation][0].offset.x ~= 0 then
|
||||
quad.offset.x = sprite.quads[sprite.animation][0].offset.x
|
||||
quad.offset.y = sprite.quads[sprite.animation][0].offset.y
|
||||
end
|
||||
if sprite.flipX and not quad.flipped then
|
||||
quad.flipped = true
|
||||
quad.offset.x = -quad.offset.x
|
||||
end
|
||||
|
||||
local quad = sprite.quads[sprite.animation][sprite.frame] or sprite.quads[sprite.animation][0]
|
||||
if not quad then goto continue end
|
||||
local cameraOffset = sprite.ui and module.Vector2() or module.cameraPosition or module.Vector2()
|
||||
|
||||
if quad.offset.x == 0 and quad.offset.y == 0 and sprite.quads[sprite.animation][0].offset.x ~= 0 then
|
||||
quad.offset.x = sprite.quads[sprite.animation][0].offset.x
|
||||
quad.offset.y = sprite.quads[sprite.animation][0].offset.y
|
||||
love.graphics.draw(sprite.image, quad.quad, (sprite.position.x + (sprite.position.x - quad.offset.x - sprite.extraOffset.x) + cameraOffset.x), (sprite.position.y + (sprite.position.y - quad.offset.y - sprite.extraOffset.y) + cameraOffset.y), 0, quad.resize.x * (sprite.flipX and -1 or 1), quad.resize.y)
|
||||
end
|
||||
end
|
||||
if sprite.flipX and not quad.flipped then
|
||||
quad.flipped = true
|
||||
quad.offset.x = -quad.offset.x
|
||||
end
|
||||
|
||||
local cameraOffset = sprite.ui and module.Vector2() or module.cameraPosition or module.Vector2()
|
||||
|
||||
love.graphics.draw(sprite.image, quad.quad, (sprite.position.x + (sprite.position.x - quad.offset.x - sprite.extraOffset.x) + cameraOffset.x), (sprite.position.y + (sprite.position.y - quad.offset.y - sprite.extraOffset.y) + cameraOffset.y), 0, quad.resize.x * (sprite.flipX and -1 or 1), quad.resize.y)
|
||||
::continue:: -- Point itself
|
||||
end
|
||||
|
||||
|
||||
for index, rect in next, Rects do
|
||||
if not rect.animation then goto continue end
|
||||
if rect.animation then
|
||||
local quad = rect.quads[rect.animation][0]
|
||||
if rect.flipX and not quad.flipped then
|
||||
quad.flipped = true
|
||||
quad.offset.x = -quad.offset.x
|
||||
end
|
||||
|
||||
local quad = rect.quads[rect.animation][0]
|
||||
local cameraOffset = rect.ui and module.Vector2() or module.cameraPosition or module.Vector2()
|
||||
|
||||
if rect.flipX and not quad.flipped then
|
||||
quad.flipped = true
|
||||
quad.offset.x = -quad.offset.x
|
||||
love.graphics.draw(rect.image, quad.quad, (rect.position.x + (rect.position.x - quad.offset.x - rect.extraOffset.x) + cameraOffset.x), (rect.position.y + (rect.position.y - quad.offset.y - rect.extraOffset.y) + cameraOffset.y), 0, quad.resize.x * (rect.flipX and -1 or 1), quad.resize.y)
|
||||
end
|
||||
|
||||
local cameraOffset = rect.ui and module.Vector2() or module.cameraPosition or module.Vector2()
|
||||
|
||||
love.graphics.draw(rect.image, quad.quad, (rect.position.x + (rect.position.x - quad.offset.x - rect.extraOffset.x) + cameraOffset.x), (rect.position.y + (rect.position.y - quad.offset.y - rect.extraOffset.y) + cameraOffset.y), 0, quad.resize.x * (rect.flipX and -1 or 1), quad.resize.y)
|
||||
::continue::
|
||||
end
|
||||
end
|
||||
|
||||
function module.Rect(image, sheet)
|
||||
local sheetString = files.read_file(sheet)
|
||||
|
||||
|
||||
if not sheetString then
|
||||
error("Failed to load", sheet)
|
||||
end
|
||||
|
||||
local atlas = json.parse(sheetString).TextureAtlas.SubTexture
|
||||
|
||||
local animations = {}
|
||||
|
||||
local quads = {}
|
||||
|
||||
local newSprite = setmetatable({
|
||||
animations = animations,
|
||||
image = love.graphics.newImage(image),
|
||||
quads = quads,
|
||||
elapsed = 0,
|
||||
fps = 10,
|
||||
animation = nil,
|
||||
frame = 1,
|
||||
position = module.Vector2(200, 100), -- changeable
|
||||
looping = false,
|
||||
extraOffset = module.Vector2(0,0),
|
||||
rect = true
|
||||
}, Sprite)
|
||||
|
||||
for index, sprite in next, atlas do
|
||||
local x = sprite._x
|
||||
local y = sprite._y
|
||||
local width = sprite._width
|
||||
local height = sprite._height
|
||||
local frameX = sprite._frameX
|
||||
local frameY = sprite._frameY
|
||||
local frameW = sprite._frameWidth
|
||||
local frameH = sprite._frameHeight
|
||||
|
||||
local name = sprite._name
|
||||
|
||||
local num = tonumber(string.sub(name, name:len() - 3, name:len()))
|
||||
|
||||
if not quads[name:sub(0, name:len() - 4)] then
|
||||
quads[name:sub(0, name:len() - 4)] = {}
|
||||
if not cachedQuads[sheet] then
|
||||
local sheetString = files.read_file(sheet)
|
||||
|
||||
if not sheetString then
|
||||
error("Failed to load", sheet)
|
||||
end
|
||||
|
||||
quads[name:sub(0, name:len() - 4)][num] = {quad = love.graphics.newQuad(x, y, width, height, newSprite.image), offset = module.Vector2(frameX or 0, frameY or 0), resize = module.Vector2(.8,1)}
|
||||
local atlas = json.parse(sheetString).TextureAtlas.SubTexture
|
||||
|
||||
local quads = {}
|
||||
|
||||
local newSprite = setmetatable({
|
||||
image = love.graphics.newImage(image),
|
||||
quads = quads,
|
||||
elapsed = 0,
|
||||
fps = 10,
|
||||
animation = nil,
|
||||
frame = 0,
|
||||
position = module.Vector2(200, 100), -- changeable
|
||||
looping = false,
|
||||
extraOffset = module.Vector2(0,0),
|
||||
rect = false
|
||||
}, Sprite)
|
||||
|
||||
for index, sprite in next, atlas do
|
||||
local x = sprite._x
|
||||
local y = sprite._y
|
||||
local width = sprite._width
|
||||
local height = sprite._height
|
||||
local frameX = sprite._frameX
|
||||
local frameY = sprite._frameY
|
||||
local frameW = sprite._frameWidth
|
||||
local frameH = sprite._frameHeight
|
||||
|
||||
local name = sprite._name
|
||||
|
||||
local num = tonumber(string.sub(name, name:len() - 3, name:len()))
|
||||
|
||||
if not quads[name:sub(0, name:len() - 4)] then
|
||||
quads[name:sub(0, name:len() - 4)] = {}
|
||||
end
|
||||
|
||||
quads[name:sub(0, name:len() - 4)][num] = {quad = love.graphics.newQuad(x, y, width, height, newSprite.image), offset = module.Vector2(frameX or 0, frameY or 0), resize = module.Vector2(.8,1)}
|
||||
end
|
||||
|
||||
newSprite.quads = quads
|
||||
cachedQuads[sheet] = quads
|
||||
|
||||
Rects[#Rects+1] = newSprite
|
||||
|
||||
return newSprite
|
||||
else
|
||||
local newSprite = setmetatable({
|
||||
image = love.graphics.newImage(image),
|
||||
quads = cachedQuads[sheet],
|
||||
elapsed = 0,
|
||||
fps = 10,
|
||||
animation = nil,
|
||||
frame = 0,
|
||||
position = module.Vector2(200, 100), -- changeable
|
||||
looping = false,
|
||||
extraOffset = module.Vector2(0,0),
|
||||
rect = false
|
||||
}, Sprite)
|
||||
|
||||
Sprites[#Sprites+1] = newSprite
|
||||
|
||||
return newSprite
|
||||
end
|
||||
|
||||
newSprite.quads = quads
|
||||
|
||||
Rects[#Rects+1] = newSprite
|
||||
|
||||
return newSprite
|
||||
end
|
||||
|
||||
function Sprite:Frame(name, frame)
|
||||
|
Reference in New Issue
Block a user