7 Commits

3 changed files with 53 additions and 15 deletions
Unified View
  1. +44
    -12
      main.lua
  2. +8
    -2
      src/class/Button.lua
  3. +1
    -1
      src/class/Textbox.lua

+ 44
- 12
main.lua View File

@@ -23,18 +23,27 @@ function love.load()
Menubutton(30, 170, 180, 40, gamestate.quit, nil, "Quit Game", {255, 255, 255}, {57, 45, 66}) Menubutton(30, 170, 180, 40, gamestate.quit, nil, "Quit Game", {255, 255, 255}, {57, 45, 66})
}, },
game = { game = {
-- Pause button or something here in future?
-- Pause button or something here in future?
} }
} }


-- Buttons: -- Buttons:
button = { button = {
tutorial = Button(width - 70, 20, 50, 30, "help", {255, 255, 255}, {40, 40, 40}, false)
tutorial = Button(width - 70, 20, 50, 30, "help", {255, 255, 255}, {40, 40, 40}, false),
pause = Button(width - 70, 60, 80, 30, "pause", {255, 255, 255}, {40, 40, 40}, false)
} }


pausebutton = {
}
table.insert(pausebutton, Button(width/2-250, height/2-25, 500, 50, "Continue", {255, 255, 255}, {40, 40, 40}, false, function() button.pause.isActive = false end))
table.insert(pausebutton, Button(width/2-250, height/2+35, 500, 50, "Main Menu", {255, 255, 255}, {40, 40, 40}, false, function() restartGame() GAMESTATE = gamestate.menu end))
table.insert(pausebutton, Button(width/2-250, height/2+95, 500, 50, "Quit", {255, 255, 255}, {40, 40, 40}, false, function() love.event.quit() end))

-- Textboxes: -- Textboxes:
textbox = { textbox = {
tutorial = Textbox(40, 40, width-80, height-80, text.tutorial, "center", {255, 255, 255}, {0, 0, 0})
tutorial = Textbox(40, 40, width-80, height-80, calc.getText(text.tutorial), "center", {255, 255, 255}, {0, 0, 0})
} }




@@ -114,15 +123,17 @@ function cameraControls()
local step = settings.zoom.step local step = settings.zoom.step


function love.wheelmoved(x, y) function love.wheelmoved(x, y)
if y > 0 then
-- Zoom in:
zoomlevel = zoomlevel + step*(zoomlevel*10)
elseif y < 0 then
-- Zoom out:
zoomlevel = zoomlevel - step*(zoomlevel*10)
if not button.pause.isActive then
if y > 0 then
-- Zoom in:
zoomlevel = zoomlevel + step*(zoomlevel*10)
elseif y < 0 then
-- Zoom out:
zoomlevel = zoomlevel - step*(zoomlevel*10)
end
end end
end end
-- Reset Zoom: -- Reset Zoom:
if love.mouse.isDown(controls.camera.zoom.reset) then if love.mouse.isDown(controls.camera.zoom.reset) then
zoomlevel = settings.zoom.reset zoomlevel = settings.zoom.reset
@@ -220,6 +231,13 @@ function love.update(dt)
elseif GAMESTATE == gamestate.menu then elseif GAMESTATE == gamestate.menu then


elseif GAMESTATE == gamestate.game then elseif GAMESTATE == gamestate.game then
button.pause:update()
if (button.pause.isActive) then
for i, butt in ipairs(pausebutton) do
butt:update()
end
return
end
-- Game Objects: -- Game Objects:
for i=1, timewarpControls() do for i=1, timewarpControls() do
-- Physics go in here: -- Physics go in here:
@@ -231,6 +249,7 @@ function love.update(dt)
-- Gui: -- Gui:
gui:update(dt) gui:update(dt)
button.tutorial:update() button.tutorial:update()


-- Camera: -- Camera:
cam:lookAt(player.x, player.y) cam:lookAt(player.x, player.y)
@@ -257,11 +276,24 @@ function love.draw()
-- Gui: -- Gui:
player:drawPositionIndicator() player:drawPositionIndicator()
gui:draw() gui:draw()
button.tutorial:draw()
if button.tutorial.isActive then if button.tutorial.isActive then
textbox.tutorial:draw() textbox.tutorial:draw()
else
button.pause:draw()
if (button.pause.isActive) then
for i, butt in ipairs(pausebutton) do
butt:draw()
end
end
end end
button.tutorial:draw()
end end
menubuttonDraw() menubuttonDraw()
end


function restartGame()
button.pause.isActive = false
button.tutorial.isActive = false
player:reset()
end end

+ 8
- 2
src/class/Button.lua View File

@@ -1,6 +1,6 @@
Button = Class {} Button = Class {}


function Button:init(tempX, tempY, tempW, tempH, tempText, tempTC, tempBC, tempActive)
function Button:init(tempX, tempY, tempW, tempH, tempText, tempTC, tempBC, tempActive, tempFn)
-- Position and Dimensions: -- Position and Dimensions:
self.x = tempX self.x = tempX
self.y = tempY self.y = tempY
@@ -20,6 +20,9 @@ function Button:init(tempX, tempY, tempW, tempH, tempText, tempTC, tempBC, tempA
-- Click Cooldown: -- Click Cooldown:
self.cooldownLimit = 30 self.cooldownLimit = 30
self.cooldown = 0 self.cooldown = 0
if tempFn~=nil then
self.fn = tempFn
end
end end




@@ -49,6 +52,9 @@ function Button:update(dt)
if self:click() and self.cooldown <= 0 then if self:click() and self.cooldown <= 0 then
self.isActive = not self.isActive self.isActive = not self.isActive
self.cooldown = self.cooldownLimit self.cooldown = self.cooldownLimit
if self.fn ~= nil then
self.fn()
end
end end
self.cooldown = self.cooldown - 1 self.cooldown = self.cooldown - 1
end end
@@ -76,5 +82,5 @@ function Button:draw()
-- Draw Text -- Draw Text
love.graphics.setFont(font.default) love.graphics.setFont(font.default)
love.graphics.setColor(tx[1], tx[2], tx[3]) love.graphics.setColor(tx[1], tx[2], tx[3])
love.graphics.printf(self.text, x, y, w, "center")
love.graphics.printf(self.text, x, y+h/8, w, "center")
end end

+ 1
- 1
src/class/Textbox.lua View File

@@ -8,7 +8,7 @@ function Textbox:init(tempX, tempY, tempW, tempH, tempText, tempAlign, tempTC, t
self.h = tempH self.h = tempH


-- Text: -- Text:
self.text = calc.getText(tempText)
self.text = tempText
self.align = tempAlign self.align = tempAlign


-- Colours: -- Colours:


Loading…
Cancel
Save