diff --git a/main.lua b/main.lua index d87565e..fa08638 100644 --- a/main.lua +++ b/main.lua @@ -53,13 +53,14 @@ local playing = false local characters = {} local stage = json.parse(files.read_file("stages/stage.json")) +local unspawnedNotes = {} local notes = {} local directions = { - "singLEFT", - "singDOWN", - "singUP", - "singRIGHT" + "LEFT", + "DOWN", + "UP", + "RIGHT" } function love.load() @@ -70,10 +71,17 @@ function love.load() for index, section in next, chart.notes do for index, note in next, section.sectionNotes do local newNote = myTypes.note(note, section.mustHitSection) - table.insert(notes, newNote) + table.insert(unspawnedNotes, newNote) end end + for i = 0, 3 do + local receptor = myTypes.Rect("sprites/NOTE_assets.png", "sprites/NOTE_assets.json") + receptor:Frame("arrow"..directions[i+1], 0) + + receptor.position = myTypes.Vector2(100 + (65 * i), 0) + end + inst:play() voices:play() @@ -86,9 +94,10 @@ local function checkNote(dir) for index, note in next, notes do if note.position - conductor.songPosition < 200 then if note.mustPress and not note.pressed and note.direction == dir then - characters.bf:PlayAnimation(directions[note.direction]) + characters.bf:PlayAnimation("sing"..directions[note.direction]) note.pressed = true table.remove(notes, index) + note:destroy() end end end @@ -109,12 +118,7 @@ function love.update(dt) step = conductor:getStepRounded(elapsed) beat = conductor:getBeatRounded(elapsed) - if step ~= oldStep then - print("Step", step) - end - if beat ~= oldBeat then - print("Beat", beat) if beat % 2 == 0 then -- gf:PlayAnimation("BF NOTE LEFT", 30, false) for name, character in next, characters do @@ -133,10 +137,10 @@ function love.update(dt) if love.keyboard.isDown("s") then checkNote(2) end - if love.keyboard.isDown("w") then + if love.keyboard.isDown("up") then checkNote(3) end - if love.keyboard.isDown("d") then + if love.keyboard.isDown("right") then checkNote(4) end @@ -145,7 +149,7 @@ function love.update(dt) if note.mustPress then miss:stop() miss:play() - characters.bf:PlayAnimation(directions[note.direction].."miss") + characters.bf:PlayAnimation("sing"..directions[note.direction].."miss") table.remove(notes, index) end end @@ -156,6 +160,26 @@ function love.update(dt) character:PlayAnimation("idle") end end + + for index, note in next, unspawnedNotes do + if note.position - elapsed < 600 and note.mustPress then + note:spawn() + table.remove(unspawnedNotes, index) + table.insert(notes, note) + end + end + + for index, note in next, notes do + note.sprite.position = myTypes.Vector2(100 + 65 * (note.direction - 1), note.position - elapsed - 100) + if note.position - elapsed < -150 then + note:destroy() + table.remove(notes, index) + end + end + + if not inst:isPlaying() then + love.event.quit() + end end local mainCanvas = love.graphics.newCanvas(1920, 1080) diff --git a/source/modules/types.lua b/source/modules/types.lua index 759e72f..46ff1b2 100644 --- a/source/modules/types.lua +++ b/source/modules/types.lua @@ -14,6 +14,7 @@ local Sprite = {} Sprite.__index = Sprite local Sprites = {} +local Rects = {} function Vector2:Lerp(newVector2, position) return module.Vector2(myMath.lerp(self.x, newVector2.x, position), myMath.lerp(self.x, newVector2.x, position)) @@ -51,7 +52,8 @@ function module.Sprite(image, sheet) frame = 1, position = module.Vector2(200, 100), -- changeable looping = false, - extraOffset = module.Vector2(0,0) + extraOffset = module.Vector2(0,0), + rect = false }, Sprite) for index, sprite in next, atlas do @@ -76,7 +78,6 @@ function module.Sprite(image, sheet) end newSprite.quads = quads - print(logging.dump(quads)) table.insert(Sprites, newSprite) @@ -91,6 +92,24 @@ function Sprite:PlayAnimation(name, fps, loop) self.ended = false end +function Sprite:Destroy() + if self.rect then + for index, rect in next, Rects do + if rect == self then + table.remove(Rects, index) + end + end + self = nil + else + for index, sprite in next, Sprites do + if sprite == self then + table.remove(Sprites, index) + end + end + self = nil + end +end + function module.updateSprites(dt) for index, sprite in next, Sprites do if not sprite.animation then goto continue end @@ -120,13 +139,84 @@ function module.drawSprites() if not 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 - local quad = sprite.quads[sprite.animation][sprite.frame] + local quad = sprite.quads[sprite.animation][sprite.frame] or sprite.quads[sprite.animation][0] love.graphics.draw(sprite.image, quad.quad, (sprite.position.x + (sprite.position.x - quad.offset.x - sprite.extraOffset.x)), (sprite.position.y + (sprite.position.y - quad.offset.y - sprite.extraOffset.y)), 0, quad.resize.x, quad.resize.y) ::continue:: -- Point itself end + + for index, rect in next, Rects do + if not rect.animation then goto continue end + + local quad = rect.quads[rect.animation][0] + + love.graphics.draw(rect.image, quad.quad, (rect.position.x + (rect.position.x - quad.offset.x - rect.extraOffset.x)), (rect.position.y + (rect.position.y - quad.offset.y - rect.extraOffset.y)), 0, quad.resize.x, 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)] = {} + 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 + + table.insert(Rects, newSprite) + + return newSprite +end + +function Sprite:Frame(name, frame) + self.animation = name + self.frame = frame +end + +noteclass.types = module module.note = noteclass.note characterclass.myTypes = module diff --git a/source/modules/types/note.lua b/source/modules/types/note.lua index e130219..ccaef8d 100644 --- a/source/modules/types/note.lua +++ b/source/modules/types/note.lua @@ -3,20 +3,43 @@ local module = {} local NoteClass = {} NoteClass.__index = NoteClass -function NoteClass:destroy() - -end +local sprites = { + "purple", + "blue", + "green", + "red" +} function module.note(raw, mustHitSection) - print(mustHitSection and raw[2] <= 3 or not mustHitSection and raw[2] > 3) + local newNote = setmetatable({ position = raw[1], character = nil, mustPress = mustHitSection and raw[2] <= 3 or not mustHitSection and raw[2] > 3, - direction = raw[2] <= 3 and raw[2] + 1 or raw[2] - 3 + direction = raw[2] <= 3 and raw[2] + 1 or raw[2] - 3, + spawned = false, + sprite = nil -- For unspawned notes }, NoteClass) return newNote end +function NoteClass:spawn() + local sprite = module.types.Rect("sprites/NOTE_assets.png", "sprites/NOTE_assets.json") + + self.sprite = sprite + + sprite:Frame(sprites[self.direction], 0) + + self.spawned = true +end + +function NoteClass:destroy() + if self.sprite then + self.sprite:Destroy() + end + self = nil +end + + return module \ No newline at end of file diff --git a/sprites/NOTE_assets.json b/sprites/NOTE_assets.json new file mode 100644 index 0000000..2c84d71 --- /dev/null +++ b/sprites/NOTE_assets.json @@ -0,0 +1,692 @@ +{ + "TextureAtlas": { + "SubTexture": [ + { + "_name": "arrowLEFT0000", + "_x": "488", + "_y": "238", + "_width": "155", + "_height": "158" + }, + { + "_name": "arrowDOWN0000", + "_x": "647", + "_y": "238", + "_width": "157", + "_height": "155" + }, + { + "_name": "arrowRIGHT0000", + "_x": "808", + "_y": "238", + "_width": "155", + "_height": "157" + }, + { + "_name": "arrowUP0000", + "_x": "323", + "_y": "240", + "_width": "157", + "_height": "154" + }, + { + "_name": "blue hold end0000", + "_x": "1062", + "_y": "452", + "_width": "51", + "_height": "64" + }, + { + "_name": "blue hold piece0000", + "_x": "1282", + "_y": "457", + "_width": "51", + "_height": "44" + }, + { + "_name": "blue0000", + "_x": "0", + "_y": "240", + "_width": "158", + "_height": "154" + }, + { + "_name": "down confirm0000", + "_x": "0", + "_y": "0", + "_width": "240", + "_height": "236", + "_frameX": "-6", + "_frameY": "0", + "_frameWidth": "240", + "_frameHeight": "236" + }, + { + "_name": "down confirm0001", + "_x": "244", + "_y": "0", + "_width": "240", + "_height": "236", + "_frameX": "-6", + "_frameY": "0", + "_frameWidth": "240", + "_frameHeight": "236" + }, + { + "_name": "down confirm0002", + "_x": "1206", + "_y": "235", + "_width": "221", + "_height": "218", + "_frameX": "-12", + "_frameY": "-12", + "_frameWidth": "240", + "_frameHeight": "236" + }, + { + "_name": "down confirm0003", + "_x": "1206", + "_y": "235", + "_width": "221", + "_height": "218", + "_frameX": "-12", + "_frameY": "-12", + "_frameWidth": "240", + "_frameHeight": "236" + }, + { + "_name": "down press0000", + "_x": "805", + "_y": "399", + "_width": "143", + "_height": "139", + "_frameX": "-4", + "_frameY": "-3", + "_frameWidth": "150", + "_frameHeight": "146" + }, + { + "_name": "down press0001", + "_x": "805", + "_y": "399", + "_width": "143", + "_height": "139", + "_frameX": "-4", + "_frameY": "-3", + "_frameWidth": "150", + "_frameHeight": "146" + }, + { + "_name": "down press0002", + "_x": "1898", + "_y": "0", + "_width": "150", + "_height": "146" + }, + { + "_name": "down press0003", + "_x": "1898", + "_y": "0", + "_width": "150", + "_height": "146" + }, + { + "_name": "green hold end0000", + "_x": "1007", + "_y": "452", + "_width": "51", + "_height": "64" + }, + { + "_name": "green hold piece0000", + "_x": "1227", + "_y": "457", + "_width": "51", + "_height": "44" + }, + { + "_name": "green0000", + "_x": "162", + "_y": "240", + "_width": "157", + "_height": "154" + }, + { + "_name": "left confirm0000", + "_x": "972", + "_y": "0", + "_width": "230", + "_height": "232" + }, + { + "_name": "left confirm0001", + "_x": "1438", + "_y": "233", + "_width": "220", + "_height": "222", + "_frameX": "-5", + "_frameY": "-5", + "_frameWidth": "230", + "_frameHeight": "232" + }, + { + "_name": "left confirm0002", + "_x": "1438", + "_y": "0", + "_width": "227", + "_height": "229", + "_frameX": "-2", + "_frameY": "-1", + "_frameWidth": "230", + "_frameHeight": "232" + }, + { + "_name": "left confirm0003", + "_x": "1438", + "_y": "0", + "_width": "227", + "_height": "229", + "_frameX": "-2", + "_frameY": "-1", + "_frameWidth": "230", + "_frameHeight": "232" + }, + { + "_name": "left press0000", + "_x": "1898", + "_y": "449", + "_width": "139", + "_height": "142", + "_frameX": "-4", + "_frameY": "-3", + "_frameWidth": "146", + "_frameHeight": "149" + }, + { + "_name": "left press0001", + "_x": "1898", + "_y": "449", + "_width": "139", + "_height": "142", + "_frameX": "-4", + "_frameY": "-3", + "_frameWidth": "146", + "_frameHeight": "149" + }, + { + "_name": "left press0002", + "_x": "1898", + "_y": "150", + "_width": "146", + "_height": "149" + }, + { + "_name": "left press0003", + "_x": "1898", + "_y": "150", + "_width": "146", + "_height": "149" + }, + { + "_name": "left press0004", + "_x": "1898", + "_y": "150", + "_width": "146", + "_height": "149" + }, + { + "_name": "left press0005", + "_x": "1898", + "_y": "150", + "_width": "146", + "_height": "149" + }, + { + "_name": "left press0006", + "_x": "1898", + "_y": "150", + "_width": "146", + "_height": "149" + }, + { + "_name": "left press0007", + "_x": "1898", + "_y": "150", + "_width": "146", + "_height": "149" + }, + { + "_name": "left press0008", + "_x": "1898", + "_y": "150", + "_width": "146", + "_height": "149" + }, + { + "_name": "left press0009", + "_x": "1898", + "_y": "150", + "_width": "146", + "_height": "149" + }, + { + "_name": "left press0010", + "_x": "1898", + "_y": "150", + "_width": "146", + "_height": "149" + }, + { + "_name": "left press0011", + "_x": "1898", + "_y": "150", + "_width": "146", + "_height": "149" + }, + { + "_name": "left press0012", + "_x": "1898", + "_y": "150", + "_width": "146", + "_height": "149" + }, + { + "_name": "left press0013", + "_x": "1898", + "_y": "150", + "_width": "146", + "_height": "149" + }, + { + "_name": "left press0014", + "_x": "1898", + "_y": "150", + "_width": "146", + "_height": "149" + }, + { + "_name": "left press0015", + "_x": "1898", + "_y": "150", + "_width": "146", + "_height": "149" + }, + { + "_name": "left press0016", + "_x": "1898", + "_y": "150", + "_width": "146", + "_height": "149" + }, + { + "_name": "left press0017", + "_x": "1898", + "_y": "150", + "_width": "146", + "_height": "149" + }, + { + "_name": "left press0018", + "_x": "1898", + "_y": "150", + "_width": "146", + "_height": "149" + }, + { + "_name": "left press0019", + "_x": "1898", + "_y": "150", + "_width": "146", + "_height": "149" + }, + { + "_name": "pruple end hold0000", + "_x": "1117", + "_y": "452", + "_width": "51", + "_height": "64" + }, + { + "_name": "purple hold piece0000", + "_x": "1337", + "_y": "457", + "_width": "51", + "_height": "44" + }, + { + "_name": "purple0000", + "_x": "0", + "_y": "398", + "_width": "154", + "_height": "157" + }, + { + "_name": "red hold end0000", + "_x": "952", + "_y": "452", + "_width": "51", + "_height": "64" + }, + { + "_name": "red hold piece0000", + "_x": "1172", + "_y": "457", + "_width": "51", + "_height": "44" + }, + { + "_name": "red0000", + "_x": "647", + "_y": "397", + "_width": "154", + "_height": "157" + }, + { + "_name": "right confirm0000", + "_x": "1669", + "_y": "0", + "_width": "225", + "_height": "228", + "_frameX": "-1", + "_frameY": "-2", + "_frameWidth": "228", + "_frameHeight": "231" + }, + { + "_name": "right confirm0001", + "_x": "1669", + "_y": "232", + "_width": "225", + "_height": "228", + "_frameX": "-1", + "_frameY": "-2", + "_frameWidth": "228", + "_frameHeight": "231" + }, + { + "_name": "right confirm0002", + "_x": "1206", + "_y": "0", + "_width": "228", + "_height": "231" + }, + { + "_name": "right confirm0003", + "_x": "1206", + "_y": "0", + "_width": "228", + "_height": "231" + }, + { + "_name": "right press0000", + "_x": "469", + "_y": "400", + "_width": "139", + "_height": "142", + "_frameX": "-3", + "_frameY": "-7", + "_frameWidth": "149", + "_frameHeight": "152" + }, + { + "_name": "right press0001", + "_x": "469", + "_y": "400", + "_width": "139", + "_height": "142", + "_frameX": "-3", + "_frameY": "-7", + "_frameWidth": "149", + "_frameHeight": "152" + }, + { + "_name": "right press0002", + "_x": "316", + "_y": "398", + "_width": "149", + "_height": "152" + }, + { + "_name": "right press0003", + "_x": "316", + "_y": "398", + "_width": "149", + "_height": "152" + }, + { + "_name": "right press0004", + "_x": "316", + "_y": "398", + "_width": "149", + "_height": "152" + }, + { + "_name": "right press0005", + "_x": "316", + "_y": "398", + "_width": "149", + "_height": "152" + }, + { + "_name": "right press0006", + "_x": "316", + "_y": "398", + "_width": "149", + "_height": "152" + }, + { + "_name": "right press0007", + "_x": "316", + "_y": "398", + "_width": "149", + "_height": "152" + }, + { + "_name": "right press0008", + "_x": "316", + "_y": "398", + "_width": "149", + "_height": "152" + }, + { + "_name": "right press0009", + "_x": "316", + "_y": "398", + "_width": "149", + "_height": "152" + }, + { + "_name": "right press0010", + "_x": "316", + "_y": "398", + "_width": "149", + "_height": "152" + }, + { + "_name": "right press0011", + "_x": "316", + "_y": "398", + "_width": "149", + "_height": "152" + }, + { + "_name": "right press0012", + "_x": "316", + "_y": "398", + "_width": "149", + "_height": "152" + }, + { + "_name": "right press0013", + "_x": "316", + "_y": "398", + "_width": "149", + "_height": "152" + }, + { + "_name": "right press0014", + "_x": "316", + "_y": "398", + "_width": "149", + "_height": "152" + }, + { + "_name": "right press0015", + "_x": "316", + "_y": "398", + "_width": "149", + "_height": "152" + }, + { + "_name": "right press0016", + "_x": "316", + "_y": "398", + "_width": "149", + "_height": "152" + }, + { + "_name": "right press0017", + "_x": "316", + "_y": "398", + "_width": "149", + "_height": "152" + }, + { + "_name": "right press0018", + "_x": "316", + "_y": "398", + "_width": "149", + "_height": "152" + }, + { + "_name": "right press0019", + "_x": "316", + "_y": "398", + "_width": "149", + "_height": "152" + }, + { + "_name": "right press0020", + "_x": "316", + "_y": "398", + "_width": "149", + "_height": "152" + }, + { + "_name": "right press0021", + "_x": "316", + "_y": "398", + "_width": "149", + "_height": "152" + }, + { + "_name": "right press0022", + "_x": "316", + "_y": "398", + "_width": "149", + "_height": "152" + }, + { + "_name": "right press0023", + "_x": "316", + "_y": "398", + "_width": "149", + "_height": "152" + }, + { + "_name": "right press0024", + "_x": "316", + "_y": "398", + "_width": "149", + "_height": "152" + }, + { + "_name": "right press0025", + "_x": "316", + "_y": "398", + "_width": "149", + "_height": "152" + }, + { + "_name": "right press0026", + "_x": "316", + "_y": "398", + "_width": "149", + "_height": "152" + }, + { + "_name": "up confirm0000", + "_x": "488", + "_y": "0", + "_width": "238", + "_height": "234" + }, + { + "_name": "up confirm0001", + "_x": "730", + "_y": "0", + "_width": "238", + "_height": "234" + }, + { + "_name": "up confirm0002", + "_x": "972", + "_y": "236", + "_width": "216", + "_height": "212", + "_frameX": "-11", + "_frameY": "-11", + "_frameWidth": "238", + "_frameHeight": "234" + }, + { + "_name": "up confirm0003", + "_x": "972", + "_y": "236", + "_width": "216", + "_height": "212", + "_frameX": "-11", + "_frameY": "-11", + "_frameWidth": "238", + "_frameHeight": "234" + }, + { + "_name": "up press0000", + "_x": "1898", + "_y": "303", + "_width": "144", + "_height": "142", + "_frameX": "-6", + "_frameY": "-4", + "_frameWidth": "154", + "_frameHeight": "151" + }, + { + "_name": "up press0001", + "_x": "1898", + "_y": "303", + "_width": "144", + "_height": "142", + "_frameX": "-6", + "_frameY": "-4", + "_frameWidth": "154", + "_frameHeight": "151" + }, + { + "_name": "up press0002", + "_x": "158", + "_y": "398", + "_width": "154", + "_height": "151" + }, + { + "_name": "up press0003", + "_x": "158", + "_y": "398", + "_width": "154", + "_height": "151" + } + ], + "_imagePath": "NOTE_assets.png" + } +} \ No newline at end of file diff --git a/sprites/NOTE_assets.png b/sprites/NOTE_assets.png new file mode 100644 index 0000000..39ea40a Binary files /dev/null and b/sprites/NOTE_assets.png differ