diff --git a/Menu/DrawMenu.lua b/Menu/DrawMenu.lua index fe6138a..96e563a 100644 --- a/Menu/DrawMenu.lua +++ b/Menu/DrawMenu.lua @@ -1,6 +1,6 @@ local function title() - local height = love.graphics.getHeight() - local width = love.graphics.getWidth() + local height = love.graphics.getHeight() / _G.Y_SCALE + local width = love.graphics.getWidth() / _G.X_SCALE love.graphics.setFont(GameFont) love.graphics.setColor(0.5, 1, 1) love.graphics.rectangle("fill", 0, 0, width, height) @@ -9,7 +9,7 @@ local function title() end function DrawMenu() - local bwidth, bheight = 300, 140 + local bwidth, bheight = 300 * _G.X_SCALE, 140 * _G.Y_SCALE title() GUI:newButton(100, 200, bwidth, bheight, "Play", MENU_POS == 0 and true or false) GUI:newButton(100, 350, bwidth, bheight, "???", MENU_POS == 1 and true or false) diff --git a/Pause/DrawPause.lua b/Pause/DrawPause.lua index bd6c992..7ebce46 100644 --- a/Pause/DrawPause.lua +++ b/Pause/DrawPause.lua @@ -1,8 +1,8 @@ function DrawPause() local opacity = 0.3 - local height = love.graphics.getHeight() - local width = love.graphics.getWidth() - local bwidth, bheight = 300, 140 + local height = love.graphics.getHeight() / _G.Y_SCALE + local width = love.graphics.getWidth() / _G.X_SCALE + local bwidth, bheight = 300 * _G.X_SCALE, 140 * _G.Y_SCALE love.graphics.setFont(GameFont) DrawGame() --Draw a single frame of the game @@ -13,7 +13,7 @@ function DrawPause() love.graphics.print("PAUSED", 100, 100) --love.graphics.print("" .. PAUSE_POS, 200,200) - GUI:newButton(100, 200, bwidth, bheight, "Return", PAUSE_POS == 0 and true or false) + GUI:newButton(100, 200, bwidth, bheight, "Back", PAUSE_POS == 0 and true or false) GUI:newButton(100, 350, bwidth, bheight, "Menu", PAUSE_POS == 1 and true or false) GUI:newButton(100, 500, bwidth, bheight, "Quit", PAUSE_POS == 2 and true or false) diff --git a/Win/DrawWin.lua b/Win/DrawWin.lua index 93b190a..aacb56b 100644 --- a/Win/DrawWin.lua +++ b/Win/DrawWin.lua @@ -1,6 +1,6 @@ local function winner() - local width = love.graphics.getWidth() - local height = love.graphics.getHeight() + local width = love.graphics.getWidth() / _G.X_SCALE + local height = love.graphics.getHeight() / _G.Y_SCALE local opacity = 0.3 local s = "" diff --git a/main.lua b/main.lua index 9aad773..75141ef 100644 --- a/main.lua +++ b/main.lua @@ -12,7 +12,10 @@ World:addCollisionClass("Player2") World:addCollisionClass("Bullet2") World:addCollisionClass("Wall") +require("gui") + require("restart") +require("truncate") require("player") require("bullet") require("mapsloader") @@ -104,10 +107,25 @@ function love.run() end end -function love.load(args) +function love.resized() + --TOD0: fix scaling! +end + +function love.load() -- Set a random seed love.math.setRandomSeed(love.timer.getTime()) + -- Figure out the X_SCALE and Y_SCALE + local curWidth, curHeight = love.graphics.getDimensions() + + print("------") + print(love.graphics.getDimensions()) + + _G.X_SCALE = truncate(curWidth / GAME_WORLD_DIM_WIDTH, 3) + _G.Y_SCALE = truncate(curHeight / GAME_WORLD_DIM_HEIGHT, 3) + print("x scale:" .. _G.X_SCALE) + print("y scale:" .. _G.Y_SCALE) + --Game values (reset after each load) HEALTH = 3 P1_DELAY = 0.5 @@ -127,6 +145,7 @@ function love.load(args) KeyDelay2 = P2_DELAY local playerSpeed = 12000 + --TODO: two player speeds for upgrades UserPlayer1 = Player(1, 1000, 100, HEALTH, "assets/player1.png", playerSpeed) UserPlayer2 = Player(2, 200, 300, HEALTH, "assets/player2.png", playerSpeed) @@ -153,7 +172,7 @@ function love.update(dt) if _G.GAMESTATE == "MENU" then UpdateMenu(dt) -- Handle music - if not musicMenu:isPlaying() then + if not musicMenu:isPlaying() and not _G.MUTED then musicMenu:setVolume(0.5) love.audio.play(musicMenu) end @@ -161,7 +180,7 @@ function love.update(dt) if _G.GAMESTATE == "PAUSE" then UpdatePause(dt) -- Handle music - if not musicPause:isPlaying() then + if not musicPause:isPlaying() and not _G.MUTED then musicBattle:setVolume(0) musicPause:setVolume(0.5) love.audio.play(musicBattle) @@ -171,7 +190,7 @@ function love.update(dt) if _G.GAMESTATE == "GAME" then UpdateGame(dt) -- Handle music - if not musicBattle:isPlaying() then + if not musicBattle:isPlaying() and not _G.MUTED then musicBattle:setVolume(0.5) musicPause:setVolume(0) love.audio.play(musicBattle) @@ -192,11 +211,6 @@ function love.draw() end if _G.GAMESTATE == "GAME" then DrawGame() - if DebugFlag then - love.graphics.setFont(DebugFont) - love.graphics.print("Debug Mode", 1200, 850) - love.graphics.print("" .. GAMESTATE, 200, 200) - end end if _G.GAMESTATE == "WIN" then DrawWin()