Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Window Scaling and Settings Menu #65

Merged
merged 10 commits into from
Mar 8, 2022
Binary file added assets/sounds/boop.mp3
Binary file not shown.
Binary file removed assets/sprites/menu.png
Binary file not shown.
Binary file removed assets/sprites/menu.png~
Binary file not shown.
Binary file added assets/sprites/menu_images/menu.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/sprites/menu_images/menu_bar.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/sprites/menu_images/settings_menu.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added assets/window_icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion conf.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function love.conf(t)
t.audio.mixwithsystem = true

t.window.title = "Spaceship Racer"
t.window.icon = nil
t.window.icon = "/assets/window_icon.png"
t.window.width = 800
t.window.height = 600
t.window.borderless = false
Expand Down
2 changes: 2 additions & 0 deletions lib/love.lua
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ local base64 = {
love.audio = {}
love.audio.newSource = function() end
love.audio.play = function() end
love.audio.setVolume = function() end

love.data = {}
love.data.decode = function(container, format, str)
Expand Down Expand Up @@ -245,5 +246,6 @@ love.physics.setMeter = function() end

love.window = {}
love.window.setMode = function() end
love.window.updateMode = function() end

return love
9 changes: 3 additions & 6 deletions main.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

local Entity = require('services/entity')
local keyboard = require('services/keyboard')
local Camera = require('services/camera')
Expand All @@ -20,7 +19,7 @@ local UpdateEntityAnimation = require('systems/UpdateEntityAnimation')
local SpaceFriction = require('systems/SpaceFriction')

love.load = function()
love.window.setMode(800, 600)
love.window.updateMode(State.camera.window_width, State.camera.window_height)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add love.window.updateMode to the mocks.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

love.graphics.setDefaultFilter('nearest', 'nearest')
textures.load()
love.globalFont = love.graphics.newFont('assets/gnevejpixel.ttf', 30)
Expand All @@ -34,9 +33,7 @@ end
-- Game time
love.keypressed = function(pressed_key)
if State.paused then
if menu.key_map[pressed_key] then
menu.key_map[pressed_key]()
end
menu.current_menu_keys(pressed_key)
else
if keyboard.key_map[pressed_key] then
keyboard.key_map[pressed_key]()
Expand All @@ -47,7 +44,7 @@ end
love.draw = function()
Camera.set()

background.draw(love.starLocations)
background.draw(love.starLocations) -- Currently bugged with how stars update to new resolution

map.draw()

Expand Down
159 changes: 87 additions & 72 deletions menu/menu.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ local mapList = require('maps/mapList')
local State = require 'services/state'
local map = require('services/map')
local shipMenu = require('menu/shipMenu')
local settingsMenu = require('menu/settingsMenu')
local save = require('services/save')
local timer = require('services/timer')

local menu = {
state = {}
}
local menu = {}

State.menu.state = nil
State.menu.blink = true

menu.up = function()
menu.mapSelect = menu.mapSelect + 1
Expand All @@ -32,7 +34,6 @@ local function displayTime()
-- Draw current time and best times.
local isNewBest = false
local convertedTime
local corner = { State.camera.pos_x, State.camera.pos_y }

-- Display either the last finish time (if map has finished) or current time.
if State.activeMap ~= -1 then
Expand All @@ -50,7 +51,7 @@ local function displayTime()
end
-- Print out times
love.graphics.print('#' .. i + 1 .. ': ' .. menu.threeBest[i + 1],
corner[1] + 448, corner[2] + 430 + (i * 45), 0, 1.5, 1.5)
menu.corner[1] + 448, menu.corner[2] + 430 + (i * 45), 0, 1.5, 1.5)
love.graphics.setColor(1, 1, 1, 1)
end

