local Game = {} local buttonRadius = 5 function Game:init() self.button = love.graphics.newCanvas( 100, 100, "normal", 16 ) love.graphics.setCanvas(self.button) self.button:clear() love.graphics.setBlendMode('alpha') love.graphics.setColor(0, 0, 0, 255) love.graphics.circle( "fill", 50, 50, (buttonRadius/100)*Config.height, 100 ) love.graphics.setColor(255, 0, 0, 255) love.graphics.circle( "fill", 50, 50, ((buttonRadius-1)/100)*Config.height, 100 ) love.graphics.setCanvas() self.circle = love.graphics.newCanvas( 100, 100, "normal", 16 ) love.graphics.setCanvas(self.circle) self.circle:clear() love.graphics.setBlendMode('alpha') love.graphics.setColor(0, 0, 0, 128) love.graphics.circle( "fill", 50, 50, (buttonRadius/100)*Config.height, 100 ) love.graphics.setColor(255, 0, 0, 128) love.graphics.circle( "fill", 50, 50, ((buttonRadius-1)/100)*Config.height, 100 ) love.graphics.setCanvas() end function Game:enter(previous, song, id) self.song = song self.level = id for k,v in pairs(self.song.bpms) do self.beatDuration = 60000*4/v break end --self.beatDuration = 60000*4/self.song.bpms["0.000"] self.music = love.audio.newSource(song.file:match("(.*/)") .. song.music) love.graphics.setBackgroundColor(104, 136, 248) end local tx=0 local ty=0 local tp=0 function love.touchpressed(x, y, p) tp = p tx = x ty = y end local speed = 50 local offset = -1000*45/speed local timer = offset local musicplaying = false local lastnote = -1 local beat = 0 local noteTime = 0 local beatTime = 0 local displayedNotes = {} function Game:update(dt) if timer < 0 then timer = timer + dt*1000 else if not musicplaying then musicplaying = true self.music:play() end timer = self.music:tell("seconds")*1000 end for k, v in pairs(displayedNotes) do if v.x > 95-buttonRadius or v.y > 95-buttonRadius or v.x < 5-buttonRadius or v.y < 5-buttonRadius then table.remove(displayedNotes, k) elseif v.orientation == "left" then displayedNotes[k].y = v.y + dt*speed elseif v.orientation == "down" then displayedNotes[k].x = v.x + dt*speed elseif v.orientation == "up" then displayedNotes[k].y = v.y - dt*speed elseif v.orientation == "right" then displayedNotes[k].x = v.x - dt*speed end end beat = math.ceil((timer-offset)/self.beatDuration) if beat < 1 then return end noteTime = self.beatDuration/#self.song.notes[self.level][SMFileSchema.NotesInfos.noteData][2][beat] beatTime = (timer-offset)-(beat-1)*self.beatDuration notes = math.ceil(beatTime/noteTime) if lastnote ~= notes then lastnote = notes notes = self.song.notes[self.level][SMFileSchema.NotesInfos.noteData][2][beat][notes] if notes[1] == "1" then table.insert(displayedNotes, { x = 50-buttonRadius, y = 50-buttonRadius, orientation = "left" }) end if notes[2] == "1" then table.insert(displayedNotes, { x = 50-buttonRadius, y = 50-buttonRadius, orientation = "down" }) end if notes[3] == "1" then table.insert(displayedNotes, { x = 50-buttonRadius, y = 50-buttonRadius, orientation = "up" }) end if notes[4] == "1" then table.insert(displayedNotes, { x = 50-buttonRadius, y = 50-buttonRadius, orientation = "right" }) end end end function Game:draw() love.graphics.clear() love.graphics.setColor(255, 0, 0) love.graphics.setBlendMode('alpha') love.graphics.print(timer, 320, 300) for k,v in pairs(self.song.bpms) do love.graphics.print(v, 200, 300) end love.graphics.print(beat, 200, 200) love.graphics.print(lastnote, 200, 100) love.graphics.print(noteTime, 200, 50) love.graphics.print(beatTime, 200, 150) love.graphics.print(tp, 350, 150) love.graphics.print(tx, 370, 150) love.graphics.print(ty, 390, 150) love.graphics.setBlendMode('premultiplied') love.graphics.draw(self.circle, Utils.percentCoordinates(5-buttonRadius, 50-buttonRadius)) love.graphics.draw(self.circle, Utils.percentCoordinates(50-buttonRadius, 95-buttonRadius)) love.graphics.draw(self.circle, Utils.percentCoordinates(50-buttonRadius, 5-buttonRadius)) love.graphics.draw(self.circle, Utils.percentCoordinates(95-buttonRadius, 50-buttonRadius)) --love.graphics.draw(self.button, Utils.percentCoordinates(x, 50)) for k, v in pairs(displayedNotes) do love.graphics.draw(self.button, Utils.percentCoordinates(v.x, v.y)) end end return Game