~kmdodrill/ghost-simulator

9f7af00ba1459182c1dc204904b6f4d1c2362198 — Kenneth Dodrill 6 months ago 69b4464
Add touchscreen support, fix build
4 files changed, 56 insertions(+), 3 deletions(-)

M build.sh
M main.lua
M src/sceneManager.lua
M src/scenes/drink.lua
M build.sh => build.sh +1 -1
@@ 1,7 1,7 @@
#!/bin/sh
rm -rf dist
mkdir dist
zip -9 -r dist/ghost-simulator.love main.lua conf.lua assets/fonts assets/music assets/sfx assets/sprites COPYING LICENSE README.md -x */**/*.pxo */**/*.aup3
zip -9 -r dist/ghost-simulator.love main.lua conf.lua src assets/fonts assets/music assets/sfx assets/sprites COPYING LICENSE README.md -x */**/*.pxo */**/*.aup3
cd dist

# build for windows

M main.lua => main.lua +40 -0
@@ 140,3 140,43 @@ function love.keypressed(key, scancode, isrepeat)
        SceneManager.reload()
    end
end

function love.touchpressed(id, x, y, dx, dy, pressure)
    CurrentCursor.image = CurrentCursor.closed

    if not Frozen then
        for _, button in ipairs(Scene.buttons) do
            if Collision.check(
                {x = x, y = y, w = 10, h = 10},
                {x = button.position.x, y = button.position.y, w = button.size.w, h = button.size.h}
            ) then
                button.callback()
                return
            end
        end
    end

    if Scene.timer then
        KeyboardTimer = love.timer.getTime()
    end
    -- waiting on the player to read the scene title and press a key to continue
    if ShowTitle and Frozen then
        ShowTitle = false
        SceneManager.unfreeze()
        if Scene.timer then
            Timer = love.timer.getTime()
            KeyboardTimer = love.timer.getTime()
        end
        return
    end
    if NeedsReloadScene and Frozen then
        SceneManager.reload()
    end
end

function love.touchreleased(id, x, y, dx, dy, pressure)
    CurrentCursor.image = CurrentCursor.open
end

function love.touchmoved(id, x, y, dx, dy, pressure)
end

M src/sceneManager.lua => src/sceneManager.lua +2 -2
@@ 133,7 133,7 @@ function SceneManager.update(dt)
        TimeLeft = Scene.timeLimit - (love.timer.getTime() - Timer)
    end

    assert(load("return " .. Scenes[CurrentSceneIndex] .. ".update(...)"))(dt)
    assert(loadstring("return " .. Scenes[CurrentSceneIndex] .. ".update(...)"))(dt)
end

function SceneManager.draw()


@@ 232,7 232,7 @@ function SceneManager.reload()

    -- somethingSelected = false

    local newScene = assert(load("return " .. Scenes[CurrentSceneIndex] .. ".load(...)"))()
    local newScene = assert(loadstring("return " .. Scenes[CurrentSceneIndex] .. ".load(...)"))()
    if newScene.title then
        Scene.title = newScene.title
    end

M src/scenes/drink.lua => src/scenes/drink.lua +13 -0
@@ 69,6 69,19 @@ function Drink.update(dt)
        ) then
            drinking = true
        end
    elseif next(love.touch.getTouches()) ~= nil then
        local x, y = love.touch.getPosition(love.touch.getTouches()[1])
        if Collision.check(
            {
                x = x - CurrentCursor.image.getWidth(CurrentCursor.image) / 2,
                y = y + CurrentCursor.image.getHeight(CurrentCursor.image) - CurrentCursor.image.getHeight(CurrentCursor.image) / 4,
                w = 25,
                h = 25,
            },
            {x = 515, y = 280, w = 115, h = 90}
        ) then
            drinking = true
        end
    else
        Sound.stop(Sip)
    end