Renamed pause.lua to ui.lua; adjusted accordingly.

This commit is contained in:
lustlion 2022-01-21 15:56:25 +01:00
parent 9e43b02620
commit f4b44dc7bc
10 changed files with 121 additions and 75 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

View File

@ -17,8 +17,7 @@ require "data/scripts/objects"
-- UI functions
require "data/scripts/debug"
require "data/scripts/keybind"
require "data/scripts/pause"
require "data/scripts/ui/button"
require "data/scripts/ui"
-- game loop
require "data/scripts/game"
require "data/scripts/gameworld"

View File

@ -32,6 +32,12 @@ function DebugColisions()
end
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
-- draw center GREEN
love.graphics.setColor(0,1,0)

View File

@ -13,8 +13,9 @@ Particle = Entity:New(x,y)
o.sprite_scale = particle_data.sprite_scale or o.sprite_scale
o.sprite_tint = particle_data.sprite_tint or o.sprite_tint
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.time = 0.5
@ -63,7 +64,7 @@ end
function Particle:HandleAnimation()
self.body:Animate()
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
self.light.range = self.lightRange * self.sprite_alpha/2
end

View File

@ -129,6 +129,7 @@ function Player:DoPhysics()
local particle_data = {
animation = self.body,
sprite_tint = HEX2RGB("#fed100"),
sprite_alpha = 0.5,
sprite_flip = {
x = self.sprite_flip.x,
y = self.sprite_flip.y

View File

@ -29,6 +29,4 @@ function GameDraw()
DebugColisions()
DebugEntities()
end
-- pause
if do_pause then PauseUI() end
end

View File

@ -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

104
data/scripts/ui.lua Normal file
View File

@ -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"

View File

@ -66,8 +66,6 @@ function love.update(dt)
fps_count = fps_count + 1
current_dt = dt
--MenuStep
MenuStep(menuPage)
--keypressed
if Keybind:HasPressed(Keybind.menu.pause) then
if do_pause then
@ -75,10 +73,12 @@ function love.update(dt)
else
menuPage = "pauseMenu"
MenuInit(menuPage)
do_pause = true
end
end
--MenuStep
if menuPage ~= nil then MenuStep(menuPage) end
if Keybind:HasPressed(Keybind.debug.debug) then
if debug then
debug = false
@ -137,5 +137,8 @@ function love.draw()
else
GameDraw()
end
if menuPage ~= nil then MenuDraw(menuPage) end
love.graphics.print(arrow,10,40)
end