~marnold128/pacetime.love

40fd5bd4e956f978aa48736bd63efc3c0a0e016d — Matt Arnold 9 months ago 82d5905
New playlist feature for testing
3 files changed, 54 insertions(+), 4 deletions(-)

M config.lua
M main.lua
A playlist.txt
M config.lua => config.lua +3 -2
@@ 2,7 2,8 @@

timerCountDown = 300
timerMaxDiv = 4
backgroundMusicFile = "pacetime.ogg"
backgroundMusicFile = "playlist.txt"
victoryMusicFile = "victory.ogg"
bleepSoundFile = "computerbeep.mp3"
meanieMode = false
\ No newline at end of file
meanieMode = false
bgIsPlaylist = true

M main.lua => main.lua +48 -2
@@ 13,7 13,42 @@
require("button")
require("config")
divMax = timerMaxDiv
function str_split (inputstr, sep)
        if sep == nil then
                sep = "%s"
        end
        local t={}
        for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
                table.insert(t, str)
        end
        return t
end

function loadPlaylist(playlist_file)
    if love.filesystem.getInfo(playlist_file) then
        file = love.filesystem.read(playlist_file)
        local post = str_split(file)
        return post
    else
        error("playlist unreadable")
    end
end

function randomize_source(tbl)
    s = love.math.random(1, #tbl)
    return tbl[s]
end


function playlistCallback(audioSrc)
    print("Entered playlist conditional")

    if (timerActive) and not audioSrc:isPlaying() then

        bgm = love.audio.newSource(randomize_source(plistTable), "stream")
        love.audio.play(bgm)
    end
end
function love.load()
    x = 100
    y = 500


@@ 29,7 64,15 @@ function love.load()
    love.graphics.setFont(font)
    love.graphics.setBackgroundColor(0.09,0.56,0.36)
    love.graphics.setColor(0.8980392156862745,0.9176470588235294,0.9803921568627451)
    bgm = love.audio.newSource(backgroundMusicFile, "stream")
    if not bgIsPlaylist then
        bgm = love.audio.newSource(backgroundMusicFile, "stream")
        bgm:setLooping(true)
    else
        plistTable = loadPlaylist(backgroundMusicFile)
        bgm = love.audio.newSource(randomize_source(plistTable), "stream")

    end

    bleep = love.audio.newSource(bleepSoundFile, "static")
    victory = love.audio.newSource(victoryMusicFile, "static")
    


@@ 48,7 91,7 @@ function startButtonCallback()
    end

    if not bgm:isPlaying() then
        bgm:setLooping(true)
        if bgIsPlaylist then bgm = love.audio.newSource(randomize_source(plistTable), "stream") end
        love.audio.play(bgm)
    end
    ourtext = "You Got this"


@@ 105,6 148,8 @@ function love.update(dt)
    end
    if y < 0 then y = 500 end
    if timerActive  then timerCallBack() end
    --print("Bingo is " .. tostring(bgIsPlaylist))
    if bgIsPlaylist then playlistCallback(bgm) end -- A Side wrong not B
end

function love.draw() 


@@ 117,6 162,7 @@ function love.draw()
    for index, button in ipairs(buttons) do
        love.graphics.print(ButtonMaker.getText(button), button.x, button.y)
    end

    love.graphics.setColor(0.8980392156862745,0.9176470588235294,0.9803921568627451)
    love.graphics.print(ourtext, x, y)


A playlist.txt => playlist.txt +3 -0
@@ 0,0 1,3 @@
internationale.ogg
pacetime.ogg
placebo.xm