167 lines
3.9 KiB
Lua
167 lines
3.9 KiB
Lua
local Height = 0
|
|
local Width = 0
|
|
|
|
local myMath = require("source.modules.math")
|
|
local myTypes = require("source.modules.types")
|
|
local conductor = require("source.modules.conductor")
|
|
local json = require("source.modules.json")
|
|
local files = require("source.modules.files")
|
|
local logger = require("source.modules.logging")
|
|
local socket = require("socket")
|
|
local logging= require("source.modules.logging")
|
|
|
|
local newVector2 = myTypes.Vector2(10, 10)
|
|
|
|
local startTime = 0
|
|
|
|
local songName = "stress"
|
|
local songDifficulty = "hard"
|
|
|
|
local chartString = files.read_file(string.format("charts/%s/%s-%s.json", songName, songName, songDifficulty))
|
|
|
|
if not chartString then
|
|
error("Chart couldn't be loaded!")
|
|
end
|
|
local chart = json.parse(chartString).song
|
|
|
|
local inst = love.audio.newSource(string.format("songs/%s/Inst.ogg", chart.song), "stream")
|
|
local voices = love.audio.newSource(string.format("songs/%s/Voices.ogg", chart.song), "stream")
|
|
local miss = love.audio.newSource("sounds/missnote1.ogg", "static")
|
|
|
|
conductor:setBpm(chart.bpm)
|
|
conductor:mapBpmChanges(chart)
|
|
|
|
local step = 0
|
|
local beat = 0
|
|
|
|
local graphics = {
|
|
}
|
|
|
|
function loadGraphic(graphic)
|
|
if graphic.graphics == love.graphics.newImage then
|
|
graphic.loaded = love.graphics.newImage(graphic.path)
|
|
end
|
|
|
|
if graphic.children then
|
|
for index, graphicChild in next, graphic.children do
|
|
loadGraphic(graphicChild)
|
|
end
|
|
end
|
|
end
|
|
|
|
local playing = false
|
|
|
|
local bf
|
|
|
|
local notes = {}
|
|
|
|
local directions = {
|
|
"singLEFT",
|
|
"singDOWN",
|
|
"singUP",
|
|
"singRIGHT"
|
|
}
|
|
|
|
function love.load()
|
|
|
|
bf = myTypes.character("bf")
|
|
|
|
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)
|
|
end
|
|
end
|
|
|
|
inst:play()
|
|
voices:play()
|
|
|
|
startTime = socket.gettime()
|
|
|
|
playing = true
|
|
end
|
|
|
|
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
|
|
bf:PlayAnimation(directions[note.direction])
|
|
note.pressed = true
|
|
table.remove(notes, index)
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
function love.update(dt)
|
|
if not playing then return end
|
|
|
|
local currentTime = socket.gettime()
|
|
|
|
local elapsed = math.floor((currentTime - startTime) * 1000)
|
|
|
|
conductor.songPosition = elapsed
|
|
|
|
local oldStep = step
|
|
local oldBeat = beat
|
|
|
|
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)
|
|
end
|
|
end
|
|
|
|
myTypes.updateSprites(dt)
|
|
|
|
if love.keyboard.isDown("a") then
|
|
checkNote(1)
|
|
end
|
|
if love.keyboard.isDown("s") then
|
|
checkNote(2)
|
|
end
|
|
if love.keyboard.isDown("w") then
|
|
checkNote(3)
|
|
end
|
|
if love.keyboard.isDown("d") then
|
|
checkNote(4)
|
|
end
|
|
|
|
for index, note in next, notes do
|
|
if note.position - conductor.songPosition < 0 then
|
|
if note.mustPress then
|
|
miss:stop()
|
|
miss:play()
|
|
bf:PlayAnimation(directions[note.direction].."miss")
|
|
table.remove(notes, index)
|
|
end
|
|
end
|
|
end
|
|
end
|
|
|
|
local mainCanvas = love.graphics.newCanvas(1920, 1080)
|
|
|
|
function love.draw()
|
|
|
|
love.graphics.setCanvas(mainCanvas)
|
|
|
|
love.graphics.clear()
|
|
|
|
myTypes.drawSprites()
|
|
|
|
love.graphics.setCanvas()
|
|
|
|
love.graphics.circle("fill", 960, 59, 50000)
|
|
|
|
love.graphics.draw(mainCanvas, 0, 0, 0, (love.graphics:getHeight() / 1080) * (4/3), love.graphics:getHeight() / 1080)
|
|
|
|
end
|
|
|
|
love.window.setMode(1280, 720, { fullscreen = true , resizable = true}) |