aboutsummaryrefslogtreecommitdiffstats
path: root/Game.lua
diff options
context:
space:
mode:
authorpiernov <piernov@piernov.org>2014-03-13 16:14:10 +0100
committerpiernov <piernov@piernov.org>2014-03-13 16:14:10 +0100
commit9004e721dd27b2d1c330cf1ce35771ca3c91ac82 (patch)
treeb45e7ce8775e3badc84233a0079fd9628303559b /Game.lua
downloadMaiLÖVE-9004e721dd27b2d1c330cf1ce35771ca3c91ac82.tar.gz
MaiLÖVE-9004e721dd27b2d1c330cf1ce35771ca3c91ac82.tar.bz2
MaiLÖVE-9004e721dd27b2d1c330cf1ce35771ca3c91ac82.tar.xz
MaiLÖVE-9004e721dd27b2d1c330cf1ce35771ca3c91ac82.zip
Importation du projet
Diffstat (limited to 'Game.lua')
-rwxr-xr-xGame.lua127
1 files changed, 127 insertions, 0 deletions
diff --git a/Game.lua b/Game.lua
new file mode 100755
index 0000000..c4cc8f5
--- /dev/null
+++ b/Game.lua
@@ -0,0 +1,127 @@
+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