diff --git a/assets/sounds/boop.mp3 b/assets/sounds/boop.mp3 new file mode 100644 index 0000000..44256ae Binary files /dev/null and b/assets/sounds/boop.mp3 differ diff --git a/assets/sprites/menu.png b/assets/sprites/menu.png deleted file mode 100644 index 2e6aaa6..0000000 Binary files a/assets/sprites/menu.png and /dev/null differ diff --git a/assets/sprites/menu.png~ b/assets/sprites/menu.png~ deleted file mode 100644 index 2e6aaa6..0000000 Binary files a/assets/sprites/menu.png~ and /dev/null differ diff --git a/assets/sprites/menu_images/menu.png b/assets/sprites/menu_images/menu.png new file mode 100644 index 0000000..8446486 Binary files /dev/null and b/assets/sprites/menu_images/menu.png differ diff --git a/assets/sprites/menu_images/menu_bar.png b/assets/sprites/menu_images/menu_bar.png new file mode 100644 index 0000000..af6fa66 Binary files /dev/null and b/assets/sprites/menu_images/menu_bar.png differ diff --git a/assets/sprites/menu_images/settings_menu.png b/assets/sprites/menu_images/settings_menu.png new file mode 100644 index 0000000..7e44c35 Binary files /dev/null and b/assets/sprites/menu_images/settings_menu.png differ diff --git a/assets/sprites/ship_menu/ship_menu.png b/assets/sprites/menu_images/ship_menu.png similarity index 100% rename from assets/sprites/ship_menu/ship_menu.png rename to assets/sprites/menu_images/ship_menu.png diff --git a/assets/window_icon.png b/assets/window_icon.png new file mode 100644 index 0000000..7d7dbc5 Binary files /dev/null and b/assets/window_icon.png differ diff --git a/conf.lua b/conf.lua index 073b275..c1be378 100644 --- a/conf.lua +++ b/conf.lua @@ -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 diff --git a/lib/love.lua b/lib/love.lua index 90052db..e86e79f 100644 --- a/lib/love.lua +++ b/lib/love.lua @@ -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) @@ -245,5 +246,6 @@ love.physics.setMeter = function() end love.window = {} love.window.setMode = function() end +love.window.updateMode = function() end return love diff --git a/main.lua b/main.lua index 2b13cad..8853d5f 100644 --- a/main.lua +++ b/main.lua @@ -1,4 +1,3 @@ - local Entity = require('services/entity') local keyboard = require('services/keyboard') local Camera = require('services/camera') @@ -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) love.graphics.setDefaultFilter('nearest', 'nearest') textures.load() love.globalFont = love.graphics.newFont('assets/gnevejpixel.ttf', 30) @@ -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]() @@ -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() diff --git a/menu/menu.lua b/menu/menu.lua index 4671afb..84d0f4d 100644 --- a/menu/menu.lua +++ b/menu/menu.lua @@ -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 @@ -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 @@ -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 @@ -63,30 +64,41 @@ 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() @@ -94,12 +106,26 @@ 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 = { @@ -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() @@ -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 diff --git a/menu/settingsMenu.lua b/menu/settingsMenu.lua new file mode 100644 index 0000000..7076f50 --- /dev/null +++ b/menu/settingsMenu.lua @@ -0,0 +1,198 @@ +local sounds = require('services/sounds') +local State = require 'services/state' +local save = require('services/save') +local camera = require('services/camera') + +local settingsMenu = {} + +-- Next section: Actions + +settingsMenu.key_map = { + up = function() + -- Loop up the list of settings + settingsMenu.selection = settingsMenu.selection + 1 + if settingsMenu.selection > #settingsMenu.options then + settingsMenu.selection = 1 + end + settingsMenu.ready = false + love.audio.stop(sounds.boop) + love.audio.play(sounds.boop) + end, + down = function() + -- Loop down the list of settings + settingsMenu.selection = settingsMenu.selection - 1 + if settingsMenu.selection < 1 then + settingsMenu.selection = #settingsMenu.options + end + settingsMenu.ready = false + love.audio.stop(sounds.boop) + love.audio.play(sounds.boop) + end, + left = function() + -- Decrement settings value, else if player is not entering values leave the settings menu. + -- If setting a setting, set the setting with the setting set + if settingsMenu.ready then + -- Change value and take a sanity check + local setting = settingsMenu.options[settingsMenu.selection] + setting.value = setting.value - setting.increment + if setting.value < setting.min then + setting.value = setting.min + end + -- Play essential sound effects + love.audio.stop(sounds.boop) + love.audio.play(sounds.boop) + else + -- If not setting a setting, leave + settingsMenu.backToMainMenu() + end + end, + right = function() + -- If player is entering values, increment settings value + if settingsMenu.ready then + local setting = settingsMenu.options[settingsMenu.selection] + setting.value = setting.value + setting.increment + if setting.value > setting.max then + setting.value = setting.max + end + love.audio.stop(sounds.boop) + love.audio.play(sounds.boop) + end + end, + escape = function() + -- Alternate way of unreadying/leaving settings menu + if settingsMenu.ready == true then + settingsMenu.ready = false + settingsMenu.updateSettings() + elseif settingsMenu.ready == false then + settingsMenu.backToMainMenu() + end + end, + backspace = function() + -- Another alternate way to leave settings menu + settingsMenu.key_map.escape() + end, + ['return'] = function() + -- Player must press enter to enable setting changes + settingsMenu.ready = not settingsMenu.ready + if settingsMenu.ready == false then + settingsMenu.updateSettings() + end + end +} + +settingsMenu.updateSettings = function() + if settingsMenu.options[1].value ~= State.camera.scale_x then + camera.resize(settingsMenu.options[1].value) + end + State.volume = settingsMenu.options[2].value / 100 + love.audio.setVolume(State.volume) + + love.audio.stop(sounds.menu_click) + love.audio.play(sounds.menu_click) + + settingsMenu.ready = false -- Don't ask +end + +settingsMenu.backToMainMenu = function() + love.audio.stop(sounds.menu_click) + love.audio.play(sounds.menu_click) + State.menu.state = 'map_select' + save.write() +end + +-- Next section: Loading + +settingsMenu.load = function() + settingsMenu.titleImage = love.graphics.newImage("/assets/sprites/menu_images/settings_menu.png") + settingsMenu.barImage = love.graphics.newImage("/assets/sprites/menu_images/menu_bar.png") + settingsMenu.bigFont = love.graphics.newFont('assets/gnevejpixel.ttf', 90) + settingsMenu.mediumFont = love.graphics.newFont('assets/gnevejpixel.ttf', 60) + settingsMenu.smallFont = love.graphics.newFont('assets/gnevejpixel.ttf', 30) + settingsMenu.selection = 1 + settingsMenu.ready = false + + settingsMenu.options = { + [1] = { + name = 'Resolution', + value = State.camera.scale_x, + increment = 0.1, + min = 1, + max = 10 + }, + [2] = { + name = 'Volume', + value = State.volume * 100, + increment = 10, + min = 0, + max = 100 + } + } +end + +settingsMenu.unload = function() + settingsMenu.bigFont = nil + settingsMenu.mediumFont = nil + settingsMenu.smallFont = nil + settingsMenu.options = nil + settingsMenu.selection = nil + settingsMenu.ready = nil + settingsMenu.titleImage = nil + settingsMenu.barImage = nil +end + + +-- Next section: Drawing + +settingsMenu.draw = function() + -- Alias the true corner coordinates for convienience + local corner = { State.camera.pos_x, State.camera.pos_y } + local unit = '' + love.graphics.setColor(1, 1, 1, 1) + + -- Short message and fancy graphic before the actual settings stuff + love.graphics.setColor(1, 1, 1, 1) + love.graphics.draw(settingsMenu.titleImage, corner[1], corner[2] + 375) + love.graphics.setFont(settingsMenu.mediumFont) + local settingsMessage = 'Use arrow keys and enter key \nto adjust settings' + love.graphics.print(settingsMessage, corner[1] + 50, corner[2] + 500, 0, 0.5, 0.5) + + -- Begin actual settings stuff + for i = 0, 1 do + -- Display current selection in gold, or green if currently setting the setting + if i + 1 == settingsMenu.selection then + if settingsMenu.ready then + love.graphics.setColor(1, 0, 0, 1) + else + love.graphics.setColor(255, 215, 0, 1) + end + else + love.graphics.setColor(1, 1, 1, 1) + end + + -- Draw settings + + -- Give appropriate unit to the setting + if settingsMenu.options[i + 1].name == 'Resolution' then + unit = 'x' + elseif settingsMenu.options[i + 1].name == 'Volume' then + unit = '%' + end + + love.graphics.setFont(settingsMenu.bigFont) + love.graphics.print(settingsMenu.options[i + 1].name, corner[1] + 50, corner[2] + 60 + (210 * i)) + love.graphics.setFont(settingsMenu.mediumFont) + love.graphics.print(settingsMenu.options[i + 1].value .. unit, corner[1] + 50, corner[2] + 160 + (210 * i)) + end + + -- Draw navigation bar + love.graphics.setFont(settingsMenu.smallFont) + love.graphics.draw(settingsMenu.barImage, corner[1], corner[2]) + love.graphics.setColor(1, 1, 1, 1) + love.graphics.print('<< Main Menu ', corner[1] + 10, corner[2] + 8, 0, 0.5, 0.5) +end + +settingsMenu.update = function() + -- Nothing for now! +end + +return settingsMenu diff --git a/menu/shipMenu.lua b/menu/shipMenu.lua index 1c178cc..b4ab561 100644 --- a/menu/shipMenu.lua +++ b/menu/shipMenu.lua @@ -33,32 +33,39 @@ local function get_right() return shipList[right_index] end -ship_menu.right = function() - - if ship_menu.shipSelect >= #shipList then - ship_menu.shipSelect = 1 - else - ship_menu.shipSelect = ship_menu.shipSelect + 1 - end - love.audio.stop() - love.audio.play(sounds.menu_click) -end - -ship_menu.left = function() - if ship_menu.shipSelect <= 1 then - ship_menu.shipSelect = #shipList - else - ship_menu.shipSelect = ship_menu.shipSelect - 1 +ship_menu.key_map = { + escape = function() + -- Go back to main menu + State.menu.state = 'map_select' + end, + backspace = function() + -- See above + State.menu.state = 'map_select' + end, + right = function() + if ship_menu.shipSelect >= #shipList then + ship_menu.shipSelect = 1 + else + ship_menu.shipSelect = ship_menu.shipSelect + 1 + end + love.audio.stop() + love.audio.play(sounds.menu_click) + end, + left = function() + if ship_menu.shipSelect <= 1 then + ship_menu.shipSelect = #shipList + else + ship_menu.shipSelect = ship_menu.shipSelect - 1 + end + love.audio.stop() + love.audio.play(sounds.menu_click) end - love.audio.stop() - love.audio.play(sounds.menu_click) -end +} ship_menu.load = function() -- Yes, these are global variables. They will be unloaded when the ship_menu is dismissed. - ship_menu.titleImage = love.graphics.newImage("assets/sprites/ship_menu/ship_menu.png") - ship_menu.blinkTimer = 0 - ship_menu.blink = true + ship_menu.titleImage = love.graphics.newImage("assets/sprites/menu_images/ship_menu.png") + State.menu.blink = true ship_menu.shipSelect = State.activeShip ship_menu.title_font = love.graphics.newFont('assets/gnevejpixel.ttf', 30) @@ -68,8 +75,6 @@ end ship_menu.unload = function() -- ship_menu.titleImage = nil - ship_menu.blinkTimer = nil - ship_menu.blink = nil ship_menu.shipSelect = nil ship_menu.title_font = nil @@ -79,7 +84,7 @@ end ship_menu.load_ship = function() State.activeShip = ship_menu.shipSelect - State.shipMenu = not State.shipMenu + State.menu.state = nil love.audio.play(sounds.chirp_down) end @@ -87,21 +92,12 @@ ship_menu.draw = function() -- 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) - -- Draw ship_menu image background love.graphics.setColor(1, 1, 1, 1) - love.graphics.draw(ship_menu.titleImage, verticies[1], verticies[2]) + love.graphics.draw(ship_menu.titleImage, corner[1], corner[2]) -- Draw text - if ship_menu.blink then + if State.menu.blink then love.graphics.setFont(ship_menu.font) local name = shipList[ship_menu.shipSelect].displayName love.graphics.printf(name, corner[1] + 208 / 2, corner[2] + 143, 300, "center", 0, 2, 2) @@ -139,7 +135,7 @@ ship_menu.draw = function() local shift_y = image:getPixelHeight() * (center_scale_y) / 2 -- Draw blinking Square around currently selected ship - if ship_menu.blink then + if State.menu.blink then love.graphics.setColor(1, 0, 0, 1) love.graphics.rectangle("line", corner[1] + 400 - shift_x - 10, corner[2] + 200 + shift_y - 10, 148, 148) @@ -297,16 +293,8 @@ ship_menu.draw = function() end end -ship_menu.update = function(dt) - -- Blink timer for visual effect - ship_menu.blinkTimer = ship_menu.blinkTimer + dt - if ship_menu.blinkTimer > 0.40 and ship_menu.blink == true then - ship_menu.blinkTimer = 0 - ship_menu.blink = not ship_menu.blink - elseif ship_menu.blinkTimer > 0.2 and ship_menu.blink == false then - ship_menu.blinkTimer = 0 - ship_menu.blink = not ship_menu.blink - end +ship_menu.update = function() + -- nothing for now! end return ship_menu diff --git a/services/camera.lua b/services/camera.lua index 5e38722..abc1913 100644 --- a/services/camera.lua +++ b/services/camera.lua @@ -12,10 +12,10 @@ State.camera.pos_y = 0 * .5 State.camera.rotation = 0 State.camera.scale_x = 1 State.camera.scale_y = 1 -State.camera.window_width, State.camera.window_height = love.graphics:getDimensions() +State.camera.window_width, State.camera.window_height = 800, 600 -local window_width = State.camera.window_width / State.camera.scale_x -local window_height = State.camera.window_height / State.camera.scale_y +local window_width = State.camera.window_width +local window_height = State.camera.window_height -- https://love2d.org/wiki/FilterMode love.graphics.setDefaultFilter('nearest', 'nearest') @@ -44,6 +44,16 @@ local move = function(dx, dy) State.camera.pos_y = State.camera.pos_y + (dy or 0) end +local resize = function(dx) + State.camera.scale_x = dx + State.camera.scale_y = dx + + State.camera.window_width = 800 * dx + State.camera.window_height = 600 * dx + love.window.updateMode(State.camera.window_width, State.camera.window_height) +end + + local rotate = function(dr) State.camera.rotation = State.camera.rotation + dr end @@ -76,6 +86,7 @@ return { get_boundary_top = get_boundary_top, get_position = get_position, move = move, + resize = resize, rotate = rotate, set = set, set_position = set_position, diff --git a/services/save.lua b/services/save.lua index 05ff688..01a9063 100644 --- a/services/save.lua +++ b/services/save.lua @@ -1,6 +1,7 @@ local state = require('services/state') local Serialize = require('lib/serialize') local timer = require('services/timer') +local camera = require('services/camera') local save = {} @@ -29,6 +30,9 @@ save.read = function() state.credits = data.credits or 0 timer.timesTable = data.times or {} state.activeShip = data.lastShip or 1 + camera.resize(data.windowScale or 1) + state.volume = data.volume or 1; love.audio.setVolume(state.volume) + -- Check for errors else @@ -49,6 +53,8 @@ save.write = function() data.credits = state.credits data.times = timer.timesTable data.lastShip = state.activeShip + data.windowScale = state.camera.scale_x + data.volume = state.volume -- Serialize data local serializedData = Serialize(data) diff --git a/services/sounds.lua b/services/sounds.lua index 9c7344a..91a8072 100644 --- a/services/sounds.lua +++ b/services/sounds.lua @@ -5,8 +5,8 @@ sounds.engine = love.audio.newSource('/assets/sounds/engine_normal.mp3', 'stream sounds.braking = love.audio.newSource('/assets/sounds/engine_braking.mp3', 'stream') sounds.chirp_up = love.audio.newSource('/assets/sounds/chirp_up.mp3', 'stream') sounds.chirp_down = love.audio.newSource('/assets/sounds/chirp_down.mp3', 'stream') - sounds.menu_click = love.audio.newSource('/assets/sounds/Flashpoint001d.flac', 'stream') +sounds.boop = love.audio.newSource('/assets/sounds/boop.mp3', 'stream') --[[ Flashpoint001d.flac diff --git a/services/state.lua b/services/state.lua index 7c890ee..95f5d62 100644 --- a/services/state.lua +++ b/services/state.lua @@ -6,8 +6,9 @@ State.paused = true State.debugOn = false State.activeMap = -1 +State.menu = {} -- Initialized in /menu/menu.lua + -- Ship stuff duh - J.R.C 2/2/22 -State.shipMenu = false; State.activeShip = 1 State.camera = {} -- Initialized in /camera.lua @@ -18,6 +19,8 @@ State.seconds = 0 -- Keep track of map times. State.lastCompletedTime = 0 State.world = love.physics.newWorld(0, 0) +State.volume = 1 + State.world:setCallbacks(world.begin_contact_callback, world.end_contact_callback, world.pre_solve_callback, nil) diff --git a/systems/CompleteLevel.lua b/systems/CompleteLevel.lua index 3e35f1b..8dc76b3 100644 --- a/systems/CompleteLevel.lua +++ b/systems/CompleteLevel.lua @@ -16,8 +16,6 @@ return System( State.paused = true love.audio.stop() love.audio.play(Sounds.chirp_up) - Menu.state.map_select = true - Menu.state.ship_select = false Menu.load() Map.loadMap(-1) end diff --git a/systems/DebugPlayer.lua b/systems/DebugPlayer.lua index 2edabb0..54234b4 100644 --- a/systems/DebugPlayer.lua +++ b/systems/DebugPlayer.lua @@ -21,6 +21,7 @@ local function debug(entity) print('=================================') end if State.debugOn then + love.graphics.setNewFont('assets/gnevejpixel.ttf', 30) local pos_x = State.camera.pos_x local pos_y = State.camera.pos_y love.graphics.setColor({ 1, 1, 1, 1 }) @@ -44,6 +45,14 @@ local function debug(entity) love.graphics.setColor({ 1, 0, 0, 1 }) love.graphics.line(entity.body:getX(), entity.body:getY(), velocityArrowX,velocityArrowY) love.graphics.setColor({ 1, 1, 1, 1 }) -- Added this line to fix sprite drawing as red - J.R.C 2/2/22 + + -- Window debug information + love.graphics.setColor({ 1, 0, 1, 1 }) + love.graphics.line(pos_x, pos_y + 300, pos_x + 800, pos_y + 300) + love.graphics.line(pos_x + 400, pos_y, pos_x + 400, pos_y + 600) + + love.graphics.setColor({ 1, 1, 1, 1 }) + love.graphics.circle('fill', 400 + State.camera.pos_x, 300 + State.camera.pos_y, 5) end end