diff --git a/Autarky2/Autarky2.love b/Autarky2/Autarky2.love index 1963ba7..96b0f79 100644 Binary files a/Autarky2/Autarky2.love and b/Autarky2/Autarky2.love differ diff --git a/Autarky2/constants.lua b/Autarky2/constants.lua index bbfb95f..bad024d 100644 --- a/Autarky2/constants.lua +++ b/Autarky2/constants.lua @@ -15,7 +15,7 @@ function constants.load() TRANSLATEX = cf.round(SCREEN_WIDTH / 2) -- starts the camera in the middle of the ocean TRANSLATEY = cf.round(SCREEN_HEIGHT / 2) -- need to round because this is working with pixels - ZOOMFACTOR = 1 + ZOOMFACTOR = 0.95 GAME_LOG_DRAWX = SCREEN_WIDTH - 275 MAP = {} @@ -25,6 +25,9 @@ function constants.load() MOUSE_DOWN_X = nil MOUSE_DOWN_Y = nil + MOUSE_DOWN_X = nil + MOUSE_DOWN_Y = nil + SCREEN_STACK = {} IMAGES = {} SPRITES = {} diff --git a/Autarky2/draw.lua b/Autarky2/draw.lua index b0de48b..d7cbda6 100644 --- a/Autarky2/draw.lua +++ b/Autarky2/draw.lua @@ -1,5 +1,26 @@ draw = {} +function draw.topBar() + -- draw world hours + love.graphics.setColor(1,1,1,1) + local str = "Time: " .. WORLD_HOURS .. ":00 Day: " .. WORLD_DAYS .. " Treasury: $" .. TREASURY .. " " + if PAUSED then str = str .. "PAUSED" end + love.graphics.print(str, 10, 10) + + -- draw villager counts + local occupationtable = people.getOccupationCount() + local str = "Farmers: " .. occupationtable[enum.jobFarmer] .. ". " + str = str .. "Healers: " .. occupationtable[enum.jobHealer] .. ". " + str = str .. "Woodsmen: " .. occupationtable[enum.jobWoodsman] .. ". " + str = str .. "Builders: " .. occupationtable[enum.jobBuilder] .. ". " + love.graphics.print(str, (SCREEN_WIDTH / 2) - 250, 10) + + -- draw more counts on the far right margin + local str = "Villagers available: " .. #PERSONS .. " Villagers quit: " .. PERSONS_LEFT + love.graphics.print(str, SCREEN_WIDTH - 300, 10) + +end + function draw.world() -- draw the map including structures @@ -12,8 +33,6 @@ function draw.world() for col = 1, NUMBER_OF_COLS do for row = 1, NUMBER_OF_ROWS do - -- drawx = LEFT_MARGIN + (col -1) * TILE_SIZE - -- drawy = TOP_MARGIN + (row - 1) * TILE_SIZE local drawx, drawy = fun.getTileXY(row, col) -- the grid border/outline @@ -44,25 +63,6 @@ function draw.world() end end - -- draw world hours - love.graphics.setColor(1,1,1,1) - local str = "Time: " .. WORLD_HOURS .. ":00 Day: " .. WORLD_DAYS .. " Treasury: $" .. TREASURY .. " " - if PAUSED then str = str .. "PAUSED" end - love.graphics.print(str, 10, 10) - - -- draw villager counts - local occupationtable = people.getOccupationCount() - local str = "Farmers: " .. occupationtable[enum.jobFarmer] .. ". " - str = str .. "Healers: " .. occupationtable[enum.jobHealer] .. ". " - str = str .. "Woodsmen: " .. occupationtable[enum.jobWoodsman] .. ". " - str = str .. "Builders: " .. occupationtable[enum.jobBuilder] .. ". " - love.graphics.print(str, (SCREEN_WIDTH / 2) - 250, 10) - - -- draw more counts on the far right margin - local str = "Villagers available: " .. #PERSONS .. " Villagers quit: " .. PERSONS_LEFT - love.graphics.print(str, SCREEN_WIDTH - 300, 10) - - end function draw.daynight() @@ -214,6 +214,8 @@ function draw.graphs() local yvalue = drawy - HISTORY_PRICE[enum.stockHerbs][i] love.graphics.points(drawx, yvalue) end + + love.graphics.print("Press ESCAPE to exit", SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2) end function draw.imageQueue() @@ -235,22 +237,25 @@ function draw.imageQueue() end function draw.optionScreen() - tax_rate_up_button:show() - tax_rate_down_button:show() - close_options_button:show() - exit_game_button:hide() - - love.graphics.setColor(1,1,1,1) - love.graphics.print(SALES_TAX, 300, 415) + -- tax_rate_up_button:show() + -- tax_rate_down_button:show() + -- close_options_button:show() + -- exit_game_button:hide() + -- + -- love.graphics.setColor(1,1,1,1) + -- love.graphics.print(SALES_TAX, 300, 415) + + love.graphics.print("Press ESCAPE to exit", SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2) + end -function draw.exitScreen() +function draw.exitScreen() tax_rate_up_button:hide() tax_rate_down_button:hide() close_options_button:hide() - exit_game_button:show() - + love.graphics.print("Press ENTER to exit", SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2) + end return draw diff --git a/Autarky2/functions.lua b/Autarky2/functions.lua index 3220c53..ab9c795 100644 --- a/Autarky2/functions.lua +++ b/Autarky2/functions.lua @@ -101,6 +101,8 @@ function functions.getTileXY(row, col) end function functions.getDrawXY(person) + -- returns the screen x/y + -- used to detect mouse interactions local row = person.row local col = person.col local x = person.x diff --git a/Autarky2/gui.lua b/Autarky2/gui.lua index f3ee2d6..50d14a7 100644 --- a/Autarky2/gui.lua +++ b/Autarky2/gui.lua @@ -23,7 +23,12 @@ function gui.load() if SALES_TAX < 0 then SALES_TAX = 0 end end - exit_game_button = gspot:button('Exit game', {x = 225, y = 400, w = 50, h = gspot.style.unit}) + local y = SCREEN_HEIGHT / 2 + local w = 100 + local x = (SCREEN_WIDTH / 2) - (w / 2) + + exit_game_button = gspot:button('Exit game', {x = x, y = y, w = w, h = gspot.style.unit * 2}) + exit_game_button.click = function(this, x, y, button) cf.RemoveScreen(SCREEN_STACK) --! can invoke the 'quit' option here for safety diff --git a/Autarky2/lib/resolution_solution.lua b/Autarky2/lib/resolution_solution.lua index eb9b29b..7ca1432 100644 --- a/Autarky2/lib/resolution_solution.lua +++ b/Autarky2/lib/resolution_solution.lua @@ -9,31 +9,31 @@ local rs = { _NAME = "Resolution Solution", _LICENSE = "The Unlicense", _LICENSE_TEXT = [[ -This is free and unencumbered software released into the public domain. - -Anyone is free to copy, modify, publish, use, compile, sell, or -distribute this software, either in source code form or as a compiled -binary, for any purpose, commercial or non-commercial, and by any -means. - -In jurisdictions that recognize copyright laws, the author or authors -of this software dedicate any and all copyright interest in the -software to the public domain. We make this dedication for the benefit -of the public at large and to the detriment of our heirs and -successors. We intend this dedication to be an overt act of -relinquishment in perpetuity of all present and future rights to this -software under copyright law. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, -EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF -MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. -IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR -OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, -ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR -OTHER DEALINGS IN THE SOFTWARE. - -For more information, please refer to -]] + This is free and unencumbered software released into the public domain. + + Anyone is free to copy, modify, publish, use, compile, sell, or + distribute this software, either in source code form or as a compiled + binary, for any purpose, commercial or non-commercial, and by any + means. + + In jurisdictions that recognize copyright laws, the author or authors + of this software dedicate any and all copyright interest in the + software to the public domain. We make this dedication for the benefit + of the public at large and to the detriment of our heirs and + successors. We intend this dedication to be an overt act of + relinquishment in perpetuity of all present and future rights to this + software under copyright law. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, + EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR + OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, + ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR + OTHER DEALINGS IN THE SOFTWARE. + + For more information, please refer to + ]] } -- Callback functions, that will be triggered when window size is changed @@ -114,7 +114,7 @@ rs.update = function() -- scale for game virtual size local scaleWidth, scaleHeight - + -- offset for black bars local xOff, yOff @@ -126,110 +126,110 @@ rs.update = function() -- get aspect of window and virtual game size local gameAspect = gameWidth / gameHeight local windowAspect = windowWidth / windowHeight - + -- check rs.gameChanged() callback local oldGameAspect = rs.gameAspect - + -- check rs.windowChanged() callback local oldWindowAspect = rs.windowAspect - + -- scale mode local scaleMode = rs.scaleMode - + -- Game zone local gameZone = rs.gameZone - + if scaleMode == 1 then -- if window height > game height; create black bars on top and bottom if gameAspect > windowAspect then local scale = windowWidth / gameWidth - + local barHeight = math.abs((gameHeight * scale - windowHeight) / 2) - + scaleWidth, scaleHeight = scale, scale - + x1, y1, w1, h1 = 0, 0, windowWidth, barHeight x2, y2, w2, h2 = 0, windowHeight, windowWidth, barHeight * -1 - + xOff, yOff = 0, windowHeight / 2 - (scale * gameHeight) / 2 -- if window width > game width; create bars on left and right sides elseif gameAspect < windowAspect then local scale = windowHeight / gameHeight - + local barWidth = math.abs((gameWidth * scale - windowWidth) / 2) - + scaleWidth, scaleHeight = scale, scale - + x1, y1, w1, h1 = 0, 0, barWidth, windowHeight x2, y2, w2, h2 = windowWidth, 0, barWidth * -1, windowHeight - + xOff = windowWidth / 2 - (scale * gameWidth) / 2 yOff = 0 else -- if window and game size equal scaleWidth, scaleHeight = 1, 1 - + x1, y1, w1, h1 = 0, 0, 0, 0 x2, y2, w2, h2 = 0, 0, 0, 0 - + xOff, yOff = 0, 0 end -- end aspect scaling method end -- end scaleMode == 1 - + -- stretch scaling method; 2 which fills entire window if scaleMode == 2 then - + scaleWidth = windowWidth / gameWidth scaleHeight = windowHeight / gameHeight - + x1, y1, w1, h1 = 0, 0, 0, 0 x2, y2, w2, h2 = 0, 0, 0, 0 - + xOff, yOff = 0, 0 - + --[[ centerX, centerY = gam topLeft, topRight = 0 bottomLeft, bottomRight = 0 - leftCenterX, rightCenterX = - topCenterY, bottomCenterY = + leftCenterX, rightCenterX = + topCenterY, bottomCenterY = --]] - + end -- end stretch scaling method -- write all changes to library - + -- black bars rs.x1, rs.y1, rs.w1, rs.h1 = x1, y1, w1, h1 rs.x2, rs.y2, rs.w2, rs.h2 = x2, y2, w2, h2 - + -- offset generated for black bars rs.xOff, rs.yOff = xOff, yOff - + -- scale rs.scaleWidth, rs.scaleHeight = scaleWidth, scaleHeight - + -- window size rs.windowWidth, rs.windowHeight = windowWidth, windowHeight - + -- aspects rs.gameAspect, rs.windowAspect = gameAspect, windowAspect - + -- game zone - + gameZone.x = xOff gameZone.y = yOff gameZone.w = windowWidth - (xOff * 2) gameZone.h = windowHeight - (yOff * 2) - + -- Call rs.gameChanged() if virtual game size is changed if oldGameAspect ~= gameAspect then rs.gameChanged() end - + -- Call rs.windowChanged() if window size is changed if oldWindowAspect ~= windowAspect then rs.windowChanged() @@ -240,16 +240,16 @@ end rs.start = function() -- Start scaling graphics until rs.stop(). -- Everything inside this function will be scaled to fit virtual game size - + -- prepare to scale love.graphics.push() - + -- reset transformation love.graphics.origin() -- set offset, based on size of black bars love.graphics.translate(rs.xOff, rs.yOff) - + -- scale game love.graphics.scale(rs.scaleWidth, rs.scaleHeight) end @@ -257,7 +257,7 @@ end rs.stop = function() -- Stop scaling caused by rs.start() -- and draw black bars, if needed. - + -- stop scaling love.graphics.pop() @@ -267,10 +267,10 @@ end -- end rs.stop rs.unscaleStart = function() -- Reset scaling with love.origin() until rs.unscaleStop(). -- With that you can, for example, draw ui with custom scaling. - + -- start unscaling love.graphics.push() - + -- reset coordinates and scaling love.graphics.origin() end @@ -278,7 +278,7 @@ end rs.unscaleStop = function() -- Stop scaling caused by rs.unscaleStart(). -- With that you can, for example, draw ui with custom scaling. - + -- stop unscaling love.graphics.pop() end @@ -323,18 +323,18 @@ rs.drawBlackBars = function() -- Function that will draw back bars. -- Can be called outside of rs.start rs.stop. -- Might be useful when you need just to draw black bars, without scaling via rs.start. - + -- do nothing if we don't need draw bars or we in aspect scaling mode (1; with black bars) if not rs.drawBars or rs.scaleMode ~= 1 then return end - + -- get colors, that was before rs.stop() function local r, g, b, a = love.graphics.getColor() - + -- prepare to draw black bars love.graphics.push() - + -- reset transformation love.graphics.origin() @@ -345,10 +345,10 @@ rs.drawBlackBars = function() love.graphics.rectangle("fill", rs.x1, rs.y1, rs.w1, rs.h1) -- draw right or bottom most love.graphics.rectangle("fill", rs.x2, rs.y2, rs.w2, rs.h2) - + -- return original colors that was before rs.stop() love.graphics.setColor(r, g, b, a) - + -- end black bars rendering love.graphics.pop() end @@ -361,7 +361,7 @@ end rs.switchScaleMode = function() -- Function to switch in-between scale modes. - if rs.scaleMode ~= 1 then + if rs.scaleMode ~= 1 then rs.scaleMode = 1 -- aspect mode else rs.scaleMode = 2 -- stretch mode @@ -389,7 +389,7 @@ end rs.switchDrawBars = function() -- Turn of/off rendering for black bars. - + rs.drawBars = not rs.drawBars end @@ -403,17 +403,17 @@ rs.isMouseInside = function() if rs.scaleMode == 2 then return true end - + -- get mouse coordinates local mouseX, mouseY = love.mouse.getPosition() - + -- get offset -- also, as will be mentioned in rs.toGame, there will some rounding/missmath with float coordinates; -- rs.toGame don't do anything with that, you should take care about this, but here -- for convenience, this function simply round to nearest integer, which should take care about edge cases; -- if you have any suggestion, etc, feel free add issue ticket/pull request at library's github page, provided in rs.__URL local xOff, yOff = math.floor(rs.xOff + 0.5), math.floor(rs.yOff + 0.5) - + -- get window size local windowWidth = rs.windowWidth local windowHeight = rs.windowHeight @@ -434,7 +434,7 @@ rs.toGame = function(x, y) -- Translate coordinates from non-scaled values to scaled; -- e.g translate real mouse coordinates into scaled so you can check -- for example, area to check collisions with object and cursor; - + -- ALSO, NOTE: don't forget about math precition and rounding, because with some scaling value -- using something like "rs.toGame(love.mouse.getPosition())" coordinates may produce: x -0.31 y -0.10 -- when you may expect just 0, 0 @@ -451,7 +451,7 @@ rs.toGameX = function(x) return (x - rs.xOff) / rs.scaleWidth end -rs.toGameY = function(y) +rs.toGameY = function(y) -- Translate y coordinate from non-scaled to scaled -- e.g translate real mouse coordinates into scaled so you can check -- for example, area to check collisions with object and cursor; @@ -460,10 +460,10 @@ rs.toGameY = function(y) end rs.toScreen = function(x, y) - -- Thanslate coordinates from scaled to non scaled. + -- Translate coordinates from scaled to non scaled. -- e.g translate x and y of object inside scaled area -- to, for example, set cursor position to that object - + return (x * rs.scaleWidth) + rs.xOff, (y * rs.scaleHeight) + rs.yOff end @@ -471,7 +471,7 @@ rs.toScreenX = function(x) -- Thanslate x coordinate from scaled to non scaled. -- e.g translate x of object inside scaled area -- to, for example, set cursor position to that object - + return (x * rs.scaleWidth) + rs.xOff end @@ -479,7 +479,7 @@ rs.toScreenY = function(y) -- Thanslate y coordinate from scaled to non scaled. -- e.g translate y of object inside scaled area -- to, for example, set cursor position to that object - + return (y * rs.scaleHeight) + rs.yOff end @@ -554,20 +554,20 @@ end love.keypressed = function(key) -- set randow virtual size if key == "q" then rs.setGame(love.math.random(800, 1920), love.math.random(600, 1080)) end - + -- switch scale mode if key == "w" then rs.switchScaleMode() end - + -- reset virtual size if key == "r" then rs.setGame(1280, 720) end end local isMouseUnder = function(x, y, w, h) -- function to check if mouse under something - + -- get scaled to game mouse position local mx, my = rs.toGame(love.mouse.getPosition()) - + -- check if cursor under if mx >= x and -- left my >= y and -- top @@ -575,25 +575,25 @@ local isMouseUnder = function(x, y, w, h) my <= y + h then -- bottom return true end - + return false - + end love.update = function(dt) -- update library rs.update() - + -- count timer timer = timer + dt - + -- set timer to zero if it reach limit if timer > timerLimit then timer = 0 end -- move rectangle in circle -- x coordinate dx = x * math.sin(timer) + 150 + (rs.gameWidth / 10) - + -- y coordinate dy = y * math.cos(timer) + 150 + (rs.gameHeight / 10) @@ -603,7 +603,7 @@ love.update = function(dt) -- this will be used to determine is mouse under rectangle in love.draw underRectangle = isMouseUnder(dx, dy, dw, dh) - + -- message/instructions message = "Does mouse touch moving rectangle?: " .. tostring(underRectangle) .. "\n" .. "Press Q to change virtual size: w" .. tostring(rs.gameWidth) .. " h" .. tostring(rs.gameHeight) .. "\n" .. @@ -618,66 +618,66 @@ love.update = function(dt) -- set cursor to moving rectangle; that how you can use toScreen() function if love.keyboard.isDown("space") then love.mouse.setPosition(rs.toScreen(dx, dy)) end - + -- set non-moving rectangle to cursor; that how you can use toGame() function - if love.keyboard.isDown("s") then + if love.keyboard.isDown("s") then rectangle[1] = rs.toGameX(love.mouse.getX()) rectangle[2] = rs.toGameY(love.mouse.getY()) end end - + love.draw = function() rs.start() - + -- set color for example image love.graphics.setColor(1, 1, 1, 1) love.graphics.draw(image) - + -- change color of moving rectangle, if you touch it with cursor or not if underRectangle then love.graphics.setColor(0, 1, 0) else love.graphics.setColor(1, 0, 0) end - + -- draw moving rectangle love.graphics.rectangle("line", dx, dy, dw, dh) - + -- set color for "cursor" which will follow cursor love.graphics.setColor(1, 0.4, 0.9, 1) - + -- draw "cursor" translated to in-game coordinates love.graphics.rectangle("fill", rs.toGameX(love.mouse.getX()), rs.toGameY(love.mouse.getY()), 10, 10) - + -- set color for non-moving rectangle love.graphics.setColor(0, 0, 0, 1) - + -- draw non-moving rectangle love.graphics.rectangle("line", unpack(rectangle)) - + rs.unscaleStart() -- example how you can use "unscale" function -- with that you can draw custom ui, that you don't want to scale with library itself -- or maybe with that create nice rendering for string, in pair with rs.window/gameChanged - + -- draw semi-transparent background for "I'm unscaled!" string -- set i't color to black and make transparent love.graphics.setColor(0, 0, 0, 0.5) -- get width and height for that background love.graphics.rectangle("fill", rs.windowWidth - (rs.xOff + 100), rs.windowHeight - (rs.yOff + 100), love.graphics.newFont():getWidth("I'm unscaled!"), love.graphics.newFont():getHeight("I'm unscaled!")) - + -- draw "I'm unscaled!" string -- add offset for it, so it will be not drawed under black bars love.graphics.setColor(1, 1, 1, 1) love.graphics.print("I'm unscaled!", rs.windowWidth - (rs.xOff + 100), rs.windowHeight - (rs.yOff + 100)) - + rs.unscaleStop() rs.stop() - + -- draw explaination/instruction love.graphics.setColor(0, 0, 0, 0.4) -- count how much string have new lines and use them to determine height oh string love.graphics.rectangle("fill", 0, 0, love.graphics.newFont():getWidth(message), love.graphics.newFont():getHeight(message) * select(2, string.gsub(message, "\n", "\n"))) - love.graphics.setColor(1, 1, 1, 1) + love.graphics.setColor(1, 1, 1, 1) love.graphics.print(message) end --]] @@ -772,5 +772,5 @@ ALso, this function uses same rules as rs.stop, meaning rs.drawBars = false will result in rs.drawBlackBars will be not rendered. * Now rs.stop will draw black bars via rs.drawBlackBars. --]=] - ---]] \ No newline at end of file + +--]] diff --git a/Autarky2/main.lua b/Autarky2/main.lua index 417e600..472cc12 100644 --- a/Autarky2/main.lua +++ b/Autarky2/main.lua @@ -33,7 +33,16 @@ require 'gui' function love.keyreleased( key, scancode ) if key == "escape" then - cf.RemoveScreen(SCREEN_STACK) + if cf.CurrentScreenName(SCREEN_STACK) == "ExitGame" then + cf.AddScreen("World", SCREEN_STACK) + else + cf.RemoveScreen(SCREEN_STACK) + end + end + if key == "return" then + if cf.CurrentScreenName(SCREEN_STACK) == "ExitGame" then + cf.RemoveScreen(SCREEN_STACK) + end end if key == "space" then -- pause @@ -127,13 +136,12 @@ function love.keyreleased( key, scancode ) end if key == "kp5" then - ZOOMFACTOR = 1 + ZOOMFACTOR = 0.95 TRANSLATEX = SCREEN_WIDTH / 2 TRANSLATEY = SCREEN_HEIGHT / 2 - + people.unselectAll() - - + end end @@ -173,6 +181,7 @@ function love.mousemoved( x, y, dx, dy, istouch ) end function love.mousepressed( x, y, button, istouch, presses ) + local wx, wy = cam:toWorld(x, y) -- converts screen x/y to world x/y gspot:mousepress(wx, wy, button) @@ -199,23 +208,28 @@ end function love.mousereleased( x, y, button, istouch, presses ) local wx, wy = cam:toWorld(x, y) -- converts screen x/y to world x/y lovelyToasts.mousereleased(wx, wy, button) - - if MOUSE_DOWN_X ~= nil then + + + if MOUSE_DOWN_X ~= nil and button == 1 then + -- cycle through persons and select all inside bounding box for _, person in pairs(PERSONS) do - if person.x > MOUSE_DOWN_X and person.x < wx then - if person.y > MOUSE_DOWN_Y and person.y < wy then + local x2, y2 = fun.getDrawXY(person) + if x2 > MOUSE_DOWN_X and x2 < wx then + if y2 > MOUSE_DOWN_Y and y2 < wy then person.isSelected = true - --! needs thorough testing + end end end end - + + -- used for mouse box dragging thingy MOUSE_DOWN_X = nil MOUSE_DOWN_Y = nil - + + end function love.wheelmoved(x, y) @@ -228,11 +242,16 @@ function love.wheelmoved(x, y) end if ZOOMFACTOR < 0.8 then ZOOMFACTOR = 0.8 end if ZOOMFACTOR > 3 then ZOOMFACTOR = 3 end + print("Zoom factor = " .. ZOOMFACTOR) end function love.load() - love.window.setMode(800, 600, {resizable = true, display = 1}) + + local width, height = love.window.getDesktopDimensions(1) + love.window.setMode(width, height, {resizable = true, display = 1}) + -- love.window.setMode(800, 600, {resizable = true, display = 2}) + res.setGame(1920, 1080) SCREEN_WIDTH = 1920 @@ -255,6 +274,8 @@ function love.load() fun.RecordHistoryStock() cam = Camera.new(SCREEN_WIDTH / 2, SCREEN_HEIGHT / 2, 1) + cam:setZoom(ZOOMFACTOR) + cam:setPos(TRANSLATEX, TRANSLATEY) gui.load() @@ -279,30 +300,41 @@ function love.draw() tax_rate_down_button:hide() close_options_button:hide() exit_game_button:hide() - + if currentscreen == "World" then -- do the mouse dragging thingy if MOUSE_DOWN_X ~= nil then -- draw box + + local x, y = love.mouse.getPosition() local wx, wy = cam:toWorld(x, y) -- converts screen x/y to world x/y local boxwidth = wx - MOUSE_DOWN_X local boxheight = wy - MOUSE_DOWN_Y + love.graphics.setColor(1,1,1,1) + love.graphics.rectangle("line", MOUSE_DOWN_X, MOUSE_DOWN_Y, boxwidth, boxheight) end end if currentscreen == "Graphs" then draw.graphs() - close_graph_button:show() + -- close_graph_button:show() else close_graph_button:hide() end - + cam:detach() + + -- this happens after the camera is detached + if currentscreen == "World" then + draw.topBar() + end + elseif currentscreen == "Options" then draw.optionScreen() elseif currentscreen == "ExitGame" then - draw.exitScreen() + draw.exitScreen() + else error("Current screen is " .. currentscreen) end @@ -385,8 +417,11 @@ function love.update(dt) end end - cam:setPos(TRANSLATEX, TRANSLATEY) + end + + if currentscreen == "World" or currentscreen == "Graphs" then cam:setZoom(ZOOMFACTOR) + cam:setPos(TRANSLATEX, TRANSLATEY) end lovelyToasts.update(dt)