Renamed pause.lua to ui.lua; adjusted accordingly.
This commit is contained in:
parent
9e43b02620
commit
f4b44dc7bc
Binary file not shown.
After Width: | Height: | Size: 1.1 KiB |
Binary file not shown.
After Width: | Height: | Size: 1.1 KiB |
|
@ -17,8 +17,7 @@ require "data/scripts/objects"
|
||||||
-- UI functions
|
-- UI functions
|
||||||
require "data/scripts/debug"
|
require "data/scripts/debug"
|
||||||
require "data/scripts/keybind"
|
require "data/scripts/keybind"
|
||||||
require "data/scripts/pause"
|
require "data/scripts/ui"
|
||||||
require "data/scripts/ui/button"
|
|
||||||
-- game loop
|
-- game loop
|
||||||
require "data/scripts/game"
|
require "data/scripts/game"
|
||||||
require "data/scripts/gameworld"
|
require "data/scripts/gameworld"
|
||||||
|
|
|
@ -32,6 +32,12 @@ function DebugColisions()
|
||||||
end
|
end
|
||||||
|
|
||||||
function DebugEntities()
|
function DebugEntities()
|
||||||
|
for _, particle in pairs(LoadedParticles) do
|
||||||
|
-- draw center CYAN
|
||||||
|
love.graphics.setColor(0,1,1)
|
||||||
|
love.graphics.circle("fill", -Camera.pos.x + particle.pos.x, -Camera.pos.y + particle.pos.y, 1)
|
||||||
|
|
||||||
|
end
|
||||||
for _, enty in pairs(LoadedEntities) do
|
for _, enty in pairs(LoadedEntities) do
|
||||||
-- draw center GREEN
|
-- draw center GREEN
|
||||||
love.graphics.setColor(0,1,0)
|
love.graphics.setColor(0,1,0)
|
||||||
|
|
|
@ -13,8 +13,9 @@ Particle = Entity:New(x,y)
|
||||||
o.sprite_scale = particle_data.sprite_scale or o.sprite_scale
|
o.sprite_scale = particle_data.sprite_scale or o.sprite_scale
|
||||||
o.sprite_tint = particle_data.sprite_tint or o.sprite_tint
|
o.sprite_tint = particle_data.sprite_tint or o.sprite_tint
|
||||||
o.sprite_alpha = particle_data.sprite_alpha or o.sprite_alpha
|
o.sprite_alpha = particle_data.sprite_alpha or o.sprite_alpha
|
||||||
o.sprite_flip = particle_data.sprite_flip or o.sprite_flip
|
o.sprite_alpha_base = o.sprite_alpha
|
||||||
|
|
||||||
|
o.sprite_flip = particle_data.sprite_flip or o.sprite_flip
|
||||||
o.animation_active = particle_data.animation_active or false
|
o.animation_active = particle_data.animation_active or false
|
||||||
|
|
||||||
o.time = 0.5
|
o.time = 0.5
|
||||||
|
@ -63,7 +64,7 @@ end
|
||||||
function Particle:HandleAnimation()
|
function Particle:HandleAnimation()
|
||||||
self.body:Animate()
|
self.body:Animate()
|
||||||
self.timer = self.timer + current_dt
|
self.timer = self.timer + current_dt
|
||||||
self.sprite_alpha = (self.time-self.timer)/self.time
|
self.sprite_alpha = self.sprite_alpha_base*(self.time-self.timer)/self.time
|
||||||
if self.light ~= nil then
|
if self.light ~= nil then
|
||||||
self.light.range = self.lightRange * self.sprite_alpha/2
|
self.light.range = self.lightRange * self.sprite_alpha/2
|
||||||
end
|
end
|
||||||
|
|
|
@ -129,6 +129,7 @@ function Player:DoPhysics()
|
||||||
local particle_data = {
|
local particle_data = {
|
||||||
animation = self.body,
|
animation = self.body,
|
||||||
sprite_tint = HEX2RGB("#fed100"),
|
sprite_tint = HEX2RGB("#fed100"),
|
||||||
|
sprite_alpha = 0.5,
|
||||||
sprite_flip = {
|
sprite_flip = {
|
||||||
x = self.sprite_flip.x,
|
x = self.sprite_flip.x,
|
||||||
y = self.sprite_flip.y
|
y = self.sprite_flip.y
|
||||||
|
|
|
@ -29,6 +29,4 @@ function GameDraw()
|
||||||
DebugColisions()
|
DebugColisions()
|
||||||
DebugEntities()
|
DebugEntities()
|
||||||
end
|
end
|
||||||
-- pause
|
|
||||||
if do_pause then PauseUI() end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,66 +0,0 @@
|
||||||
function PauseUI()
|
|
||||||
-- Set scale to 1
|
|
||||||
love.graphics.scale(0.5,0.5)
|
|
||||||
-- Parameters
|
|
||||||
local pauseWidth = 640
|
|
||||||
local pauseHeight = 480
|
|
||||||
local pauseX = (game.width/2)-(pauseWidth/2)
|
|
||||||
local pauseY = (game.height/2)-(pauseHeight/2)
|
|
||||||
local mouse_x, mouse_y = love.mouse.getPosition()
|
|
||||||
-- Base items
|
|
||||||
love.graphics.setColor(0,0,0,0.3)
|
|
||||||
love.graphics.rectangle("fill", 0, 0, game.width, game.height)
|
|
||||||
love.graphics.setColor(1,1,1,1)
|
|
||||||
love.graphics.rectangle("fill", pauseX, pauseY, pauseWidth, pauseHeight)
|
|
||||||
-- Buttons
|
|
||||||
for _, element in pairs(UIElement) do
|
|
||||||
element:Draw()
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Reset scale
|
|
||||||
love.graphics.scale(2,2)
|
|
||||||
end
|
|
||||||
|
|
||||||
function MenuStep(menu)
|
|
||||||
-- first get mouse
|
|
||||||
local mouse_x, mouse_y = love.mouse.getPosition()
|
|
||||||
for _, element in pairs(UIElement) do
|
|
||||||
if element.type == "Button" then
|
|
||||||
element:checkMouse(mouse_x, mouse_y)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if menu == "pauseMenu" then
|
|
||||||
if PauseResume:getVariable() == true then
|
|
||||||
MenuExit(menu,0)
|
|
||||||
do_pause = false
|
|
||||||
elseif PauseExit:getVariable() == true then
|
|
||||||
love.event.quit()
|
|
||||||
end
|
|
||||||
else
|
|
||||||
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function MenuExit(from,to)
|
|
||||||
for _, element in pairs(UIElement) do
|
|
||||||
element = nil
|
|
||||||
end
|
|
||||||
UIElement = {}
|
|
||||||
if from == "pauseMenu" then
|
|
||||||
PauseResume = nil
|
|
||||||
PauseOptions = nil
|
|
||||||
PauseExit = nil
|
|
||||||
end
|
|
||||||
menuPage = to or nil
|
|
||||||
end
|
|
||||||
|
|
||||||
function MenuInit(menu)
|
|
||||||
local buttonStandard = {width = 200, height = 30, separation = 10}
|
|
||||||
-- main menu
|
|
||||||
if menu == "pauseMenu" then
|
|
||||||
-- elements
|
|
||||||
PauseResume = interfaceButton:New(game.width/2, game.height/2-buttonStandard.height-buttonStandard.separation, buttonStandard.width, buttonStandard.height, {false,true}, 1, {text = "Resume", color = {0,0,0.5}, color2 = {1,1,1}})
|
|
||||||
PauseOptions = interfaceButton:New(game.width/2, game.height/2, buttonStandard.width, buttonStandard.height, {false,true}, 1, {text = "Options", color = {0,0,0.5}, color2 = {1,1,1}})
|
|
||||||
PauseExit = interfaceButton:New(game.width/2, game.height/2+buttonStandard.height+buttonStandard.separation, buttonStandard.width, buttonStandard.height, {false,true}, 1, {text = "Exit", color = {0,0,0.5}, color2 = {1,1,1}})
|
|
||||||
end
|
|
||||||
end
|
|
|
@ -0,0 +1,104 @@
|
||||||
|
function MenuDraw(menu)
|
||||||
|
-- Set scale to 1
|
||||||
|
love.graphics.scale(0.5,0.5)
|
||||||
|
if menu == "pauseMenu" then
|
||||||
|
-- Parameters
|
||||||
|
local pauseWidth = 640
|
||||||
|
local pauseHeight = 480
|
||||||
|
local pauseX = (game.width/2)-(pauseWidth/2)
|
||||||
|
local pauseY = (game.height/2)-(pauseHeight/2)
|
||||||
|
local mouse_x, mouse_y = love.mouse.getPosition()
|
||||||
|
-- Base items
|
||||||
|
love.graphics.setColor(0,0,0,0.3)
|
||||||
|
love.graphics.rectangle("fill", 0, 0, game.width, game.height)
|
||||||
|
love.graphics.setColor(1,1,1,1)
|
||||||
|
love.graphics.rectangle("fill", pauseX, pauseY, pauseWidth, pauseHeight)
|
||||||
|
-- Reset scale
|
||||||
|
end
|
||||||
|
for _, element in pairs(UIElement) do
|
||||||
|
element:Draw()
|
||||||
|
end
|
||||||
|
love.graphics.scale(2,2)
|
||||||
|
end
|
||||||
|
|
||||||
|
function MenuStep(menu)
|
||||||
|
-- first get mouse
|
||||||
|
local mouse_x, mouse_y = love.mouse.getPosition()
|
||||||
|
for _, element in pairs(UIElement) do
|
||||||
|
if element.type == "Button" then
|
||||||
|
element:checkMouse(mouse_x, mouse_y)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if menu == "pauseMenu" then
|
||||||
|
if PauseResume:getVariable() == true then
|
||||||
|
MenuExit(menu,0)
|
||||||
|
do_pause = false
|
||||||
|
elseif PauseExit:getVariable() == true then
|
||||||
|
love.event.quit()
|
||||||
|
end
|
||||||
|
else
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function MenuExit(from,to)
|
||||||
|
for _, element in pairs(UIElement) do
|
||||||
|
element = nil
|
||||||
|
end
|
||||||
|
UIElement = {}
|
||||||
|
if from == "pauseMenu" then
|
||||||
|
PauseResume = nil
|
||||||
|
PauseOptions = nil
|
||||||
|
PauseExit = nil
|
||||||
|
end
|
||||||
|
menuPage = to or nil
|
||||||
|
end
|
||||||
|
|
||||||
|
function MenuInit(menu)
|
||||||
|
local buttonStandard = {width = 200, height = 30, separation = 10}
|
||||||
|
-- main menu
|
||||||
|
if menu == "pauseMenu" then
|
||||||
|
-- elements
|
||||||
|
PauseResume = interfaceButton:New(
|
||||||
|
game.width/2,
|
||||||
|
game.height/2-buttonStandard.height-buttonStandard.separation,
|
||||||
|
buttonStandard.width,
|
||||||
|
buttonStandard.height,
|
||||||
|
{false,true},
|
||||||
|
1,
|
||||||
|
{
|
||||||
|
text = "Resume",
|
||||||
|
color = {0,0,0.5},
|
||||||
|
color2 = {1,1,1}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
PauseOptions = interfaceButton:New(
|
||||||
|
game.width/2,
|
||||||
|
game.height/2,
|
||||||
|
buttonStandard.width,
|
||||||
|
buttonStandard.height,
|
||||||
|
{false,true},
|
||||||
|
1,
|
||||||
|
{
|
||||||
|
text = "Options",
|
||||||
|
color = {0,0,0.5},
|
||||||
|
color2 = {1,1,1}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
PauseExit = interfaceButton:New(
|
||||||
|
game.width/2,
|
||||||
|
game.height/2+buttonStandard.height+buttonStandard.separation,
|
||||||
|
buttonStandard.width,
|
||||||
|
buttonStandard.height,
|
||||||
|
{false,true},
|
||||||
|
1,
|
||||||
|
{
|
||||||
|
text = "Exit",
|
||||||
|
color = {0,0,0.5},
|
||||||
|
color2 = {1,1,1}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
require "data/scripts/ui/button"
|
9
main.lua
9
main.lua
|
@ -66,8 +66,6 @@ function love.update(dt)
|
||||||
fps_count = fps_count + 1
|
fps_count = fps_count + 1
|
||||||
current_dt = dt
|
current_dt = dt
|
||||||
|
|
||||||
--MenuStep
|
|
||||||
MenuStep(menuPage)
|
|
||||||
--keypressed
|
--keypressed
|
||||||
if Keybind:HasPressed(Keybind.menu.pause) then
|
if Keybind:HasPressed(Keybind.menu.pause) then
|
||||||
if do_pause then
|
if do_pause then
|
||||||
|
@ -75,10 +73,12 @@ function love.update(dt)
|
||||||
else
|
else
|
||||||
menuPage = "pauseMenu"
|
menuPage = "pauseMenu"
|
||||||
MenuInit(menuPage)
|
MenuInit(menuPage)
|
||||||
do_pause = true
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--MenuStep
|
||||||
|
if menuPage ~= nil then MenuStep(menuPage) end
|
||||||
|
|
||||||
if Keybind:HasPressed(Keybind.debug.debug) then
|
if Keybind:HasPressed(Keybind.debug.debug) then
|
||||||
if debug then
|
if debug then
|
||||||
debug = false
|
debug = false
|
||||||
|
@ -137,5 +137,8 @@ function love.draw()
|
||||||
else
|
else
|
||||||
GameDraw()
|
GameDraw()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if menuPage ~= nil then MenuDraw(menuPage) end
|
||||||
|
|
||||||
love.graphics.print(arrow,10,40)
|
love.graphics.print(arrow,10,40)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue