Code: Select all
scenes = {
sceneone = true,
scenetwo = false,
}
function love.load()
require "sceneone"
require "scenetwo"
end
function love.update(dt)
end
function love.draw()
if scenes.sceneone == true then
sceneone:draw()
end
if scenes.scenetwo == true then
scenetwo:draw()
end
end
function love.mousepressed(x, y, b)
if scenes.sceneone == true then
sceneone:mousepressed(x, y, b)
end
if scenes.scenetwo == true then
scenetwo:mousepressed(x, y, b)
end
end
Code: Select all
sceneone = {}
local button = {x = 10, y = 10, w = 100, h = 30}
function sceneone:update(dt)
end
function sceneone:draw()
love.graphics.setColor(1,0,0)
love.graphics.print("ONE", 45, 17)
love.graphics.rectangle("line", button.x, button.y, button.w, button.h)
end
function sceneone:mousepressed(x, y, b)
if b == 1 and scenes.sceneone == true then
if (x > button.x and x < button.x + button.w)
and (y > button.y and y < button.y + button.h)
then
print("this is scene two")
scenes.sceneone = false
scenes.scenetwo = true
end
end
end
Code: Select all
scenetwo = {}
local button = {x = 10, y = 10, w = 100, h = 30}
function scenetwo:update(dt)
end
function scenetwo:draw()
love.graphics.setColor(0,0,1)
love.graphics.print("TWO", 45, 17)
love.graphics.rectangle("line", button.x, button.y, button.w, button.h)
end
function scenetwo:mousepressed(x, y, b)
if b == 1 and scenes.scenetwo == true then
if (x > button.x and x < button.x + button.w)
and (y > button.y and y < button.y + button.h)
then
print("this is scene one")
scenes.scenetwo = false
scenes.sceneone = true
end
end
end