Expand All @@ -63,43 +64,68 @@ local function displayTime()
love.graphics.setColor(1, 0, 0.25, 1)
end
-- Print current time.
love.graphics.print(convertedTime, corner[1] + 550, corner[2] + 340, 0, 1.5, 1.5)
love.graphics.print(convertedTime, menu.corner[1] + 550, menu.corner[2] + 340, 0, 1.5, 1.5)
love.graphics.setColor(1, 1, 1, 1)
love.graphics.print('-----', corner[1] + 550, corner[2] + 385, 0, 1.5, 1.5)
love.graphics.print('-----', menu.corner[1] + 550, menu.corner[2] + 385, 0, 1.5, 1.5)
end
end

menu.load = function()
-- Yes, these are global variables. They will be unloaded when the menu is dismissed.
menu.titleImage = love.graphics.newImage("/assets/sprites/menu.png")
menu.titleImage = love.graphics.newImage("/assets/sprites/menu_images/menu.png")
menu.barImage = love.graphics.newImage("/assets/sprites/menu_images/menu_bar.png")
menu.blinkTimer = 0
menu.blink = true
if State.activeMap ~= -1 then
menu.mapSelect = State.activeMap
else
menu.mapSelect = 1
end
-- Alias the true corner coordinates for convienience
menu.corner = { State.camera.pos_x, State.camera.pos_y }
menu.threeBest = timer.getBestTimes(menu.mapSelect, 3)

shipMenu.load() -- Load ship menu - J.R.C 2/2/22
settingsMenu.load()

--[[ Set the current menu state to map select
menu.state values can be:
nil - no menu
map_select - main menu/map selection prior to selecting ship
ship_select - select ship prior to loading map
settings - settings menu (precedes no specific event)
]]--

-- Set the current menu state to map select
menu.state.map_select = true
menu.state.ship_select = false
menu.font = love.graphics.newFont('assets/gnevejpixel.ttf', 30)
State.menu.state = 'map_select'

menu.smallFont = love.graphics.newFont('assets/gnevejpixel.ttf', 30)
menu.bigFont = love.graphics.newFont('assets/gnevejpixel.ttf', 60)

-- Save data when opening menu since this is likely right before a player will quit.
save.write()
end

menu.unload = function()
menu.titleImage = nil
menu.barImage = nil
menu.blinkTimer = nil
menu.blink = nil
menu.mapSelect = nil
menu.threeBest = nil
menu.font = nil
menu.smallFont = nil
menu.bigFont = nil
menu.corner = nil
shipMenu.unload()
settingsMenu.unload()
end

menu.current_menu_keys = function(pressed_key)
-- Prioritize current menu's key_map, otherwise fall back on main menu key_map
if State.menu.state == 'ship_select' and shipMenu.key_map[pressed_key] then
shipMenu.key_map[pressed_key]()
elseif State.menu.state == 'settings' and settingsMenu.key_map[pressed_key] then
settingsMenu.key_map[pressed_key]()
elseif menu.key_map[pressed_key] then
menu.key_map[pressed_key]()
end
end

