From 7efa8d6a49fe47328723134164cef44c7f55615a Mon Sep 17 00:00:00 2001 From: simleo Date: Fri, 2 Nov 2018 17:51:22 +0100 Subject: [PATCH 1/2] single source push.lua --- pong-1/main.lua | 2 + pong-1/push.lua | 232 -------------------------------- pong-10/main.lua | 2 + pong-10/push.lua | 232 -------------------------------- pong-11/main.lua | 2 + pong-11/push.lua | 232 -------------------------------- pong-12/main.lua | 2 + pong-12/push.lua | 232 -------------------------------- pong-2/main.lua | 2 + pong-2/push.lua | 232 -------------------------------- pong-3/main.lua | 2 + pong-3/push.lua | 232 -------------------------------- pong-4/main.lua | 2 + pong-4/push.lua | 232 -------------------------------- pong-5/main.lua | 2 + pong-5/push.lua | 232 -------------------------------- pong-6/main.lua | 2 + pong-6/push.lua | 232 -------------------------------- pong-7/main.lua | 2 + pong-7/push.lua | 232 -------------------------------- pong-8/main.lua | 2 + pong-8/push.lua | 232 -------------------------------- pong-9/main.lua | 2 + pong-9/push.lua | 232 -------------------------------- pong-final/main.lua | 2 + pong-final/push.lua => push.lua | 0 26 files changed, 26 insertions(+), 2784 deletions(-) delete mode 100644 pong-1/push.lua delete mode 100644 pong-10/push.lua delete mode 100644 pong-11/push.lua delete mode 100644 pong-12/push.lua delete mode 100644 pong-2/push.lua delete mode 100644 pong-3/push.lua delete mode 100644 pong-4/push.lua delete mode 100644 pong-5/push.lua delete mode 100644 pong-6/push.lua delete mode 100644 pong-7/push.lua delete mode 100644 pong-8/push.lua delete mode 100644 pong-9/push.lua rename pong-final/push.lua => push.lua (100%) diff --git a/pong-1/main.lua b/pong-1/main.lua index 4029596..47210ff 100644 --- a/pong-1/main.lua +++ b/pong-1/main.lua @@ -20,6 +20,8 @@ modern systems. ]] +package.path = package.path .. ";../?.lua" + -- push is a library that will allow us to draw our game at a virtual -- resolution, instead of however large our window is; used to provide -- a more retro aesthetic diff --git a/pong-1/push.lua b/pong-1/push.lua deleted file mode 100644 index 0e0709a..0000000 --- a/pong-1/push.lua +++ /dev/null @@ -1,232 +0,0 @@ --- push.lua v0.2 - --- Copyright (c) 2017 Ulysse Ramage --- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: --- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. --- 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 OR COPYRIGHT HOLDERS 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. - -local push = { - - defaults = { - fullscreen = false, - resizable = false, - pixelperfect = false, - highdpi = true, - canvas = true - } - -} -setmetatable(push, push) - ---TODO: rendering resolution? ---TODO: clean up code - -function push:applySettings(settings) - for k, v in pairs(settings) do - self["_" .. k] = v - end -end - -function push:resetSettings() return self:applySettings(self.defaults) end - -function push:setupScreen(WWIDTH, WHEIGHT, RWIDTH, RHEIGHT, settings) - - settings = settings or {} - - self._WWIDTH, self._WHEIGHT = WWIDTH, WHEIGHT - self._RWIDTH, self._RHEIGHT = RWIDTH, RHEIGHT - - self:applySettings(self.defaults) --set defaults first - self:applySettings(settings) --then fill with custom settings - - love.window.setMode( self._RWIDTH, self._RHEIGHT, { - fullscreen = self._fullscreen, - resizable = self._resizable, - highdpi = self._highdpi - } ) - - self:initValues() - - if self._canvas then - self:setupCanvas({ "default" }) --setup canvas - end - - self._borderColor = {0, 0, 0} - - self._drawFunctions = { - ["start"] = self.start, - ["end"] = self.finish - } - - return self -end - -function push:setupCanvas(canvases) - table.insert(canvases, { name = "_render" }) --final render - - self._canvas = true - self.canvases = {} - - for i = 1, #canvases do - self.canvases[i] = { - name = canvases[i].name, - shader = canvases[i].shader, - canvas = love.graphics.newCanvas(self._WWIDTH, self._WHEIGHT) - } - end - - return self -end - -function push:setCanvas(name) - if not self._canvas then return true end - return love.graphics.setCanvas( self:getCanvasTable(name).canvas ) -end -function push:getCanvasTable(name) - for i = 1, #self.canvases do - if self.canvases[i].name == name then - return self.canvases[i] - end - end -end -function push:setShader(name, shader) - if not shader then - self:getCanvasTable("_render").shader = name - else - self:getCanvasTable(name).shader = shader - end -end - -function push:initValues() - self._PSCALE = self._highdpi and love.window.getPixelScale() or 1 - - self._SCALE = { - x = self._RWIDTH/self._WWIDTH * self._PSCALE, - y = self._RHEIGHT/self._WHEIGHT * self._PSCALE - } - - if self._stretched then --if stretched, no need to apply offset - self._OFFSET = {x = 0, y = 0} - else - local scale = math.min(self._SCALE.x, self._SCALE.y) - if self._pixelperfect then scale = math.floor(scale) end - - self._OFFSET = {x = (self._SCALE.x - scale) * (self._WWIDTH/2), y = (self._SCALE.y - scale) * (self._WHEIGHT/2)} - self._SCALE.x, self._SCALE.y = scale, scale --apply same scale to X and Y - end - - self._GWIDTH = self._RWIDTH * self._PSCALE - self._OFFSET.x * 2 - self._GHEIGHT = self._RHEIGHT * self._PSCALE - self._OFFSET.y * 2 -end - ---[[ DEPRECATED ]]-- -function push:apply(operation, shader) - if operation == "start" then - self:start() - elseif operation == "finish" or operation == "end" then - self:finish(shader) - end -end - -function push:start() - if self._canvas then - love.graphics.push() - love.graphics.setCanvas(self.canvases[1].canvas) - else - love.graphics.translate(self._OFFSET.x, self._OFFSET.y) - love.graphics.setScissor(self._OFFSET.x, self._OFFSET.y, self._WWIDTH*self._SCALE.x, self._WHEIGHT*self._SCALE.y) - love.graphics.push() - love.graphics.scale(self._SCALE.x, self._SCALE.y) - end -end - -function push:finish(shader) - love.graphics.setBackgroundColor(unpack(self._borderColor)) - if self._canvas then - local _render = self:getCanvasTable("_render") - - love.graphics.pop() - - love.graphics.setColor(255, 255, 255) - - --draw canvas - love.graphics.setCanvas(_render.canvas) - for i = 1, #self.canvases - 1 do --do not draw _render yet - local _table = self.canvases[i] - love.graphics.setShader(_table.shader) - love.graphics.draw(_table.canvas) - end - love.graphics.setCanvas() - - --draw render - love.graphics.translate(self._OFFSET.x, self._OFFSET.y) - love.graphics.setShader(shader or self:getCanvasTable("_render").shader) - love.graphics.draw(self:getCanvasTable("_render").canvas, 0, 0, 0, self._SCALE.x, self._SCALE.y) - - --clear canvas - for i = 1, #self.canvases do - love.graphics.setCanvas( self.canvases[i].canvas ) - love.graphics.clear() - end - - love.graphics.setCanvas() - love.graphics.setShader() - else - love.graphics.pop() - love.graphics.setScissor() - end -end - -function push:setBorderColor(color, g, b) - self._borderColor = g and {color, g, b} or color -end - -function push:toGame(x, y) - x, y = x - self._OFFSET.x, y - self._OFFSET.y - local normalX, normalY = x / self._GWIDTH, y / self._GHEIGHT - - x = (x >= 0 and x <= self._WWIDTH * self._SCALE.x) and normalX * self._WWIDTH or nil - y = (y >= 0 and y <= self._WHEIGHT * self._SCALE.y) and normalY * self._WHEIGHT or nil - - return x, y -end - ---doesn't work - TODO -function push:toReal(x, y) - return x+self._OFFSET.x, y+self._OFFSET.y -end - -function push:switchFullscreen(winw, winh) - self._fullscreen = not self._fullscreen - local windowWidth, windowHeight = love.window.getDesktopDimensions() - - if self._fullscreen then --save windowed dimensions for later - self._WINWIDTH, self._WINHEIGHT = self._RWIDTH, self._RHEIGHT - elseif not self._WINWIDTH or not self._WINHEIGHT then - self._WINWIDTH, self._WINHEIGHT = windowWidth * .5, windowHeight * .5 - end - - self._RWIDTH = self._fullscreen and windowWidth or winw or self._WINWIDTH - self._RHEIGHT = self._fullscreen and windowHeight or winh or self._WINHEIGHT - - self:initValues() - - love.window.setFullscreen(self._fullscreen, "desktop") - if not self._fullscreen and (winw or winh) then - love.window.setMode(self._RWIDTH, self._RHEIGHT) --set window dimensions - end -end - -function push:resize(w, h) - local pixelScale = love.window.getPixelScale() - if self._highdpi then w, h = w / pixelScale, h / pixelScale end - self._RWIDTH = w - self._RHEIGHT = h - self:initValues() -end - -function push:getWidth() return self._WWIDTH end -function push:getHeight() return self._WHEIGHT end -function push:getDimensions() return self._WWIDTH, self._WHEIGHT end - -return push diff --git a/pong-10/main.lua b/pong-10/main.lua index 6f19e49..11eb3b7 100644 --- a/pong-10/main.lua +++ b/pong-10/main.lua @@ -20,6 +20,8 @@ modern systems. ]] +package.path = package.path .. ";../?.lua" + -- push is a library that will allow us to draw our game at a virtual -- resolution, instead of however large our window is; used to provide -- a more retro aesthetic diff --git a/pong-10/push.lua b/pong-10/push.lua deleted file mode 100644 index 0e0709a..0000000 --- a/pong-10/push.lua +++ /dev/null @@ -1,232 +0,0 @@ --- push.lua v0.2 - --- Copyright (c) 2017 Ulysse Ramage --- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: --- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. --- 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 OR COPYRIGHT HOLDERS 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. - -local push = { - - defaults = { - fullscreen = false, - resizable = false, - pixelperfect = false, - highdpi = true, - canvas = true - } - -} -setmetatable(push, push) - ---TODO: rendering resolution? ---TODO: clean up code - -function push:applySettings(settings) - for k, v in pairs(settings) do - self["_" .. k] = v - end -end - -function push:resetSettings() return self:applySettings(self.defaults) end - -function push:setupScreen(WWIDTH, WHEIGHT, RWIDTH, RHEIGHT, settings) - - settings = settings or {} - - self._WWIDTH, self._WHEIGHT = WWIDTH, WHEIGHT - self._RWIDTH, self._RHEIGHT = RWIDTH, RHEIGHT - - self:applySettings(self.defaults) --set defaults first - self:applySettings(settings) --then fill with custom settings - - love.window.setMode( self._RWIDTH, self._RHEIGHT, { - fullscreen = self._fullscreen, - resizable = self._resizable, - highdpi = self._highdpi - } ) - - self:initValues() - - if self._canvas then - self:setupCanvas({ "default" }) --setup canvas - end - - self._borderColor = {0, 0, 0} - - self._drawFunctions = { - ["start"] = self.start, - ["end"] = self.finish - } - - return self -end - -function push:setupCanvas(canvases) - table.insert(canvases, { name = "_render" }) --final render - - self._canvas = true - self.canvases = {} - - for i = 1, #canvases do - self.canvases[i] = { - name = canvases[i].name, - shader = canvases[i].shader, - canvas = love.graphics.newCanvas(self._WWIDTH, self._WHEIGHT) - } - end - - return self -end - -function push:setCanvas(name) - if not self._canvas then return true end - return love.graphics.setCanvas( self:getCanvasTable(name).canvas ) -end -function push:getCanvasTable(name) - for i = 1, #self.canvases do - if self.canvases[i].name == name then - return self.canvases[i] - end - end -end -function push:setShader(name, shader) - if not shader then - self:getCanvasTable("_render").shader = name - else - self:getCanvasTable(name).shader = shader - end -end - -function push:initValues() - self._PSCALE = self._highdpi and love.window.getPixelScale() or 1 - - self._SCALE = { - x = self._RWIDTH/self._WWIDTH * self._PSCALE, - y = self._RHEIGHT/self._WHEIGHT * self._PSCALE - } - - if self._stretched then --if stretched, no need to apply offset - self._OFFSET = {x = 0, y = 0} - else - local scale = math.min(self._SCALE.x, self._SCALE.y) - if self._pixelperfect then scale = math.floor(scale) end - - self._OFFSET = {x = (self._SCALE.x - scale) * (self._WWIDTH/2), y = (self._SCALE.y - scale) * (self._WHEIGHT/2)} - self._SCALE.x, self._SCALE.y = scale, scale --apply same scale to X and Y - end - - self._GWIDTH = self._RWIDTH * self._PSCALE - self._OFFSET.x * 2 - self._GHEIGHT = self._RHEIGHT * self._PSCALE - self._OFFSET.y * 2 -end - ---[[ DEPRECATED ]]-- -function push:apply(operation, shader) - if operation == "start" then - self:start() - elseif operation == "finish" or operation == "end" then - self:finish(shader) - end -end - -function push:start() - if self._canvas then - love.graphics.push() - love.graphics.setCanvas(self.canvases[1].canvas) - else - love.graphics.translate(self._OFFSET.x, self._OFFSET.y) - love.graphics.setScissor(self._OFFSET.x, self._OFFSET.y, self._WWIDTH*self._SCALE.x, self._WHEIGHT*self._SCALE.y) - love.graphics.push() - love.graphics.scale(self._SCALE.x, self._SCALE.y) - end -end - -function push:finish(shader) - love.graphics.setBackgroundColor(unpack(self._borderColor)) - if self._canvas then - local _render = self:getCanvasTable("_render") - - love.graphics.pop() - - love.graphics.setColor(255, 255, 255) - - --draw canvas - love.graphics.setCanvas(_render.canvas) - for i = 1, #self.canvases - 1 do --do not draw _render yet - local _table = self.canvases[i] - love.graphics.setShader(_table.shader) - love.graphics.draw(_table.canvas) - end - love.graphics.setCanvas() - - --draw render - love.graphics.translate(self._OFFSET.x, self._OFFSET.y) - love.graphics.setShader(shader or self:getCanvasTable("_render").shader) - love.graphics.draw(self:getCanvasTable("_render").canvas, 0, 0, 0, self._SCALE.x, self._SCALE.y) - - --clear canvas - for i = 1, #self.canvases do - love.graphics.setCanvas( self.canvases[i].canvas ) - love.graphics.clear() - end - - love.graphics.setCanvas() - love.graphics.setShader() - else - love.graphics.pop() - love.graphics.setScissor() - end -end - -function push:setBorderColor(color, g, b) - self._borderColor = g and {color, g, b} or color -end - -function push:toGame(x, y) - x, y = x - self._OFFSET.x, y - self._OFFSET.y - local normalX, normalY = x / self._GWIDTH, y / self._GHEIGHT - - x = (x >= 0 and x <= self._WWIDTH * self._SCALE.x) and normalX * self._WWIDTH or nil - y = (y >= 0 and y <= self._WHEIGHT * self._SCALE.y) and normalY * self._WHEIGHT or nil - - return x, y -end - ---doesn't work - TODO -function push:toReal(x, y) - return x+self._OFFSET.x, y+self._OFFSET.y -end - -function push:switchFullscreen(winw, winh) - self._fullscreen = not self._fullscreen - local windowWidth, windowHeight = love.window.getDesktopDimensions() - - if self._fullscreen then --save windowed dimensions for later - self._WINWIDTH, self._WINHEIGHT = self._RWIDTH, self._RHEIGHT - elseif not self._WINWIDTH or not self._WINHEIGHT then - self._WINWIDTH, self._WINHEIGHT = windowWidth * .5, windowHeight * .5 - end - - self._RWIDTH = self._fullscreen and windowWidth or winw or self._WINWIDTH - self._RHEIGHT = self._fullscreen and windowHeight or winh or self._WINHEIGHT - - self:initValues() - - love.window.setFullscreen(self._fullscreen, "desktop") - if not self._fullscreen and (winw or winh) then - love.window.setMode(self._RWIDTH, self._RHEIGHT) --set window dimensions - end -end - -function push:resize(w, h) - local pixelScale = love.window.getPixelScale() - if self._highdpi then w, h = w / pixelScale, h / pixelScale end - self._RWIDTH = w - self._RHEIGHT = h - self:initValues() -end - -function push:getWidth() return self._WWIDTH end -function push:getHeight() return self._WHEIGHT end -function push:getDimensions() return self._WWIDTH, self._WHEIGHT end - -return push diff --git a/pong-11/main.lua b/pong-11/main.lua index 58956e1..43ce1e5 100644 --- a/pong-11/main.lua +++ b/pong-11/main.lua @@ -20,6 +20,8 @@ modern systems. ]] +package.path = package.path .. ";../?.lua" + -- push is a library that will allow us to draw our game at a virtual -- resolution, instead of however large our window is; used to provide -- a more retro aesthetic diff --git a/pong-11/push.lua b/pong-11/push.lua deleted file mode 100644 index 0e0709a..0000000 --- a/pong-11/push.lua +++ /dev/null @@ -1,232 +0,0 @@ --- push.lua v0.2 - --- Copyright (c) 2017 Ulysse Ramage --- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: --- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. --- 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 OR COPYRIGHT HOLDERS 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. - -local push = { - - defaults = { - fullscreen = false, - resizable = false, - pixelperfect = false, - highdpi = true, - canvas = true - } - -} -setmetatable(push, push) - ---TODO: rendering resolution? ---TODO: clean up code - -function push:applySettings(settings) - for k, v in pairs(settings) do - self["_" .. k] = v - end -end - -function push:resetSettings() return self:applySettings(self.defaults) end - -function push:setupScreen(WWIDTH, WHEIGHT, RWIDTH, RHEIGHT, settings) - - settings = settings or {} - - self._WWIDTH, self._WHEIGHT = WWIDTH, WHEIGHT - self._RWIDTH, self._RHEIGHT = RWIDTH, RHEIGHT - - self:applySettings(self.defaults) --set defaults first - self:applySettings(settings) --then fill with custom settings - - love.window.setMode( self._RWIDTH, self._RHEIGHT, { - fullscreen = self._fullscreen, - resizable = self._resizable, - highdpi = self._highdpi - } ) - - self:initValues() - - if self._canvas then - self:setupCanvas({ "default" }) --setup canvas - end - - self._borderColor = {0, 0, 0} - - self._drawFunctions = { - ["start"] = self.start, - ["end"] = self.finish - } - - return self -end - -function push:setupCanvas(canvases) - table.insert(canvases, { name = "_render" }) --final render - - self._canvas = true - self.canvases = {} - - for i = 1, #canvases do - self.canvases[i] = { - name = canvases[i].name, - shader = canvases[i].shader, - canvas = love.graphics.newCanvas(self._WWIDTH, self._WHEIGHT) - } - end - - return self -end - -function push:setCanvas(name) - if not self._canvas then return true end - return love.graphics.setCanvas( self:getCanvasTable(name).canvas ) -end -function push:getCanvasTable(name) - for i = 1, #self.canvases do - if self.canvases[i].name == name then - return self.canvases[i] - end - end -end -function push:setShader(name, shader) - if not shader then - self:getCanvasTable("_render").shader = name - else - self:getCanvasTable(name).shader = shader - end -end - -function push:initValues() - self._PSCALE = self._highdpi and love.window.getPixelScale() or 1 - - self._SCALE = { - x = self._RWIDTH/self._WWIDTH * self._PSCALE, - y = self._RHEIGHT/self._WHEIGHT * self._PSCALE - } - - if self._stretched then --if stretched, no need to apply offset - self._OFFSET = {x = 0, y = 0} - else - local scale = math.min(self._SCALE.x, self._SCALE.y) - if self._pixelperfect then scale = math.floor(scale) end - - self._OFFSET = {x = (self._SCALE.x - scale) * (self._WWIDTH/2), y = (self._SCALE.y - scale) * (self._WHEIGHT/2)} - self._SCALE.x, self._SCALE.y = scale, scale --apply same scale to X and Y - end - - self._GWIDTH = self._RWIDTH * self._PSCALE - self._OFFSET.x * 2 - self._GHEIGHT = self._RHEIGHT * self._PSCALE - self._OFFSET.y * 2 -end - ---[[ DEPRECATED ]]-- -function push:apply(operation, shader) - if operation == "start" then - self:start() - elseif operation == "finish" or operation == "end" then - self:finish(shader) - end -end - -function push:start() - if self._canvas then - love.graphics.push() - love.graphics.setCanvas(self.canvases[1].canvas) - else - love.graphics.translate(self._OFFSET.x, self._OFFSET.y) - love.graphics.setScissor(self._OFFSET.x, self._OFFSET.y, self._WWIDTH*self._SCALE.x, self._WHEIGHT*self._SCALE.y) - love.graphics.push() - love.graphics.scale(self._SCALE.x, self._SCALE.y) - end -end - -function push:finish(shader) - love.graphics.setBackgroundColor(unpack(self._borderColor)) - if self._canvas then - local _render = self:getCanvasTable("_render") - - love.graphics.pop() - - love.graphics.setColor(255, 255, 255) - - --draw canvas - love.graphics.setCanvas(_render.canvas) - for i = 1, #self.canvases - 1 do --do not draw _render yet - local _table = self.canvases[i] - love.graphics.setShader(_table.shader) - love.graphics.draw(_table.canvas) - end - love.graphics.setCanvas() - - --draw render - love.graphics.translate(self._OFFSET.x, self._OFFSET.y) - love.graphics.setShader(shader or self:getCanvasTable("_render").shader) - love.graphics.draw(self:getCanvasTable("_render").canvas, 0, 0, 0, self._SCALE.x, self._SCALE.y) - - --clear canvas - for i = 1, #self.canvases do - love.graphics.setCanvas( self.canvases[i].canvas ) - love.graphics.clear() - end - - love.graphics.setCanvas() - love.graphics.setShader() - else - love.graphics.pop() - love.graphics.setScissor() - end -end - -function push:setBorderColor(color, g, b) - self._borderColor = g and {color, g, b} or color -end - -function push:toGame(x, y) - x, y = x - self._OFFSET.x, y - self._OFFSET.y - local normalX, normalY = x / self._GWIDTH, y / self._GHEIGHT - - x = (x >= 0 and x <= self._WWIDTH * self._SCALE.x) and normalX * self._WWIDTH or nil - y = (y >= 0 and y <= self._WHEIGHT * self._SCALE.y) and normalY * self._WHEIGHT or nil - - return x, y -end - ---doesn't work - TODO -function push:toReal(x, y) - return x+self._OFFSET.x, y+self._OFFSET.y -end - -function push:switchFullscreen(winw, winh) - self._fullscreen = not self._fullscreen - local windowWidth, windowHeight = love.window.getDesktopDimensions() - - if self._fullscreen then --save windowed dimensions for later - self._WINWIDTH, self._WINHEIGHT = self._RWIDTH, self._RHEIGHT - elseif not self._WINWIDTH or not self._WINHEIGHT then - self._WINWIDTH, self._WINHEIGHT = windowWidth * .5, windowHeight * .5 - end - - self._RWIDTH = self._fullscreen and windowWidth or winw or self._WINWIDTH - self._RHEIGHT = self._fullscreen and windowHeight or winh or self._WINHEIGHT - - self:initValues() - - love.window.setFullscreen(self._fullscreen, "desktop") - if not self._fullscreen and (winw or winh) then - love.window.setMode(self._RWIDTH, self._RHEIGHT) --set window dimensions - end -end - -function push:resize(w, h) - local pixelScale = love.window.getPixelScale() - if self._highdpi then w, h = w / pixelScale, h / pixelScale end - self._RWIDTH = w - self._RHEIGHT = h - self:initValues() -end - -function push:getWidth() return self._WWIDTH end -function push:getHeight() return self._WHEIGHT end -function push:getDimensions() return self._WWIDTH, self._WHEIGHT end - -return push diff --git a/pong-12/main.lua b/pong-12/main.lua index b06a998..e1948cb 100644 --- a/pong-12/main.lua +++ b/pong-12/main.lua @@ -20,6 +20,8 @@ modern systems. ]] +package.path = package.path .. ";../?.lua" + -- push is a library that will allow us to draw our game at a virtual -- resolution, instead of however large our window is; used to provide -- a more retro aesthetic diff --git a/pong-12/push.lua b/pong-12/push.lua deleted file mode 100644 index 0e0709a..0000000 --- a/pong-12/push.lua +++ /dev/null @@ -1,232 +0,0 @@ --- push.lua v0.2 - --- Copyright (c) 2017 Ulysse Ramage --- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: --- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. --- 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 OR COPYRIGHT HOLDERS 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. - -local push = { - - defaults = { - fullscreen = false, - resizable = false, - pixelperfect = false, - highdpi = true, - canvas = true - } - -} -setmetatable(push, push) - ---TODO: rendering resolution? ---TODO: clean up code - -function push:applySettings(settings) - for k, v in pairs(settings) do - self["_" .. k] = v - end -end - -function push:resetSettings() return self:applySettings(self.defaults) end - -function push:setupScreen(WWIDTH, WHEIGHT, RWIDTH, RHEIGHT, settings) - - settings = settings or {} - - self._WWIDTH, self._WHEIGHT = WWIDTH, WHEIGHT - self._RWIDTH, self._RHEIGHT = RWIDTH, RHEIGHT - - self:applySettings(self.defaults) --set defaults first - self:applySettings(settings) --then fill with custom settings - - love.window.setMode( self._RWIDTH, self._RHEIGHT, { - fullscreen = self._fullscreen, - resizable = self._resizable, - highdpi = self._highdpi - } ) - - self:initValues() - - if self._canvas then - self:setupCanvas({ "default" }) --setup canvas - end - - self._borderColor = {0, 0, 0} - - self._drawFunctions = { - ["start"] = self.start, - ["end"] = self.finish - } - - return self -end - -function push:setupCanvas(canvases) - table.insert(canvases, { name = "_render" }) --final render - - self._canvas = true - self.canvases = {} - - for i = 1, #canvases do - self.canvases[i] = { - name = canvases[i].name, - shader = canvases[i].shader, - canvas = love.graphics.newCanvas(self._WWIDTH, self._WHEIGHT) - } - end - - return self -end - -function push:setCanvas(name) - if not self._canvas then return true end - return love.graphics.setCanvas( self:getCanvasTable(name).canvas ) -end -function push:getCanvasTable(name) - for i = 1, #self.canvases do - if self.canvases[i].name == name then - return self.canvases[i] - end - end -end -function push:setShader(name, shader) - if not shader then - self:getCanvasTable("_render").shader = name - else - self:getCanvasTable(name).shader = shader - end -end - -function push:initValues() - self._PSCALE = self._highdpi and love.window.getPixelScale() or 1 - - self._SCALE = { - x = self._RWIDTH/self._WWIDTH * self._PSCALE, - y = self._RHEIGHT/self._WHEIGHT * self._PSCALE - } - - if self._stretched then --if stretched, no need to apply offset - self._OFFSET = {x = 0, y = 0} - else - local scale = math.min(self._SCALE.x, self._SCALE.y) - if self._pixelperfect then scale = math.floor(scale) end - - self._OFFSET = {x = (self._SCALE.x - scale) * (self._WWIDTH/2), y = (self._SCALE.y - scale) * (self._WHEIGHT/2)} - self._SCALE.x, self._SCALE.y = scale, scale --apply same scale to X and Y - end - - self._GWIDTH = self._RWIDTH * self._PSCALE - self._OFFSET.x * 2 - self._GHEIGHT = self._RHEIGHT * self._PSCALE - self._OFFSET.y * 2 -end - ---[[ DEPRECATED ]]-- -function push:apply(operation, shader) - if operation == "start" then - self:start() - elseif operation == "finish" or operation == "end" then - self:finish(shader) - end -end - -function push:start() - if self._canvas then - love.graphics.push() - love.graphics.setCanvas(self.canvases[1].canvas) - else - love.graphics.translate(self._OFFSET.x, self._OFFSET.y) - love.graphics.setScissor(self._OFFSET.x, self._OFFSET.y, self._WWIDTH*self._SCALE.x, self._WHEIGHT*self._SCALE.y) - love.graphics.push() - love.graphics.scale(self._SCALE.x, self._SCALE.y) - end -end - -function push:finish(shader) - love.graphics.setBackgroundColor(unpack(self._borderColor)) - if self._canvas then - local _render = self:getCanvasTable("_render") - - love.graphics.pop() - - love.graphics.setColor(255, 255, 255) - - --draw canvas - love.graphics.setCanvas(_render.canvas) - for i = 1, #self.canvases - 1 do --do not draw _render yet - local _table = self.canvases[i] - love.graphics.setShader(_table.shader) - love.graphics.draw(_table.canvas) - end - love.graphics.setCanvas() - - --draw render - love.graphics.translate(self._OFFSET.x, self._OFFSET.y) - love.graphics.setShader(shader or self:getCanvasTable("_render").shader) - love.graphics.draw(self:getCanvasTable("_render").canvas, 0, 0, 0, self._SCALE.x, self._SCALE.y) - - --clear canvas - for i = 1, #self.canvases do - love.graphics.setCanvas( self.canvases[i].canvas ) - love.graphics.clear() - end - - love.graphics.setCanvas() - love.graphics.setShader() - else - love.graphics.pop() - love.graphics.setScissor() - end -end - -function push:setBorderColor(color, g, b) - self._borderColor = g and {color, g, b} or color -end - -function push:toGame(x, y) - x, y = x - self._OFFSET.x, y - self._OFFSET.y - local normalX, normalY = x / self._GWIDTH, y / self._GHEIGHT - - x = (x >= 0 and x <= self._WWIDTH * self._SCALE.x) and normalX * self._WWIDTH or nil - y = (y >= 0 and y <= self._WHEIGHT * self._SCALE.y) and normalY * self._WHEIGHT or nil - - return x, y -end - ---doesn't work - TODO -function push:toReal(x, y) - return x+self._OFFSET.x, y+self._OFFSET.y -end - -function push:switchFullscreen(winw, winh) - self._fullscreen = not self._fullscreen - local windowWidth, windowHeight = love.window.getDesktopDimensions() - - if self._fullscreen then --save windowed dimensions for later - self._WINWIDTH, self._WINHEIGHT = self._RWIDTH, self._RHEIGHT - elseif not self._WINWIDTH or not self._WINHEIGHT then - self._WINWIDTH, self._WINHEIGHT = windowWidth * .5, windowHeight * .5 - end - - self._RWIDTH = self._fullscreen and windowWidth or winw or self._WINWIDTH - self._RHEIGHT = self._fullscreen and windowHeight or winh or self._WINHEIGHT - - self:initValues() - - love.window.setFullscreen(self._fullscreen, "desktop") - if not self._fullscreen and (winw or winh) then - love.window.setMode(self._RWIDTH, self._RHEIGHT) --set window dimensions - end -end - -function push:resize(w, h) - local pixelScale = love.window.getPixelScale() - if self._highdpi then w, h = w / pixelScale, h / pixelScale end - self._RWIDTH = w - self._RHEIGHT = h - self:initValues() -end - -function push:getWidth() return self._WWIDTH end -function push:getHeight() return self._WHEIGHT end -function push:getDimensions() return self._WWIDTH, self._WHEIGHT end - -return push diff --git a/pong-2/main.lua b/pong-2/main.lua index aa4b0bf..9ad82bf 100644 --- a/pong-2/main.lua +++ b/pong-2/main.lua @@ -20,6 +20,8 @@ modern systems. ]] +package.path = package.path .. ";../?.lua" + -- push is a library that will allow us to draw our game at a virtual -- resolution, instead of however large our window is; used to provide -- a more retro aesthetic diff --git a/pong-2/push.lua b/pong-2/push.lua deleted file mode 100644 index 0e0709a..0000000 --- a/pong-2/push.lua +++ /dev/null @@ -1,232 +0,0 @@ --- push.lua v0.2 - --- Copyright (c) 2017 Ulysse Ramage --- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: --- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. --- 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 OR COPYRIGHT HOLDERS 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. - -local push = { - - defaults = { - fullscreen = false, - resizable = false, - pixelperfect = false, - highdpi = true, - canvas = true - } - -} -setmetatable(push, push) - ---TODO: rendering resolution? ---TODO: clean up code - -function push:applySettings(settings) - for k, v in pairs(settings) do - self["_" .. k] = v - end -end - -function push:resetSettings() return self:applySettings(self.defaults) end - -function push:setupScreen(WWIDTH, WHEIGHT, RWIDTH, RHEIGHT, settings) - - settings = settings or {} - - self._WWIDTH, self._WHEIGHT = WWIDTH, WHEIGHT - self._RWIDTH, self._RHEIGHT = RWIDTH, RHEIGHT - - self:applySettings(self.defaults) --set defaults first - self:applySettings(settings) --then fill with custom settings - - love.window.setMode( self._RWIDTH, self._RHEIGHT, { - fullscreen = self._fullscreen, - resizable = self._resizable, - highdpi = self._highdpi - } ) - - self:initValues() - - if self._canvas then - self:setupCanvas({ "default" }) --setup canvas - end - - self._borderColor = {0, 0, 0} - - self._drawFunctions = { - ["start"] = self.start, - ["end"] = self.finish - } - - return self -end - -function push:setupCanvas(canvases) - table.insert(canvases, { name = "_render" }) --final render - - self._canvas = true - self.canvases = {} - - for i = 1, #canvases do - self.canvases[i] = { - name = canvases[i].name, - shader = canvases[i].shader, - canvas = love.graphics.newCanvas(self._WWIDTH, self._WHEIGHT) - } - end - - return self -end - -function push:setCanvas(name) - if not self._canvas then return true end - return love.graphics.setCanvas( self:getCanvasTable(name).canvas ) -end -function push:getCanvasTable(name) - for i = 1, #self.canvases do - if self.canvases[i].name == name then - return self.canvases[i] - end - end -end -function push:setShader(name, shader) - if not shader then - self:getCanvasTable("_render").shader = name - else - self:getCanvasTable(name).shader = shader - end -end - -function push:initValues() - self._PSCALE = self._highdpi and love.window.getPixelScale() or 1 - - self._SCALE = { - x = self._RWIDTH/self._WWIDTH * self._PSCALE, - y = self._RHEIGHT/self._WHEIGHT * self._PSCALE - } - - if self._stretched then --if stretched, no need to apply offset - self._OFFSET = {x = 0, y = 0} - else - local scale = math.min(self._SCALE.x, self._SCALE.y) - if self._pixelperfect then scale = math.floor(scale) end - - self._OFFSET = {x = (self._SCALE.x - scale) * (self._WWIDTH/2), y = (self._SCALE.y - scale) * (self._WHEIGHT/2)} - self._SCALE.x, self._SCALE.y = scale, scale --apply same scale to X and Y - end - - self._GWIDTH = self._RWIDTH * self._PSCALE - self._OFFSET.x * 2 - self._GHEIGHT = self._RHEIGHT * self._PSCALE - self._OFFSET.y * 2 -end - ---[[ DEPRECATED ]]-- -function push:apply(operation, shader) - if operation == "start" then - self:start() - elseif operation == "finish" or operation == "end" then - self:finish(shader) - end -end - -function push:start() - if self._canvas then - love.graphics.push() - love.graphics.setCanvas(self.canvases[1].canvas) - else - love.graphics.translate(self._OFFSET.x, self._OFFSET.y) - love.graphics.setScissor(self._OFFSET.x, self._OFFSET.y, self._WWIDTH*self._SCALE.x, self._WHEIGHT*self._SCALE.y) - love.graphics.push() - love.graphics.scale(self._SCALE.x, self._SCALE.y) - end -end - -function push:finish(shader) - love.graphics.setBackgroundColor(unpack(self._borderColor)) - if self._canvas then - local _render = self:getCanvasTable("_render") - - love.graphics.pop() - - love.graphics.setColor(255, 255, 255) - - --draw canvas - love.graphics.setCanvas(_render.canvas) - for i = 1, #self.canvases - 1 do --do not draw _render yet - local _table = self.canvases[i] - love.graphics.setShader(_table.shader) - love.graphics.draw(_table.canvas) - end - love.graphics.setCanvas() - - --draw render - love.graphics.translate(self._OFFSET.x, self._OFFSET.y) - love.graphics.setShader(shader or self:getCanvasTable("_render").shader) - love.graphics.draw(self:getCanvasTable("_render").canvas, 0, 0, 0, self._SCALE.x, self._SCALE.y) - - --clear canvas - for i = 1, #self.canvases do - love.graphics.setCanvas( self.canvases[i].canvas ) - love.graphics.clear() - end - - love.graphics.setCanvas() - love.graphics.setShader() - else - love.graphics.pop() - love.graphics.setScissor() - end -end - -function push:setBorderColor(color, g, b) - self._borderColor = g and {color, g, b} or color -end - -function push:toGame(x, y) - x, y = x - self._OFFSET.x, y - self._OFFSET.y - local normalX, normalY = x / self._GWIDTH, y / self._GHEIGHT - - x = (x >= 0 and x <= self._WWIDTH * self._SCALE.x) and normalX * self._WWIDTH or nil - y = (y >= 0 and y <= self._WHEIGHT * self._SCALE.y) and normalY * self._WHEIGHT or nil - - return x, y -end - ---doesn't work - TODO -function push:toReal(x, y) - return x+self._OFFSET.x, y+self._OFFSET.y -end - -function push:switchFullscreen(winw, winh) - self._fullscreen = not self._fullscreen - local windowWidth, windowHeight = love.window.getDesktopDimensions() - - if self._fullscreen then --save windowed dimensions for later - self._WINWIDTH, self._WINHEIGHT = self._RWIDTH, self._RHEIGHT - elseif not self._WINWIDTH or not self._WINHEIGHT then - self._WINWIDTH, self._WINHEIGHT = windowWidth * .5, windowHeight * .5 - end - - self._RWIDTH = self._fullscreen and windowWidth or winw or self._WINWIDTH - self._RHEIGHT = self._fullscreen and windowHeight or winh or self._WINHEIGHT - - self:initValues() - - love.window.setFullscreen(self._fullscreen, "desktop") - if not self._fullscreen and (winw or winh) then - love.window.setMode(self._RWIDTH, self._RHEIGHT) --set window dimensions - end -end - -function push:resize(w, h) - local pixelScale = love.window.getPixelScale() - if self._highdpi then w, h = w / pixelScale, h / pixelScale end - self._RWIDTH = w - self._RHEIGHT = h - self:initValues() -end - -function push:getWidth() return self._WWIDTH end -function push:getHeight() return self._WHEIGHT end -function push:getDimensions() return self._WWIDTH, self._WHEIGHT end - -return push diff --git a/pong-3/main.lua b/pong-3/main.lua index c4aa3c8..f47de45 100644 --- a/pong-3/main.lua +++ b/pong-3/main.lua @@ -20,6 +20,8 @@ modern systems. ]] +package.path = package.path .. ";../?.lua" + -- push is a library that will allow us to draw our game at a virtual -- resolution, instead of however large our window is; used to provide -- a more retro aesthetic diff --git a/pong-3/push.lua b/pong-3/push.lua deleted file mode 100644 index 0e0709a..0000000 --- a/pong-3/push.lua +++ /dev/null @@ -1,232 +0,0 @@ --- push.lua v0.2 - --- Copyright (c) 2017 Ulysse Ramage --- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: --- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. --- 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 OR COPYRIGHT HOLDERS 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. - -local push = { - - defaults = { - fullscreen = false, - resizable = false, - pixelperfect = false, - highdpi = true, - canvas = true - } - -} -setmetatable(push, push) - ---TODO: rendering resolution? ---TODO: clean up code - -function push:applySettings(settings) - for k, v in pairs(settings) do - self["_" .. k] = v - end -end - -function push:resetSettings() return self:applySettings(self.defaults) end - -function push:setupScreen(WWIDTH, WHEIGHT, RWIDTH, RHEIGHT, settings) - - settings = settings or {} - - self._WWIDTH, self._WHEIGHT = WWIDTH, WHEIGHT - self._RWIDTH, self._RHEIGHT = RWIDTH, RHEIGHT - - self:applySettings(self.defaults) --set defaults first - self:applySettings(settings) --then fill with custom settings - - love.window.setMode( self._RWIDTH, self._RHEIGHT, { - fullscreen = self._fullscreen, - resizable = self._resizable, - highdpi = self._highdpi - } ) - - self:initValues() - - if self._canvas then - self:setupCanvas({ "default" }) --setup canvas - end - - self._borderColor = {0, 0, 0} - - self._drawFunctions = { - ["start"] = self.start, - ["end"] = self.finish - } - - return self -end - -function push:setupCanvas(canvases) - table.insert(canvases, { name = "_render" }) --final render - - self._canvas = true - self.canvases = {} - - for i = 1, #canvases do - self.canvases[i] = { - name = canvases[i].name, - shader = canvases[i].shader, - canvas = love.graphics.newCanvas(self._WWIDTH, self._WHEIGHT) - } - end - - return self -end - -function push:setCanvas(name) - if not self._canvas then return true end - return love.graphics.setCanvas( self:getCanvasTable(name).canvas ) -end -function push:getCanvasTable(name) - for i = 1, #self.canvases do - if self.canvases[i].name == name then - return self.canvases[i] - end - end -end -function push:setShader(name, shader) - if not shader then - self:getCanvasTable("_render").shader = name - else - self:getCanvasTable(name).shader = shader - end -end - -function push:initValues() - self._PSCALE = self._highdpi and love.window.getPixelScale() or 1 - - self._SCALE = { - x = self._RWIDTH/self._WWIDTH * self._PSCALE, - y = self._RHEIGHT/self._WHEIGHT * self._PSCALE - } - - if self._stretched then --if stretched, no need to apply offset - self._OFFSET = {x = 0, y = 0} - else - local scale = math.min(self._SCALE.x, self._SCALE.y) - if self._pixelperfect then scale = math.floor(scale) end - - self._OFFSET = {x = (self._SCALE.x - scale) * (self._WWIDTH/2), y = (self._SCALE.y - scale) * (self._WHEIGHT/2)} - self._SCALE.x, self._SCALE.y = scale, scale --apply same scale to X and Y - end - - self._GWIDTH = self._RWIDTH * self._PSCALE - self._OFFSET.x * 2 - self._GHEIGHT = self._RHEIGHT * self._PSCALE - self._OFFSET.y * 2 -end - ---[[ DEPRECATED ]]-- -function push:apply(operation, shader) - if operation == "start" then - self:start() - elseif operation == "finish" or operation == "end" then - self:finish(shader) - end -end - -function push:start() - if self._canvas then - love.graphics.push() - love.graphics.setCanvas(self.canvases[1].canvas) - else - love.graphics.translate(self._OFFSET.x, self._OFFSET.y) - love.graphics.setScissor(self._OFFSET.x, self._OFFSET.y, self._WWIDTH*self._SCALE.x, self._WHEIGHT*self._SCALE.y) - love.graphics.push() - love.graphics.scale(self._SCALE.x, self._SCALE.y) - end -end - -function push:finish(shader) - love.graphics.setBackgroundColor(unpack(self._borderColor)) - if self._canvas then - local _render = self:getCanvasTable("_render") - - love.graphics.pop() - - love.graphics.setColor(255, 255, 255) - - --draw canvas - love.graphics.setCanvas(_render.canvas) - for i = 1, #self.canvases - 1 do --do not draw _render yet - local _table = self.canvases[i] - love.graphics.setShader(_table.shader) - love.graphics.draw(_table.canvas) - end - love.graphics.setCanvas() - - --draw render - love.graphics.translate(self._OFFSET.x, self._OFFSET.y) - love.graphics.setShader(shader or self:getCanvasTable("_render").shader) - love.graphics.draw(self:getCanvasTable("_render").canvas, 0, 0, 0, self._SCALE.x, self._SCALE.y) - - --clear canvas - for i = 1, #self.canvases do - love.graphics.setCanvas( self.canvases[i].canvas ) - love.graphics.clear() - end - - love.graphics.setCanvas() - love.graphics.setShader() - else - love.graphics.pop() - love.graphics.setScissor() - end -end - -function push:setBorderColor(color, g, b) - self._borderColor = g and {color, g, b} or color -end - -function push:toGame(x, y) - x, y = x - self._OFFSET.x, y - self._OFFSET.y - local normalX, normalY = x / self._GWIDTH, y / self._GHEIGHT - - x = (x >= 0 and x <= self._WWIDTH * self._SCALE.x) and normalX * self._WWIDTH or nil - y = (y >= 0 and y <= self._WHEIGHT * self._SCALE.y) and normalY * self._WHEIGHT or nil - - return x, y -end - ---doesn't work - TODO -function push:toReal(x, y) - return x+self._OFFSET.x, y+self._OFFSET.y -end - -function push:switchFullscreen(winw, winh) - self._fullscreen = not self._fullscreen - local windowWidth, windowHeight = love.window.getDesktopDimensions() - - if self._fullscreen then --save windowed dimensions for later - self._WINWIDTH, self._WINHEIGHT = self._RWIDTH, self._RHEIGHT - elseif not self._WINWIDTH or not self._WINHEIGHT then - self._WINWIDTH, self._WINHEIGHT = windowWidth * .5, windowHeight * .5 - end - - self._RWIDTH = self._fullscreen and windowWidth or winw or self._WINWIDTH - self._RHEIGHT = self._fullscreen and windowHeight or winh or self._WINHEIGHT - - self:initValues() - - love.window.setFullscreen(self._fullscreen, "desktop") - if not self._fullscreen and (winw or winh) then - love.window.setMode(self._RWIDTH, self._RHEIGHT) --set window dimensions - end -end - -function push:resize(w, h) - local pixelScale = love.window.getPixelScale() - if self._highdpi then w, h = w / pixelScale, h / pixelScale end - self._RWIDTH = w - self._RHEIGHT = h - self:initValues() -end - -function push:getWidth() return self._WWIDTH end -function push:getHeight() return self._WHEIGHT end -function push:getDimensions() return self._WWIDTH, self._WHEIGHT end - -return push diff --git a/pong-4/main.lua b/pong-4/main.lua index 8d8bbcb..8667e84 100644 --- a/pong-4/main.lua +++ b/pong-4/main.lua @@ -20,6 +20,8 @@ modern systems. ]] +package.path = package.path .. ";../?.lua" + -- push is a library that will allow us to draw our game at a virtual -- resolution, instead of however large our window is; used to provide -- a more retro aesthetic diff --git a/pong-4/push.lua b/pong-4/push.lua deleted file mode 100644 index 0e0709a..0000000 --- a/pong-4/push.lua +++ /dev/null @@ -1,232 +0,0 @@ --- push.lua v0.2 - --- Copyright (c) 2017 Ulysse Ramage --- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: --- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. --- 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 OR COPYRIGHT HOLDERS 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. - -local push = { - - defaults = { - fullscreen = false, - resizable = false, - pixelperfect = false, - highdpi = true, - canvas = true - } - -} -setmetatable(push, push) - ---TODO: rendering resolution? ---TODO: clean up code - -function push:applySettings(settings) - for k, v in pairs(settings) do - self["_" .. k] = v - end -end - -function push:resetSettings() return self:applySettings(self.defaults) end - -function push:setupScreen(WWIDTH, WHEIGHT, RWIDTH, RHEIGHT, settings) - - settings = settings or {} - - self._WWIDTH, self._WHEIGHT = WWIDTH, WHEIGHT - self._RWIDTH, self._RHEIGHT = RWIDTH, RHEIGHT - - self:applySettings(self.defaults) --set defaults first - self:applySettings(settings) --then fill with custom settings - - love.window.setMode( self._RWIDTH, self._RHEIGHT, { - fullscreen = self._fullscreen, - resizable = self._resizable, - highdpi = self._highdpi - } ) - - self:initValues() - - if self._canvas then - self:setupCanvas({ "default" }) --setup canvas - end - - self._borderColor = {0, 0, 0} - - self._drawFunctions = { - ["start"] = self.start, - ["end"] = self.finish - } - - return self -end - -function push:setupCanvas(canvases) - table.insert(canvases, { name = "_render" }) --final render - - self._canvas = true - self.canvases = {} - - for i = 1, #canvases do - self.canvases[i] = { - name = canvases[i].name, - shader = canvases[i].shader, - canvas = love.graphics.newCanvas(self._WWIDTH, self._WHEIGHT) - } - end - - return self -end - -function push:setCanvas(name) - if not self._canvas then return true end - return love.graphics.setCanvas( self:getCanvasTable(name).canvas ) -end -function push:getCanvasTable(name) - for i = 1, #self.canvases do - if self.canvases[i].name == name then - return self.canvases[i] - end - end -end -function push:setShader(name, shader) - if not shader then - self:getCanvasTable("_render").shader = name - else - self:getCanvasTable(name).shader = shader - end -end - -function push:initValues() - self._PSCALE = self._highdpi and love.window.getPixelScale() or 1 - - self._SCALE = { - x = self._RWIDTH/self._WWIDTH * self._PSCALE, - y = self._RHEIGHT/self._WHEIGHT * self._PSCALE - } - - if self._stretched then --if stretched, no need to apply offset - self._OFFSET = {x = 0, y = 0} - else - local scale = math.min(self._SCALE.x, self._SCALE.y) - if self._pixelperfect then scale = math.floor(scale) end - - self._OFFSET = {x = (self._SCALE.x - scale) * (self._WWIDTH/2), y = (self._SCALE.y - scale) * (self._WHEIGHT/2)} - self._SCALE.x, self._SCALE.y = scale, scale --apply same scale to X and Y - end - - self._GWIDTH = self._RWIDTH * self._PSCALE - self._OFFSET.x * 2 - self._GHEIGHT = self._RHEIGHT * self._PSCALE - self._OFFSET.y * 2 -end - ---[[ DEPRECATED ]]-- -function push:apply(operation, shader) - if operation == "start" then - self:start() - elseif operation == "finish" or operation == "end" then - self:finish(shader) - end -end - -function push:start() - if self._canvas then - love.graphics.push() - love.graphics.setCanvas(self.canvases[1].canvas) - else - love.graphics.translate(self._OFFSET.x, self._OFFSET.y) - love.graphics.setScissor(self._OFFSET.x, self._OFFSET.y, self._WWIDTH*self._SCALE.x, self._WHEIGHT*self._SCALE.y) - love.graphics.push() - love.graphics.scale(self._SCALE.x, self._SCALE.y) - end -end - -function push:finish(shader) - love.graphics.setBackgroundColor(unpack(self._borderColor)) - if self._canvas then - local _render = self:getCanvasTable("_render") - - love.graphics.pop() - - love.graphics.setColor(255, 255, 255) - - --draw canvas - love.graphics.setCanvas(_render.canvas) - for i = 1, #self.canvases - 1 do --do not draw _render yet - local _table = self.canvases[i] - love.graphics.setShader(_table.shader) - love.graphics.draw(_table.canvas) - end - love.graphics.setCanvas() - - --draw render - love.graphics.translate(self._OFFSET.x, self._OFFSET.y) - love.graphics.setShader(shader or self:getCanvasTable("_render").shader) - love.graphics.draw(self:getCanvasTable("_render").canvas, 0, 0, 0, self._SCALE.x, self._SCALE.y) - - --clear canvas - for i = 1, #self.canvases do - love.graphics.setCanvas( self.canvases[i].canvas ) - love.graphics.clear() - end - - love.graphics.setCanvas() - love.graphics.setShader() - else - love.graphics.pop() - love.graphics.setScissor() - end -end - -function push:setBorderColor(color, g, b) - self._borderColor = g and {color, g, b} or color -end - -function push:toGame(x, y) - x, y = x - self._OFFSET.x, y - self._OFFSET.y - local normalX, normalY = x / self._GWIDTH, y / self._GHEIGHT - - x = (x >= 0 and x <= self._WWIDTH * self._SCALE.x) and normalX * self._WWIDTH or nil - y = (y >= 0 and y <= self._WHEIGHT * self._SCALE.y) and normalY * self._WHEIGHT or nil - - return x, y -end - ---doesn't work - TODO -function push:toReal(x, y) - return x+self._OFFSET.x, y+self._OFFSET.y -end - -function push:switchFullscreen(winw, winh) - self._fullscreen = not self._fullscreen - local windowWidth, windowHeight = love.window.getDesktopDimensions() - - if self._fullscreen then --save windowed dimensions for later - self._WINWIDTH, self._WINHEIGHT = self._RWIDTH, self._RHEIGHT - elseif not self._WINWIDTH or not self._WINHEIGHT then - self._WINWIDTH, self._WINHEIGHT = windowWidth * .5, windowHeight * .5 - end - - self._RWIDTH = self._fullscreen and windowWidth or winw or self._WINWIDTH - self._RHEIGHT = self._fullscreen and windowHeight or winh or self._WINHEIGHT - - self:initValues() - - love.window.setFullscreen(self._fullscreen, "desktop") - if not self._fullscreen and (winw or winh) then - love.window.setMode(self._RWIDTH, self._RHEIGHT) --set window dimensions - end -end - -function push:resize(w, h) - local pixelScale = love.window.getPixelScale() - if self._highdpi then w, h = w / pixelScale, h / pixelScale end - self._RWIDTH = w - self._RHEIGHT = h - self:initValues() -end - -function push:getWidth() return self._WWIDTH end -function push:getHeight() return self._WHEIGHT end -function push:getDimensions() return self._WWIDTH, self._WHEIGHT end - -return push diff --git a/pong-5/main.lua b/pong-5/main.lua index 62222eb..00d9b7b 100644 --- a/pong-5/main.lua +++ b/pong-5/main.lua @@ -20,6 +20,8 @@ modern systems. ]] +package.path = package.path .. ";../?.lua" + -- push is a library that will allow us to draw our game at a virtual -- resolution, instead of however large our window is; used to provide -- a more retro aesthetic diff --git a/pong-5/push.lua b/pong-5/push.lua deleted file mode 100644 index 0e0709a..0000000 --- a/pong-5/push.lua +++ /dev/null @@ -1,232 +0,0 @@ --- push.lua v0.2 - --- Copyright (c) 2017 Ulysse Ramage --- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: --- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. --- 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 OR COPYRIGHT HOLDERS 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. - -local push = { - - defaults = { - fullscreen = false, - resizable = false, - pixelperfect = false, - highdpi = true, - canvas = true - } - -} -setmetatable(push, push) - ---TODO: rendering resolution? ---TODO: clean up code - -function push:applySettings(settings) - for k, v in pairs(settings) do - self["_" .. k] = v - end -end - -function push:resetSettings() return self:applySettings(self.defaults) end - -function push:setupScreen(WWIDTH, WHEIGHT, RWIDTH, RHEIGHT, settings) - - settings = settings or {} - - self._WWIDTH, self._WHEIGHT = WWIDTH, WHEIGHT - self._RWIDTH, self._RHEIGHT = RWIDTH, RHEIGHT - - self:applySettings(self.defaults) --set defaults first - self:applySettings(settings) --then fill with custom settings - - love.window.setMode( self._RWIDTH, self._RHEIGHT, { - fullscreen = self._fullscreen, - resizable = self._resizable, - highdpi = self._highdpi - } ) - - self:initValues() - - if self._canvas then - self:setupCanvas({ "default" }) --setup canvas - end - - self._borderColor = {0, 0, 0} - - self._drawFunctions = { - ["start"] = self.start, - ["end"] = self.finish - } - - return self -end - -function push:setupCanvas(canvases) - table.insert(canvases, { name = "_render" }) --final render - - self._canvas = true - self.canvases = {} - - for i = 1, #canvases do - self.canvases[i] = { - name = canvases[i].name, - shader = canvases[i].shader, - canvas = love.graphics.newCanvas(self._WWIDTH, self._WHEIGHT) - } - end - - return self -end - -function push:setCanvas(name) - if not self._canvas then return true end - return love.graphics.setCanvas( self:getCanvasTable(name).canvas ) -end -function push:getCanvasTable(name) - for i = 1, #self.canvases do - if self.canvases[i].name == name then - return self.canvases[i] - end - end -end -function push:setShader(name, shader) - if not shader then - self:getCanvasTable("_render").shader = name - else - self:getCanvasTable(name).shader = shader - end -end - -function push:initValues() - self._PSCALE = self._highdpi and love.window.getPixelScale() or 1 - - self._SCALE = { - x = self._RWIDTH/self._WWIDTH * self._PSCALE, - y = self._RHEIGHT/self._WHEIGHT * self._PSCALE - } - - if self._stretched then --if stretched, no need to apply offset - self._OFFSET = {x = 0, y = 0} - else - local scale = math.min(self._SCALE.x, self._SCALE.y) - if self._pixelperfect then scale = math.floor(scale) end - - self._OFFSET = {x = (self._SCALE.x - scale) * (self._WWIDTH/2), y = (self._SCALE.y - scale) * (self._WHEIGHT/2)} - self._SCALE.x, self._SCALE.y = scale, scale --apply same scale to X and Y - end - - self._GWIDTH = self._RWIDTH * self._PSCALE - self._OFFSET.x * 2 - self._GHEIGHT = self._RHEIGHT * self._PSCALE - self._OFFSET.y * 2 -end - ---[[ DEPRECATED ]]-- -function push:apply(operation, shader) - if operation == "start" then - self:start() - elseif operation == "finish" or operation == "end" then - self:finish(shader) - end -end - -function push:start() - if self._canvas then - love.graphics.push() - love.graphics.setCanvas(self.canvases[1].canvas) - else - love.graphics.translate(self._OFFSET.x, self._OFFSET.y) - love.graphics.setScissor(self._OFFSET.x, self._OFFSET.y, self._WWIDTH*self._SCALE.x, self._WHEIGHT*self._SCALE.y) - love.graphics.push() - love.graphics.scale(self._SCALE.x, self._SCALE.y) - end -end - -function push:finish(shader) - love.graphics.setBackgroundColor(unpack(self._borderColor)) - if self._canvas then - local _render = self:getCanvasTable("_render") - - love.graphics.pop() - - love.graphics.setColor(255, 255, 255) - - --draw canvas - love.graphics.setCanvas(_render.canvas) - for i = 1, #self.canvases - 1 do --do not draw _render yet - local _table = self.canvases[i] - love.graphics.setShader(_table.shader) - love.graphics.draw(_table.canvas) - end - love.graphics.setCanvas() - - --draw render - love.graphics.translate(self._OFFSET.x, self._OFFSET.y) - love.graphics.setShader(shader or self:getCanvasTable("_render").shader) - love.graphics.draw(self:getCanvasTable("_render").canvas, 0, 0, 0, self._SCALE.x, self._SCALE.y) - - --clear canvas - for i = 1, #self.canvases do - love.graphics.setCanvas( self.canvases[i].canvas ) - love.graphics.clear() - end - - love.graphics.setCanvas() - love.graphics.setShader() - else - love.graphics.pop() - love.graphics.setScissor() - end -end - -function push:setBorderColor(color, g, b) - self._borderColor = g and {color, g, b} or color -end - -function push:toGame(x, y) - x, y = x - self._OFFSET.x, y - self._OFFSET.y - local normalX, normalY = x / self._GWIDTH, y / self._GHEIGHT - - x = (x >= 0 and x <= self._WWIDTH * self._SCALE.x) and normalX * self._WWIDTH or nil - y = (y >= 0 and y <= self._WHEIGHT * self._SCALE.y) and normalY * self._WHEIGHT or nil - - return x, y -end - ---doesn't work - TODO -function push:toReal(x, y) - return x+self._OFFSET.x, y+self._OFFSET.y -end - -function push:switchFullscreen(winw, winh) - self._fullscreen = not self._fullscreen - local windowWidth, windowHeight = love.window.getDesktopDimensions() - - if self._fullscreen then --save windowed dimensions for later - self._WINWIDTH, self._WINHEIGHT = self._RWIDTH, self._RHEIGHT - elseif not self._WINWIDTH or not self._WINHEIGHT then - self._WINWIDTH, self._WINHEIGHT = windowWidth * .5, windowHeight * .5 - end - - self._RWIDTH = self._fullscreen and windowWidth or winw or self._WINWIDTH - self._RHEIGHT = self._fullscreen and windowHeight or winh or self._WINHEIGHT - - self:initValues() - - love.window.setFullscreen(self._fullscreen, "desktop") - if not self._fullscreen and (winw or winh) then - love.window.setMode(self._RWIDTH, self._RHEIGHT) --set window dimensions - end -end - -function push:resize(w, h) - local pixelScale = love.window.getPixelScale() - if self._highdpi then w, h = w / pixelScale, h / pixelScale end - self._RWIDTH = w - self._RHEIGHT = h - self:initValues() -end - -function push:getWidth() return self._WWIDTH end -function push:getHeight() return self._WHEIGHT end -function push:getDimensions() return self._WWIDTH, self._WHEIGHT end - -return push diff --git a/pong-6/main.lua b/pong-6/main.lua index f86f891..62b34f9 100644 --- a/pong-6/main.lua +++ b/pong-6/main.lua @@ -20,6 +20,8 @@ modern systems. ]] +package.path = package.path .. ";../?.lua" + -- push is a library that will allow us to draw our game at a virtual -- resolution, instead of however large our window is; used to provide -- a more retro aesthetic diff --git a/pong-6/push.lua b/pong-6/push.lua deleted file mode 100644 index 0e0709a..0000000 --- a/pong-6/push.lua +++ /dev/null @@ -1,232 +0,0 @@ --- push.lua v0.2 - --- Copyright (c) 2017 Ulysse Ramage --- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: --- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. --- 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 OR COPYRIGHT HOLDERS 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. - -local push = { - - defaults = { - fullscreen = false, - resizable = false, - pixelperfect = false, - highdpi = true, - canvas = true - } - -} -setmetatable(push, push) - ---TODO: rendering resolution? ---TODO: clean up code - -function push:applySettings(settings) - for k, v in pairs(settings) do - self["_" .. k] = v - end -end - -function push:resetSettings() return self:applySettings(self.defaults) end - -function push:setupScreen(WWIDTH, WHEIGHT, RWIDTH, RHEIGHT, settings) - - settings = settings or {} - - self._WWIDTH, self._WHEIGHT = WWIDTH, WHEIGHT - self._RWIDTH, self._RHEIGHT = RWIDTH, RHEIGHT - - self:applySettings(self.defaults) --set defaults first - self:applySettings(settings) --then fill with custom settings - - love.window.setMode( self._RWIDTH, self._RHEIGHT, { - fullscreen = self._fullscreen, - resizable = self._resizable, - highdpi = self._highdpi - } ) - - self:initValues() - - if self._canvas then - self:setupCanvas({ "default" }) --setup canvas - end - - self._borderColor = {0, 0, 0} - - self._drawFunctions = { - ["start"] = self.start, - ["end"] = self.finish - } - - return self -end - -function push:setupCanvas(canvases) - table.insert(canvases, { name = "_render" }) --final render - - self._canvas = true - self.canvases = {} - - for i = 1, #canvases do - self.canvases[i] = { - name = canvases[i].name, - shader = canvases[i].shader, - canvas = love.graphics.newCanvas(self._WWIDTH, self._WHEIGHT) - } - end - - return self -end - -function push:setCanvas(name) - if not self._canvas then return true end - return love.graphics.setCanvas( self:getCanvasTable(name).canvas ) -end -function push:getCanvasTable(name) - for i = 1, #self.canvases do - if self.canvases[i].name == name then - return self.canvases[i] - end - end -end -function push:setShader(name, shader) - if not shader then - self:getCanvasTable("_render").shader = name - else - self:getCanvasTable(name).shader = shader - end -end - -function push:initValues() - self._PSCALE = self._highdpi and love.window.getPixelScale() or 1 - - self._SCALE = { - x = self._RWIDTH/self._WWIDTH * self._PSCALE, - y = self._RHEIGHT/self._WHEIGHT * self._PSCALE - } - - if self._stretched then --if stretched, no need to apply offset - self._OFFSET = {x = 0, y = 0} - else - local scale = math.min(self._SCALE.x, self._SCALE.y) - if self._pixelperfect then scale = math.floor(scale) end - - self._OFFSET = {x = (self._SCALE.x - scale) * (self._WWIDTH/2), y = (self._SCALE.y - scale) * (self._WHEIGHT/2)} - self._SCALE.x, self._SCALE.y = scale, scale --apply same scale to X and Y - end - - self._GWIDTH = self._RWIDTH * self._PSCALE - self._OFFSET.x * 2 - self._GHEIGHT = self._RHEIGHT * self._PSCALE - self._OFFSET.y * 2 -end - ---[[ DEPRECATED ]]-- -function push:apply(operation, shader) - if operation == "start" then - self:start() - elseif operation == "finish" or operation == "end" then - self:finish(shader) - end -end - -function push:start() - if self._canvas then - love.graphics.push() - love.graphics.setCanvas(self.canvases[1].canvas) - else - love.graphics.translate(self._OFFSET.x, self._OFFSET.y) - love.graphics.setScissor(self._OFFSET.x, self._OFFSET.y, self._WWIDTH*self._SCALE.x, self._WHEIGHT*self._SCALE.y) - love.graphics.push() - love.graphics.scale(self._SCALE.x, self._SCALE.y) - end -end - -function push:finish(shader) - love.graphics.setBackgroundColor(unpack(self._borderColor)) - if self._canvas then - local _render = self:getCanvasTable("_render") - - love.graphics.pop() - - love.graphics.setColor(255, 255, 255) - - --draw canvas - love.graphics.setCanvas(_render.canvas) - for i = 1, #self.canvases - 1 do --do not draw _render yet - local _table = self.canvases[i] - love.graphics.setShader(_table.shader) - love.graphics.draw(_table.canvas) - end - love.graphics.setCanvas() - - --draw render - love.graphics.translate(self._OFFSET.x, self._OFFSET.y) - love.graphics.setShader(shader or self:getCanvasTable("_render").shader) - love.graphics.draw(self:getCanvasTable("_render").canvas, 0, 0, 0, self._SCALE.x, self._SCALE.y) - - --clear canvas - for i = 1, #self.canvases do - love.graphics.setCanvas( self.canvases[i].canvas ) - love.graphics.clear() - end - - love.graphics.setCanvas() - love.graphics.setShader() - else - love.graphics.pop() - love.graphics.setScissor() - end -end - -function push:setBorderColor(color, g, b) - self._borderColor = g and {color, g, b} or color -end - -function push:toGame(x, y) - x, y = x - self._OFFSET.x, y - self._OFFSET.y - local normalX, normalY = x / self._GWIDTH, y / self._GHEIGHT - - x = (x >= 0 and x <= self._WWIDTH * self._SCALE.x) and normalX * self._WWIDTH or nil - y = (y >= 0 and y <= self._WHEIGHT * self._SCALE.y) and normalY * self._WHEIGHT or nil - - return x, y -end - ---doesn't work - TODO -function push:toReal(x, y) - return x+self._OFFSET.x, y+self._OFFSET.y -end - -function push:switchFullscreen(winw, winh) - self._fullscreen = not self._fullscreen - local windowWidth, windowHeight = love.window.getDesktopDimensions() - - if self._fullscreen then --save windowed dimensions for later - self._WINWIDTH, self._WINHEIGHT = self._RWIDTH, self._RHEIGHT - elseif not self._WINWIDTH or not self._WINHEIGHT then - self._WINWIDTH, self._WINHEIGHT = windowWidth * .5, windowHeight * .5 - end - - self._RWIDTH = self._fullscreen and windowWidth or winw or self._WINWIDTH - self._RHEIGHT = self._fullscreen and windowHeight or winh or self._WINHEIGHT - - self:initValues() - - love.window.setFullscreen(self._fullscreen, "desktop") - if not self._fullscreen and (winw or winh) then - love.window.setMode(self._RWIDTH, self._RHEIGHT) --set window dimensions - end -end - -function push:resize(w, h) - local pixelScale = love.window.getPixelScale() - if self._highdpi then w, h = w / pixelScale, h / pixelScale end - self._RWIDTH = w - self._RHEIGHT = h - self:initValues() -end - -function push:getWidth() return self._WWIDTH end -function push:getHeight() return self._WHEIGHT end -function push:getDimensions() return self._WWIDTH, self._WHEIGHT end - -return push diff --git a/pong-7/main.lua b/pong-7/main.lua index 0c940ee..ea4f094 100644 --- a/pong-7/main.lua +++ b/pong-7/main.lua @@ -20,6 +20,8 @@ modern systems. ]] +package.path = package.path .. ";../?.lua" + -- push is a library that will allow us to draw our game at a virtual -- resolution, instead of however large our window is; used to provide -- a more retro aesthetic diff --git a/pong-7/push.lua b/pong-7/push.lua deleted file mode 100644 index 0e0709a..0000000 --- a/pong-7/push.lua +++ /dev/null @@ -1,232 +0,0 @@ --- push.lua v0.2 - --- Copyright (c) 2017 Ulysse Ramage --- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: --- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. --- 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 OR COPYRIGHT HOLDERS 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. - -local push = { - - defaults = { - fullscreen = false, - resizable = false, - pixelperfect = false, - highdpi = true, - canvas = true - } - -} -setmetatable(push, push) - ---TODO: rendering resolution? ---TODO: clean up code - -function push:applySettings(settings) - for k, v in pairs(settings) do - self["_" .. k] = v - end -end - -function push:resetSettings() return self:applySettings(self.defaults) end - -function push:setupScreen(WWIDTH, WHEIGHT, RWIDTH, RHEIGHT, settings) - - settings = settings or {} - - self._WWIDTH, self._WHEIGHT = WWIDTH, WHEIGHT - self._RWIDTH, self._RHEIGHT = RWIDTH, RHEIGHT - - self:applySettings(self.defaults) --set defaults first - self:applySettings(settings) --then fill with custom settings - - love.window.setMode( self._RWIDTH, self._RHEIGHT, { - fullscreen = self._fullscreen, - resizable = self._resizable, - highdpi = self._highdpi - } ) - - self:initValues() - - if self._canvas then - self:setupCanvas({ "default" }) --setup canvas - end - - self._borderColor = {0, 0, 0} - - self._drawFunctions = { - ["start"] = self.start, - ["end"] = self.finish - } - - return self -end - -function push:setupCanvas(canvases) - table.insert(canvases, { name = "_render" }) --final render - - self._canvas = true - self.canvases = {} - - for i = 1, #canvases do - self.canvases[i] = { - name = canvases[i].name, - shader = canvases[i].shader, - canvas = love.graphics.newCanvas(self._WWIDTH, self._WHEIGHT) - } - end - - return self -end - -function push:setCanvas(name) - if not self._canvas then return true end - return love.graphics.setCanvas( self:getCanvasTable(name).canvas ) -end -function push:getCanvasTable(name) - for i = 1, #self.canvases do - if self.canvases[i].name == name then - return self.canvases[i] - end - end -end -function push:setShader(name, shader) - if not shader then - self:getCanvasTable("_render").shader = name - else - self:getCanvasTable(name).shader = shader - end -end - -function push:initValues() - self._PSCALE = self._highdpi and love.window.getPixelScale() or 1 - - self._SCALE = { - x = self._RWIDTH/self._WWIDTH * self._PSCALE, - y = self._RHEIGHT/self._WHEIGHT * self._PSCALE - } - - if self._stretched then --if stretched, no need to apply offset - self._OFFSET = {x = 0, y = 0} - else - local scale = math.min(self._SCALE.x, self._SCALE.y) - if self._pixelperfect then scale = math.floor(scale) end - - self._OFFSET = {x = (self._SCALE.x - scale) * (self._WWIDTH/2), y = (self._SCALE.y - scale) * (self._WHEIGHT/2)} - self._SCALE.x, self._SCALE.y = scale, scale --apply same scale to X and Y - end - - self._GWIDTH = self._RWIDTH * self._PSCALE - self._OFFSET.x * 2 - self._GHEIGHT = self._RHEIGHT * self._PSCALE - self._OFFSET.y * 2 -end - ---[[ DEPRECATED ]]-- -function push:apply(operation, shader) - if operation == "start" then - self:start() - elseif operation == "finish" or operation == "end" then - self:finish(shader) - end -end - -function push:start() - if self._canvas then - love.graphics.push() - love.graphics.setCanvas(self.canvases[1].canvas) - else - love.graphics.translate(self._OFFSET.x, self._OFFSET.y) - love.graphics.setScissor(self._OFFSET.x, self._OFFSET.y, self._WWIDTH*self._SCALE.x, self._WHEIGHT*self._SCALE.y) - love.graphics.push() - love.graphics.scale(self._SCALE.x, self._SCALE.y) - end -end - -function push:finish(shader) - love.graphics.setBackgroundColor(unpack(self._borderColor)) - if self._canvas then - local _render = self:getCanvasTable("_render") - - love.graphics.pop() - - love.graphics.setColor(255, 255, 255) - - --draw canvas - love.graphics.setCanvas(_render.canvas) - for i = 1, #self.canvases - 1 do --do not draw _render yet - local _table = self.canvases[i] - love.graphics.setShader(_table.shader) - love.graphics.draw(_table.canvas) - end - love.graphics.setCanvas() - - --draw render - love.graphics.translate(self._OFFSET.x, self._OFFSET.y) - love.graphics.setShader(shader or self:getCanvasTable("_render").shader) - love.graphics.draw(self:getCanvasTable("_render").canvas, 0, 0, 0, self._SCALE.x, self._SCALE.y) - - --clear canvas - for i = 1, #self.canvases do - love.graphics.setCanvas( self.canvases[i].canvas ) - love.graphics.clear() - end - - love.graphics.setCanvas() - love.graphics.setShader() - else - love.graphics.pop() - love.graphics.setScissor() - end -end - -function push:setBorderColor(color, g, b) - self._borderColor = g and {color, g, b} or color -end - -function push:toGame(x, y) - x, y = x - self._OFFSET.x, y - self._OFFSET.y - local normalX, normalY = x / self._GWIDTH, y / self._GHEIGHT - - x = (x >= 0 and x <= self._WWIDTH * self._SCALE.x) and normalX * self._WWIDTH or nil - y = (y >= 0 and y <= self._WHEIGHT * self._SCALE.y) and normalY * self._WHEIGHT or nil - - return x, y -end - ---doesn't work - TODO -function push:toReal(x, y) - return x+self._OFFSET.x, y+self._OFFSET.y -end - -function push:switchFullscreen(winw, winh) - self._fullscreen = not self._fullscreen - local windowWidth, windowHeight = love.window.getDesktopDimensions() - - if self._fullscreen then --save windowed dimensions for later - self._WINWIDTH, self._WINHEIGHT = self._RWIDTH, self._RHEIGHT - elseif not self._WINWIDTH or not self._WINHEIGHT then - self._WINWIDTH, self._WINHEIGHT = windowWidth * .5, windowHeight * .5 - end - - self._RWIDTH = self._fullscreen and windowWidth or winw or self._WINWIDTH - self._RHEIGHT = self._fullscreen and windowHeight or winh or self._WINHEIGHT - - self:initValues() - - love.window.setFullscreen(self._fullscreen, "desktop") - if not self._fullscreen and (winw or winh) then - love.window.setMode(self._RWIDTH, self._RHEIGHT) --set window dimensions - end -end - -function push:resize(w, h) - local pixelScale = love.window.getPixelScale() - if self._highdpi then w, h = w / pixelScale, h / pixelScale end - self._RWIDTH = w - self._RHEIGHT = h - self:initValues() -end - -function push:getWidth() return self._WWIDTH end -function push:getHeight() return self._WHEIGHT end -function push:getDimensions() return self._WWIDTH, self._WHEIGHT end - -return push diff --git a/pong-8/main.lua b/pong-8/main.lua index 2d4873f..2a0bcf7 100644 --- a/pong-8/main.lua +++ b/pong-8/main.lua @@ -20,6 +20,8 @@ modern systems. ]] +package.path = package.path .. ";../?.lua" + -- push is a library that will allow us to draw our game at a virtual -- resolution, instead of however large our window is; used to provide -- a more retro aesthetic diff --git a/pong-8/push.lua b/pong-8/push.lua deleted file mode 100644 index 0e0709a..0000000 --- a/pong-8/push.lua +++ /dev/null @@ -1,232 +0,0 @@ --- push.lua v0.2 - --- Copyright (c) 2017 Ulysse Ramage --- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: --- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. --- 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 OR COPYRIGHT HOLDERS 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. - -local push = { - - defaults = { - fullscreen = false, - resizable = false, - pixelperfect = false, - highdpi = true, - canvas = true - } - -} -setmetatable(push, push) - ---TODO: rendering resolution? ---TODO: clean up code - -function push:applySettings(settings) - for k, v in pairs(settings) do - self["_" .. k] = v - end -end - -function push:resetSettings() return self:applySettings(self.defaults) end - -function push:setupScreen(WWIDTH, WHEIGHT, RWIDTH, RHEIGHT, settings) - - settings = settings or {} - - self._WWIDTH, self._WHEIGHT = WWIDTH, WHEIGHT - self._RWIDTH, self._RHEIGHT = RWIDTH, RHEIGHT - - self:applySettings(self.defaults) --set defaults first - self:applySettings(settings) --then fill with custom settings - - love.window.setMode( self._RWIDTH, self._RHEIGHT, { - fullscreen = self._fullscreen, - resizable = self._resizable, - highdpi = self._highdpi - } ) - - self:initValues() - - if self._canvas then - self:setupCanvas({ "default" }) --setup canvas - end - - self._borderColor = {0, 0, 0} - - self._drawFunctions = { - ["start"] = self.start, - ["end"] = self.finish - } - - return self -end - -function push:setupCanvas(canvases) - table.insert(canvases, { name = "_render" }) --final render - - self._canvas = true - self.canvases = {} - - for i = 1, #canvases do - self.canvases[i] = { - name = canvases[i].name, - shader = canvases[i].shader, - canvas = love.graphics.newCanvas(self._WWIDTH, self._WHEIGHT) - } - end - - return self -end - -function push:setCanvas(name) - if not self._canvas then return true end - return love.graphics.setCanvas( self:getCanvasTable(name).canvas ) -end -function push:getCanvasTable(name) - for i = 1, #self.canvases do - if self.canvases[i].name == name then - return self.canvases[i] - end - end -end -function push:setShader(name, shader) - if not shader then - self:getCanvasTable("_render").shader = name - else - self:getCanvasTable(name).shader = shader - end -end - -function push:initValues() - self._PSCALE = self._highdpi and love.window.getPixelScale() or 1 - - self._SCALE = { - x = self._RWIDTH/self._WWIDTH * self._PSCALE, - y = self._RHEIGHT/self._WHEIGHT * self._PSCALE - } - - if self._stretched then --if stretched, no need to apply offset - self._OFFSET = {x = 0, y = 0} - else - local scale = math.min(self._SCALE.x, self._SCALE.y) - if self._pixelperfect then scale = math.floor(scale) end - - self._OFFSET = {x = (self._SCALE.x - scale) * (self._WWIDTH/2), y = (self._SCALE.y - scale) * (self._WHEIGHT/2)} - self._SCALE.x, self._SCALE.y = scale, scale --apply same scale to X and Y - end - - self._GWIDTH = self._RWIDTH * self._PSCALE - self._OFFSET.x * 2 - self._GHEIGHT = self._RHEIGHT * self._PSCALE - self._OFFSET.y * 2 -end - ---[[ DEPRECATED ]]-- -function push:apply(operation, shader) - if operation == "start" then - self:start() - elseif operation == "finish" or operation == "end" then - self:finish(shader) - end -end - -function push:start() - if self._canvas then - love.graphics.push() - love.graphics.setCanvas(self.canvases[1].canvas) - else - love.graphics.translate(self._OFFSET.x, self._OFFSET.y) - love.graphics.setScissor(self._OFFSET.x, self._OFFSET.y, self._WWIDTH*self._SCALE.x, self._WHEIGHT*self._SCALE.y) - love.graphics.push() - love.graphics.scale(self._SCALE.x, self._SCALE.y) - end -end - -function push:finish(shader) - love.graphics.setBackgroundColor(unpack(self._borderColor)) - if self._canvas then - local _render = self:getCanvasTable("_render") - - love.graphics.pop() - - love.graphics.setColor(255, 255, 255) - - --draw canvas - love.graphics.setCanvas(_render.canvas) - for i = 1, #self.canvases - 1 do --do not draw _render yet - local _table = self.canvases[i] - love.graphics.setShader(_table.shader) - love.graphics.draw(_table.canvas) - end - love.graphics.setCanvas() - - --draw render - love.graphics.translate(self._OFFSET.x, self._OFFSET.y) - love.graphics.setShader(shader or self:getCanvasTable("_render").shader) - love.graphics.draw(self:getCanvasTable("_render").canvas, 0, 0, 0, self._SCALE.x, self._SCALE.y) - - --clear canvas - for i = 1, #self.canvases do - love.graphics.setCanvas( self.canvases[i].canvas ) - love.graphics.clear() - end - - love.graphics.setCanvas() - love.graphics.setShader() - else - love.graphics.pop() - love.graphics.setScissor() - end -end - -function push:setBorderColor(color, g, b) - self._borderColor = g and {color, g, b} or color -end - -function push:toGame(x, y) - x, y = x - self._OFFSET.x, y - self._OFFSET.y - local normalX, normalY = x / self._GWIDTH, y / self._GHEIGHT - - x = (x >= 0 and x <= self._WWIDTH * self._SCALE.x) and normalX * self._WWIDTH or nil - y = (y >= 0 and y <= self._WHEIGHT * self._SCALE.y) and normalY * self._WHEIGHT or nil - - return x, y -end - ---doesn't work - TODO -function push:toReal(x, y) - return x+self._OFFSET.x, y+self._OFFSET.y -end - -function push:switchFullscreen(winw, winh) - self._fullscreen = not self._fullscreen - local windowWidth, windowHeight = love.window.getDesktopDimensions() - - if self._fullscreen then --save windowed dimensions for later - self._WINWIDTH, self._WINHEIGHT = self._RWIDTH, self._RHEIGHT - elseif not self._WINWIDTH or not self._WINHEIGHT then - self._WINWIDTH, self._WINHEIGHT = windowWidth * .5, windowHeight * .5 - end - - self._RWIDTH = self._fullscreen and windowWidth or winw or self._WINWIDTH - self._RHEIGHT = self._fullscreen and windowHeight or winh or self._WINHEIGHT - - self:initValues() - - love.window.setFullscreen(self._fullscreen, "desktop") - if not self._fullscreen and (winw or winh) then - love.window.setMode(self._RWIDTH, self._RHEIGHT) --set window dimensions - end -end - -function push:resize(w, h) - local pixelScale = love.window.getPixelScale() - if self._highdpi then w, h = w / pixelScale, h / pixelScale end - self._RWIDTH = w - self._RHEIGHT = h - self:initValues() -end - -function push:getWidth() return self._WWIDTH end -function push:getHeight() return self._WHEIGHT end -function push:getDimensions() return self._WWIDTH, self._WHEIGHT end - -return push diff --git a/pong-9/main.lua b/pong-9/main.lua index d7f1b58..394a386 100644 --- a/pong-9/main.lua +++ b/pong-9/main.lua @@ -20,6 +20,8 @@ modern systems. ]] +package.path = package.path .. ";../?.lua" + -- push is a library that will allow us to draw our game at a virtual -- resolution, instead of however large our window is; used to provide -- a more retro aesthetic diff --git a/pong-9/push.lua b/pong-9/push.lua deleted file mode 100644 index 0e0709a..0000000 --- a/pong-9/push.lua +++ /dev/null @@ -1,232 +0,0 @@ --- push.lua v0.2 - --- Copyright (c) 2017 Ulysse Ramage --- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: --- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. --- 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 OR COPYRIGHT HOLDERS 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. - -local push = { - - defaults = { - fullscreen = false, - resizable = false, - pixelperfect = false, - highdpi = true, - canvas = true - } - -} -setmetatable(push, push) - ---TODO: rendering resolution? ---TODO: clean up code - -function push:applySettings(settings) - for k, v in pairs(settings) do - self["_" .. k] = v - end -end - -function push:resetSettings() return self:applySettings(self.defaults) end - -function push:setupScreen(WWIDTH, WHEIGHT, RWIDTH, RHEIGHT, settings) - - settings = settings or {} - - self._WWIDTH, self._WHEIGHT = WWIDTH, WHEIGHT - self._RWIDTH, self._RHEIGHT = RWIDTH, RHEIGHT - - self:applySettings(self.defaults) --set defaults first - self:applySettings(settings) --then fill with custom settings - - love.window.setMode( self._RWIDTH, self._RHEIGHT, { - fullscreen = self._fullscreen, - resizable = self._resizable, - highdpi = self._highdpi - } ) - - self:initValues() - - if self._canvas then - self:setupCanvas({ "default" }) --setup canvas - end - - self._borderColor = {0, 0, 0} - - self._drawFunctions = { - ["start"] = self.start, - ["end"] = self.finish - } - - return self -end - -function push:setupCanvas(canvases) - table.insert(canvases, { name = "_render" }) --final render - - self._canvas = true - self.canvases = {} - - for i = 1, #canvases do - self.canvases[i] = { - name = canvases[i].name, - shader = canvases[i].shader, - canvas = love.graphics.newCanvas(self._WWIDTH, self._WHEIGHT) - } - end - - return self -end - -function push:setCanvas(name) - if not self._canvas then return true end - return love.graphics.setCanvas( self:getCanvasTable(name).canvas ) -end -function push:getCanvasTable(name) - for i = 1, #self.canvases do - if self.canvases[i].name == name then - return self.canvases[i] - end - end -end -function push:setShader(name, shader) - if not shader then - self:getCanvasTable("_render").shader = name - else - self:getCanvasTable(name).shader = shader - end -end - -function push:initValues() - self._PSCALE = self._highdpi and love.window.getPixelScale() or 1 - - self._SCALE = { - x = self._RWIDTH/self._WWIDTH * self._PSCALE, - y = self._RHEIGHT/self._WHEIGHT * self._PSCALE - } - - if self._stretched then --if stretched, no need to apply offset - self._OFFSET = {x = 0, y = 0} - else - local scale = math.min(self._SCALE.x, self._SCALE.y) - if self._pixelperfect then scale = math.floor(scale) end - - self._OFFSET = {x = (self._SCALE.x - scale) * (self._WWIDTH/2), y = (self._SCALE.y - scale) * (self._WHEIGHT/2)} - self._SCALE.x, self._SCALE.y = scale, scale --apply same scale to X and Y - end - - self._GWIDTH = self._RWIDTH * self._PSCALE - self._OFFSET.x * 2 - self._GHEIGHT = self._RHEIGHT * self._PSCALE - self._OFFSET.y * 2 -end - ---[[ DEPRECATED ]]-- -function push:apply(operation, shader) - if operation == "start" then - self:start() - elseif operation == "finish" or operation == "end" then - self:finish(shader) - end -end - -function push:start() - if self._canvas then - love.graphics.push() - love.graphics.setCanvas(self.canvases[1].canvas) - else - love.graphics.translate(self._OFFSET.x, self._OFFSET.y) - love.graphics.setScissor(self._OFFSET.x, self._OFFSET.y, self._WWIDTH*self._SCALE.x, self._WHEIGHT*self._SCALE.y) - love.graphics.push() - love.graphics.scale(self._SCALE.x, self._SCALE.y) - end -end - -function push:finish(shader) - love.graphics.setBackgroundColor(unpack(self._borderColor)) - if self._canvas then - local _render = self:getCanvasTable("_render") - - love.graphics.pop() - - love.graphics.setColor(255, 255, 255) - - --draw canvas - love.graphics.setCanvas(_render.canvas) - for i = 1, #self.canvases - 1 do --do not draw _render yet - local _table = self.canvases[i] - love.graphics.setShader(_table.shader) - love.graphics.draw(_table.canvas) - end - love.graphics.setCanvas() - - --draw render - love.graphics.translate(self._OFFSET.x, self._OFFSET.y) - love.graphics.setShader(shader or self:getCanvasTable("_render").shader) - love.graphics.draw(self:getCanvasTable("_render").canvas, 0, 0, 0, self._SCALE.x, self._SCALE.y) - - --clear canvas - for i = 1, #self.canvases do - love.graphics.setCanvas( self.canvases[i].canvas ) - love.graphics.clear() - end - - love.graphics.setCanvas() - love.graphics.setShader() - else - love.graphics.pop() - love.graphics.setScissor() - end -end - -function push:setBorderColor(color, g, b) - self._borderColor = g and {color, g, b} or color -end - -function push:toGame(x, y) - x, y = x - self._OFFSET.x, y - self._OFFSET.y - local normalX, normalY = x / self._GWIDTH, y / self._GHEIGHT - - x = (x >= 0 and x <= self._WWIDTH * self._SCALE.x) and normalX * self._WWIDTH or nil - y = (y >= 0 and y <= self._WHEIGHT * self._SCALE.y) and normalY * self._WHEIGHT or nil - - return x, y -end - ---doesn't work - TODO -function push:toReal(x, y) - return x+self._OFFSET.x, y+self._OFFSET.y -end - -function push:switchFullscreen(winw, winh) - self._fullscreen = not self._fullscreen - local windowWidth, windowHeight = love.window.getDesktopDimensions() - - if self._fullscreen then --save windowed dimensions for later - self._WINWIDTH, self._WINHEIGHT = self._RWIDTH, self._RHEIGHT - elseif not self._WINWIDTH or not self._WINHEIGHT then - self._WINWIDTH, self._WINHEIGHT = windowWidth * .5, windowHeight * .5 - end - - self._RWIDTH = self._fullscreen and windowWidth or winw or self._WINWIDTH - self._RHEIGHT = self._fullscreen and windowHeight or winh or self._WINHEIGHT - - self:initValues() - - love.window.setFullscreen(self._fullscreen, "desktop") - if not self._fullscreen and (winw or winh) then - love.window.setMode(self._RWIDTH, self._RHEIGHT) --set window dimensions - end -end - -function push:resize(w, h) - local pixelScale = love.window.getPixelScale() - if self._highdpi then w, h = w / pixelScale, h / pixelScale end - self._RWIDTH = w - self._RHEIGHT = h - self:initValues() -end - -function push:getWidth() return self._WWIDTH end -function push:getHeight() return self._WHEIGHT end -function push:getDimensions() return self._WWIDTH, self._WHEIGHT end - -return push diff --git a/pong-final/main.lua b/pong-final/main.lua index c8df5fc..3ca8fc0 100644 --- a/pong-final/main.lua +++ b/pong-final/main.lua @@ -17,6 +17,8 @@ modern systems. ]] +package.path = package.path .. ";../?.lua" + -- push is a library that will allow us to draw our game at a virtual -- resolution, instead of however large our window is; used to provide -- a more retro aesthetic diff --git a/pong-final/push.lua b/push.lua similarity index 100% rename from pong-final/push.lua rename to push.lua From 2a4ab88f19f3178f0c427b89b52a80a68fe8deaf Mon Sep 17 00:00:00 2001 From: simleo Date: Sat, 3 Nov 2018 14:51:30 +0100 Subject: [PATCH 2/2] fix call to graphics.clear for love 11 --- pong-10/main.lua | 12 +++++++++++- pong-11/main.lua | 12 +++++++++++- pong-12/main.lua | 12 +++++++++++- pong-2/main.lua | 12 +++++++++++- pong-3/main.lua | 12 +++++++++++- pong-4/main.lua | 12 +++++++++++- pong-5/main.lua | 12 +++++++++++- pong-6/main.lua | 12 +++++++++++- pong-7/main.lua | 12 +++++++++++- pong-8/main.lua | 12 +++++++++++- pong-9/main.lua | 12 +++++++++++- pong-final/main.lua | 12 +++++++++++- 12 files changed, 132 insertions(+), 12 deletions(-) diff --git a/pong-10/main.lua b/pong-10/main.lua index 11eb3b7..4078548 100644 --- a/pong-10/main.lua +++ b/pong-10/main.lua @@ -53,6 +53,16 @@ VIRTUAL_HEIGHT = 243 -- speed at which we will move our paddle; multiplied by dt in update PADDLE_SPEED = 200 +--[[ + Love 11 compat +]] +function clear(r, g, b, a) + if love.getVersion() >= 11 then + r, g, b, a = r / 255, g / 255, b / 255, a / 255 + end + love.graphics.clear(r, g, b, a) +end + --[[ Runs when the game first starts up, only once; used to initialize the game. ]] @@ -257,7 +267,7 @@ function love.draw() -- clear the screen with a specific color; in this case, a color similar -- to some versions of the original Pong - love.graphics.clear(40, 45, 52, 255) + clear(40, 45, 52, 255) love.graphics.setFont(smallFont) diff --git a/pong-11/main.lua b/pong-11/main.lua index 43ce1e5..a5c7651 100644 --- a/pong-11/main.lua +++ b/pong-11/main.lua @@ -53,6 +53,16 @@ VIRTUAL_HEIGHT = 243 -- speed at which we will move our paddle; multiplied by dt in update PADDLE_SPEED = 200 +--[[ + Love 11 compat +]] +function clear(r, g, b, a) + if love.getVersion() >= 11 then + r, g, b, a = r / 255, g / 255, b / 255, a / 255 + end + love.graphics.clear(r, g, b, a) +end + --[[ Runs when the game first starts up, only once; used to initialize the game. ]] @@ -273,7 +283,7 @@ function love.draw() -- clear the screen with a specific color; in this case, a color similar -- to some versions of the original Pong - love.graphics.clear(40, 45, 52, 255) + clear(40, 45, 52, 255) love.graphics.setFont(smallFont) diff --git a/pong-12/main.lua b/pong-12/main.lua index e1948cb..573b879 100644 --- a/pong-12/main.lua +++ b/pong-12/main.lua @@ -53,6 +53,16 @@ VIRTUAL_HEIGHT = 243 -- speed at which we will move our paddle; multiplied by dt in update PADDLE_SPEED = 200 +--[[ + Love 11 compat +]] +function clear(r, g, b, a) + if love.getVersion() >= 11 then + r, g, b, a = r / 255, g / 255, b / 255, a / 255 + end + love.graphics.clear(r, g, b, a) +end + --[[ Runs when the game first starts up, only once; used to initialize the game. ]] @@ -281,7 +291,7 @@ function love.draw() -- clear the screen with a specific color; in this case, a color similar -- to some versions of the original Pong - love.graphics.clear(40, 45, 52, 255) + clear(40, 45, 52, 255) love.graphics.setFont(smallFont) diff --git a/pong-2/main.lua b/pong-2/main.lua index 9ad82bf..54abf5b 100644 --- a/pong-2/main.lua +++ b/pong-2/main.lua @@ -35,6 +35,16 @@ WINDOW_HEIGHT = 720 VIRTUAL_WIDTH = 432 VIRTUAL_HEIGHT = 243 +--[[ + Love 11 compat +]] +function clear(r, g, b, a) + if love.getVersion() >= 11 then + r, g, b, a = r / 255, g / 255, b / 255, a / 255 + end + love.graphics.clear(r, g, b, a) +end + --[[ Runs when the game first starts up, only once; used to initialize the game. ]] @@ -77,7 +87,7 @@ function love.draw() -- clear the screen with a specific color; in this case, a color similar -- to some versions of the original Pong - love.graphics.clear(40, 45, 52, 255) + clear(40, 45, 52, 255) -- draw welcome text toward the top of the screen love.graphics.printf('Hello Pong!', 0, 20, VIRTUAL_WIDTH, 'center') diff --git a/pong-3/main.lua b/pong-3/main.lua index f47de45..3a6e975 100644 --- a/pong-3/main.lua +++ b/pong-3/main.lua @@ -38,6 +38,16 @@ VIRTUAL_HEIGHT = 243 -- speed at which we will move our paddle; multiplied by dt in update PADDLE_SPEED = 200 +--[[ + Love 11 compat +]] +function clear(r, g, b, a) + if love.getVersion() >= 11 then + r, g, b, a = r / 255, g / 255, b / 255, a / 255 + end + love.graphics.clear(r, g, b, a) +end + --[[ Runs when the game first starts up, only once; used to initialize the game. ]] @@ -116,7 +126,7 @@ function love.draw() -- clear the screen with a specific color; in this case, a color similar -- to some versions of the original Pong - love.graphics.clear(40, 45, 52, 255) + clear(40, 45, 52, 255) -- draw welcome text toward the top of the screen love.graphics.setFont(smallFont) diff --git a/pong-4/main.lua b/pong-4/main.lua index 8667e84..d80838b 100644 --- a/pong-4/main.lua +++ b/pong-4/main.lua @@ -38,6 +38,16 @@ VIRTUAL_HEIGHT = 243 -- speed at which we will move our paddle; multiplied by dt in update PADDLE_SPEED = 200 +--[[ + Love 11 compat +]] +function clear(r, g, b, a) + if love.getVersion() >= 11 then + r, g, b, a = r / 255, g / 255, b / 255, a / 255 + end + love.graphics.clear(r, g, b, a) +end + --[[ Runs when the game first starts up, only once; used to initialize the game. ]] @@ -155,7 +165,7 @@ function love.draw() -- clear the screen with a specific color; in this case, a color similar -- to some versions of the original Pong - love.graphics.clear(40, 45, 52, 255) + clear(40, 45, 52, 255) -- draw different things based on the state of the game love.graphics.setFont(smallFont) diff --git a/pong-5/main.lua b/pong-5/main.lua index 00d9b7b..b2adaa5 100644 --- a/pong-5/main.lua +++ b/pong-5/main.lua @@ -53,6 +53,16 @@ VIRTUAL_HEIGHT = 243 -- speed at which we will move our paddle; multiplied by dt in update PADDLE_SPEED = 200 +--[[ + Love 11 compat +]] +function clear(r, g, b, a) + if love.getVersion() >= 11 then + r, g, b, a = r / 255, g / 255, b / 255, a / 255 + end + love.graphics.clear(r, g, b, a) +end + --[[ Runs when the game first starts up, only once; used to initialize the game. ]] @@ -156,7 +166,7 @@ function love.draw() -- clear the screen with a specific color; in this case, a color similar -- to some versions of the original Pong - love.graphics.clear(40, 45, 52, 255) + clear(40, 45, 52, 255) -- draw different things based on the state of the game love.graphics.setFont(smallFont) diff --git a/pong-6/main.lua b/pong-6/main.lua index 62b34f9..df2dc63 100644 --- a/pong-6/main.lua +++ b/pong-6/main.lua @@ -53,6 +53,16 @@ VIRTUAL_HEIGHT = 243 -- speed at which we will move our paddle; multiplied by dt in update PADDLE_SPEED = 200 +--[[ + Love 11 compat +]] +function clear(r, g, b, a) + if love.getVersion() >= 11 then + r, g, b, a = r / 255, g / 255, b / 255, a / 255 + end + love.graphics.clear(r, g, b, a) +end + --[[ Runs when the game first starts up, only once; used to initialize the game. ]] @@ -170,7 +180,7 @@ function love.draw() -- clear the screen with a specific color; in this case, a color similar -- to some versions of the original Pong - love.graphics.clear(40, 45, 52, 255) + clear(40, 45, 52, 255) -- draw different things based on the state of the game love.graphics.setFont(smallFont) diff --git a/pong-7/main.lua b/pong-7/main.lua index ea4f094..73190c7 100644 --- a/pong-7/main.lua +++ b/pong-7/main.lua @@ -53,6 +53,16 @@ VIRTUAL_HEIGHT = 243 -- speed at which we will move our paddle; multiplied by dt in update PADDLE_SPEED = 200 +--[[ + Love 11 compat +]] +function clear(r, g, b, a) + if love.getVersion() >= 11 then + r, g, b, a = r / 255, g / 255, b / 255, a / 255 + end + love.graphics.clear(r, g, b, a) +end + --[[ Runs when the game first starts up, only once; used to initialize the game. ]] @@ -209,7 +219,7 @@ function love.draw() -- clear the screen with a specific color; in this case, a color similar -- to some versions of the original Pong - love.graphics.clear(40, 45, 52, 255) + clear(40, 45, 52, 255) -- draw different things based on the state of the game love.graphics.setFont(smallFont) diff --git a/pong-8/main.lua b/pong-8/main.lua index 2a0bcf7..6db3382 100644 --- a/pong-8/main.lua +++ b/pong-8/main.lua @@ -53,6 +53,16 @@ VIRTUAL_HEIGHT = 243 -- speed at which we will move our paddle; multiplied by dt in update PADDLE_SPEED = 200 +--[[ + Love 11 compat +]] +function clear(r, g, b, a) + if love.getVersion() >= 11 then + r, g, b, a = r / 255, g / 255, b / 255, a / 255 + end + love.graphics.clear(r, g, b, a) +end + --[[ Runs when the game first starts up, only once; used to initialize the game. ]] @@ -225,7 +235,7 @@ function love.draw() -- clear the screen with a specific color; in this case, a color similar -- to some versions of the original Pong - love.graphics.clear(40, 45, 52, 255) + clear(40, 45, 52, 255) -- draw different things based on the state of the game love.graphics.setFont(smallFont) diff --git a/pong-9/main.lua b/pong-9/main.lua index 394a386..a0f3d9e 100644 --- a/pong-9/main.lua +++ b/pong-9/main.lua @@ -53,6 +53,16 @@ VIRTUAL_HEIGHT = 243 -- speed at which we will move our paddle; multiplied by dt in update PADDLE_SPEED = 200 +--[[ + Love 11 compat +]] +function clear(r, g, b, a) + if love.getVersion() >= 11 then + r, g, b, a = r / 255, g / 255, b / 255, a / 255 + end + love.graphics.clear(r, g, b, a) +end + --[[ Runs when the game first starts up, only once; used to initialize the game. ]] @@ -228,7 +238,7 @@ function love.draw() -- clear the screen with a specific color; in this case, a color similar -- to some versions of the original Pong - love.graphics.clear(40, 45, 52, 255) + clear(40, 45, 52, 255) love.graphics.setFont(smallFont) diff --git a/pong-final/main.lua b/pong-final/main.lua index 3ca8fc0..00972b8 100644 --- a/pong-final/main.lua +++ b/pong-final/main.lua @@ -52,6 +52,16 @@ VIRTUAL_HEIGHT = 243 -- paddle movement speed PADDLE_SPEED = 200 +--[[ + Love 11 compat +]] +function clear(r, g, b, a) + if love.getVersion() >= 11 then + r, g, b, a = r / 255, g / 255, b / 255, a / 255 + end + love.graphics.clear(r, g, b, a) +end + --[[ Called just once at the beginning of the game; used to set up game objects, variables, etc. and prepare the game world. @@ -305,7 +315,7 @@ function love.draw() -- begin drawing with push, in our virtual resolution push:start() - love.graphics.clear(40, 45, 52, 255) + clear(40, 45, 52, 255) -- render different things depending on which part of the game we're in if gameState == 'start' then