menu.key_map = {
Expand All @@ -119,45 +145,29 @@ menu.key_map = {
-- use ENTER to select a map and ship - J.R.C 2/7/22
p = function()
if State.activeMap ~= -1 then
menu.state.map_select = not menu.state.map_select
State.menu.state = nil
State.paused = not State.paused
end
end,
up = function()
if menu.state.map_select then
menu.up()
end
menu.up()
end,
down = function()
if menu.state.map_select then
menu.down()
end
end,
left = function()
if menu.state.ship_select then
shipMenu.left()
end
menu.down()
end,
right = function()
if menu.state.ship_select then
shipMenu.right()
end
end,
backspace = function()
if menu.state.ship_select then
menu.state.map_select = true
menu.state.ship_select = false
end
State.menu.state = 'settings'
love.audio.stop(sounds.menu_click)
love.audio.play(sounds.menu_click)
end,
['return'] = function()
if menu.state.map_select then
menu.state.map_select = false
menu.state.ship_select = true
elseif menu.state.ship_select then
if State.menu.state == 'ship_select' then
shipMenu.load_ship()
menu.load_map()
else
State.menu.state = 'ship_select'
end
end,
end
}

menu.load_map = function()
Expand Down Expand Up @@ -187,63 +197,68 @@ end

menu.draw = function()

-- Transparent red background to be displayed for all menus
love.graphics.setColor(0.1, 0.0, 0.0, 0.6)
local verticies = {
0 + menu.corner[1], 0 + menu.corner[2],
0 + menu.corner[1], State.camera.window_height + menu.corner[2],
State.camera.window_width + menu.corner[1], State.camera.window_height + menu.corner[2],
State.camera.window_width + menu.corner[1], 0 + menu.corner[2] }
love.graphics.polygon('fill', verticies)

-- Draw map select (normal menu)
if menu.state.map_select then
if State.menu.state == 'map_select' then
-- Added this because shipMenu changed the font - J.R.C
love.graphics.setFont(menu.font)
-- Alias the true corner coordinates for convienience
local corner = { State.camera.pos_x, State.camera.pos_y }

-- Transparent red background
love.graphics.setColor(0.1, 0.0, 0.0, 0.6)
local verticies = {
0 + corner[1], 0 + corner[2],
0 + corner[1], 600 + corner[2],
800 + corner[1], 600 + corner[2],
800 + corner[1], 0 + corner[2] }
love.graphics.polygon('fill', verticies)
love.graphics.setFont(menu.smallFont)

-- Draw menu image background
love.graphics.setColor(1, 1, 1, 1)
love.graphics.draw(menu.titleImage, verticies[1], verticies[2])

-- Draw text
if menu.blink then
love.graphics.print(State.credits, corner[1] + 700, corner[2] + 30)
if State.menu.blink then
love.graphics.print(State.credits, menu.corner[1] + 700, menu.corner[2] + 70)

-- Highlight map name in red if it is the active map.
if menu.mapSelect == State.activeMap then
love.graphics.setColor(1, 0, 0.25, 1)
end
love.graphics.print(mapList[menu.mapSelect].displayName, corner[1] + 55, corner[2] + 420, 0, 2, 2)
love.graphics.setFont(menu.bigFont)
love.graphics.print(mapList[menu.mapSelect].displayName, menu.corner[1] + 55, menu.corner[2] + 410)
love.graphics.setColor(1, 1, 1, 1)
end
love.graphics.print('SPACE RACE', corner[1] + 25, corner[2] + 100, 0, 2, 2)
love.graphics.print('Credits: ', corner[1] + 550, corner[2] + 30)

love.graphics.setFont(menu.bigFont)
love.graphics.print('SPACE RACE', menu.corner[1] + 25, menu.corner[2] + 110)
love.graphics.setFont(menu.smallFont)
love.graphics.print('Credits: ', menu.corner[1] + 550, menu.corner[2] + 70)

-- Draw best times and current time.
displayTime()

-- Display navigation bar
love.graphics.draw(menu.barImage, menu.corner[1], menu.corner[2])
love.graphics.setColor(1, 1, 1, 1)
love.graphics.print('Settings >>', menu.corner[1] + 690, menu.corner[2] + 8, 0, 0.5, 0.5)

-- Draw ship select Menu
elseif menu.state.ship_select then
elseif State.menu.state == 'ship_select' then
shipMenu.draw()
elseif State.menu.state == 'settings' then
settingsMenu.draw()
end

end

menu.update = function(dt)
if menu.state.map_select then
-- Blink timer for visual effect
menu.blinkTimer = menu.blinkTimer + dt
if menu.blinkTimer > 0.80 and menu.blink == true then
menu.blinkTimer = 0
menu.blink = not menu.blink
elseif menu.blinkTimer > 0.2 and menu.blink == false then
menu.blinkTimer = 0
menu.blink = not menu.blink
end
elseif menu.state.ship_select then
shipMenu.update(dt)
-- Blink timer for visual effect
menu.blinkTimer = menu.blinkTimer + dt
if menu.blinkTimer > 0.80 and State.menu.blink == true then
menu.blinkTimer = 0
State.menu.blink = not State.menu.blink
elseif menu.blinkTimer > 0.2 and State.menu.blink == false then
menu.blinkTimer = 0
State.menu.blink = not State.menu.blink
end
end

Expand Down
Loading