From b33dc78a0ff1b34b27a404be412c69aa7619fa2b Mon Sep 17 00:00:00 2001 From: jaujau088 Date: Wed, 26 Aug 2020 12:49:16 +0200 Subject: [PATCH 1/2] updated breakout13 codes for Lua v11 and fixed few bugs --- breakout13/lib/push.lua | 512 ++++++++++-------- breakout13/main.lua | 43 +- breakout13/src/Brick.lua | 8 +- breakout13/src/states/EnterHighScoreState.lua | 17 +- breakout13/src/states/PaddleSelectState.lua | 17 +- breakout13/src/states/StartState.lua | 13 +- 6 files changed, 345 insertions(+), 265 deletions(-) diff --git a/breakout13/lib/push.lua b/breakout13/lib/push.lua index 0e0709a..57aab42 100644 --- a/breakout13/lib/push.lua +++ b/breakout13/lib/push.lua @@ -1,232 +1,280 @@ --- 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 +-- push.lua v0.4 + +-- Copyright (c) 2020 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 love11 = love.getVersion() == 11 +local getDPI = love11 and love.window.getDPIScale or love.window.getPixelScale +local windowUpdateMode = love11 and love.window.updateMode or function(width, height, settings) + local _, _, flags = love.window.getMode() + for k, v in pairs(settings) do flags[k] = v end + love.window.setMode(width, height, flags) +end + +local push = { + + defaults = { + fullscreen = false, + resizable = false, + pixelperfect = false, + highdpi = true, + canvas = true, + stencil = true + } + +} +setmetatable(push, push) + +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 + + windowUpdateMode(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", private = true }) --final render + + self._canvas = true + self.canvases = {} + + for i = 1, #canvases do + push:addCanvas(canvases[i]) + end + + return self +end +function push:addCanvas(params) + table.insert(self.canvases, { + name = params.name, + private = params.private, + shader = params.shader, + canvas = love.graphics.newCanvas(self._WWIDTH, self._WHEIGHT), + stencil = params.stencil or self._stencil + }) +end + +function push:setCanvas(name) + if not self._canvas then return true end + local canvasTable = self:getCanvasTable(name) + return love.graphics.setCanvas({ canvasTable.canvas, stencil = canvasTable.stencil }) +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 = (not love11 and self._highdpi) and getDPI() 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 + +function push:apply(operation, shader) + self._drawFunctions[operation](self, shader) +end + +function push:start() + if self._canvas then + love.graphics.push() + love.graphics.setCanvas({ self.canvases[1].canvas, stencil = self.canvases[1].stencil }) + + 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:applyShaders(canvas, shaders) + local _shader = love.graphics.getShader() + if #shaders <= 1 then + love.graphics.setShader(shaders[1]) + love.graphics.draw(canvas) + else + local _canvas = love.graphics.getCanvas() + + local _tmp = self:getCanvasTable("_tmp") + if not _tmp then --create temp canvas only if needed + self:addCanvas({ name = "_tmp", private = true, shader = nil }) + _tmp = self:getCanvasTable("_tmp") + end + + love.graphics.push() + love.graphics.origin() + local outputCanvas + for i = 1, #shaders do + local inputCanvas = i % 2 == 1 and canvas or _tmp.canvas + outputCanvas = i % 2 == 0 and canvas or _tmp.canvas + love.graphics.setCanvas(outputCanvas) + love.graphics.clear() + love.graphics.setShader(shaders[i]) + love.graphics.draw(inputCanvas) + love.graphics.setCanvas(inputCanvas) + end + love.graphics.pop() + + love.graphics.setCanvas(_canvas) + love.graphics.draw(outputCanvas) + end + love.graphics.setShader(_shader) +end + +function push:finish(shader) + love.graphics.setBackgroundColor(unpack(self._borderColor)) + if self._canvas then + local _render = self:getCanvasTable("_render") + + love.graphics.pop() + + local white = love11 and 1 or 255 + love.graphics.setColor(white, white, white) + + --draw canvas + love.graphics.setCanvas(_render.canvas) + for i = 1, #self.canvases do --do not draw _render yet + local _table = self.canvases[i] + if not _table.private then + local _canvas = _table.canvas + local _shader = _table.shader + self:applyShaders(_canvas, type(_shader) == "table" and _shader or { _shader }) + end + end + love.graphics.setCanvas() + + --draw render + love.graphics.translate(self._OFFSET.x, self._OFFSET.y) + local shader = shader or _render.shader + love.graphics.push() + love.graphics.scale(self._SCALE.x, self._SCALE.y) + self:applyShaders(_render.canvas, type(shader) == "table" and shader or { shader }) + love.graphics.pop() + + --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 + windowUpdateMode(self._RWIDTH, self._RHEIGHT) --set window dimensions + end +end + +function push:resize(w, h) + if self._highdpi then w, h = w / self._PSCALE, h / self._PSCALE 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/breakout13/main.lua b/breakout13/main.lua index 0f7e091..b1ed897 100644 --- a/breakout13/main.lua +++ b/breakout13/main.lua @@ -22,6 +22,14 @@ Credit for music (great loop): http://freesound.org/people/joshuaempyre/sounds/251461/ http://www.soundcloud.com/empyreanma + + Update to LÖVE v11 and few bugs fixation by: Jauhari Alafi + CS50 student 2020 (online) Netherlands + jaujau088@gmail.com + - Changed setColor values from base 255 to base 1 + - Added source type to the love.audio.newSource function (i.e. 'static' or 'stream') + for documentation when to use either of them, see: https://love2d.org/wiki/Tutorial:Audio + - Updated love.filesystem.exists to love.filesystem.getInfo ]] require 'src/Dependencies' @@ -80,21 +88,21 @@ function love.load() -- set up our sound effects; later, we can just index this table and -- call each entry's `play` method gSounds = { - ['paddle-hit'] = love.audio.newSource('sounds/paddle_hit.wav'), - ['score'] = love.audio.newSource('sounds/score.wav'), - ['wall-hit'] = love.audio.newSource('sounds/wall_hit.wav'), - ['confirm'] = love.audio.newSource('sounds/confirm.wav'), - ['select'] = love.audio.newSource('sounds/select.wav'), - ['no-select'] = love.audio.newSource('sounds/no-select.wav'), - ['brick-hit-1'] = love.audio.newSource('sounds/brick-hit-1.wav'), - ['brick-hit-2'] = love.audio.newSource('sounds/brick-hit-2.wav'), - ['hurt'] = love.audio.newSource('sounds/hurt.wav'), - ['victory'] = love.audio.newSource('sounds/victory.wav'), - ['recover'] = love.audio.newSource('sounds/recover.wav'), - ['high-score'] = love.audio.newSource('sounds/high_score.wav'), - ['pause'] = love.audio.newSource('sounds/pause.wav'), - - ['music'] = love.audio.newSource('sounds/music.wav') + ['paddle-hit'] = love.audio.newSource('sounds/paddle_hit.wav', 'static'), + ['score'] = love.audio.newSource('sounds/score.wav', 'static'), + ['wall-hit'] = love.audio.newSource('sounds/wall_hit.wav', 'static'), + ['confirm'] = love.audio.newSource('sounds/confirm.wav', 'static'), + ['select'] = love.audio.newSource('sounds/select.wav', 'static'), + ['no-select'] = love.audio.newSource('sounds/no-select.wav', 'static'), + ['brick-hit-1'] = love.audio.newSource('sounds/brick-hit-1.wav', 'static'), + ['brick-hit-2'] = love.audio.newSource('sounds/brick-hit-2.wav', 'static'), + ['hurt'] = love.audio.newSource('sounds/hurt.wav', 'static'), + ['victory'] = love.audio.newSource('sounds/victory.wav', 'static'), + ['recover'] = love.audio.newSource('sounds/recover.wav', 'static'), + ['high-score'] = love.audio.newSource('sounds/high_score.wav', 'static'), + ['pause'] = love.audio.newSource('sounds/pause.wav', 'static'), + + ['music'] = love.audio.newSource('sounds/music.wav', 'stream') } -- the state machine we'll be using to transition between various states @@ -220,7 +228,8 @@ function loadHighScores() love.filesystem.setIdentity('breakout') -- if the file doesn't exist, initialize it with some default scores - if not love.filesystem.exists('breakout.lst') then + -- Old version: love.filesystem.exists, LÖVE v11: love.filesystem.getInfo + if not love.filesystem.getInfo('breakout.lst') then local scores = '' for i = 10, 1, -1 do scores = scores .. 'CTO\n' @@ -289,7 +298,7 @@ end function displayFPS() -- simple FPS display across all states love.graphics.setFont(gFonts['small']) - love.graphics.setColor(0, 255, 0, 255) + love.graphics.setColor(0, 1, 0, 1) love.graphics.print('FPS: ' .. tostring(love.timer.getFPS()), 5, 5) end diff --git a/breakout13/src/Brick.lua b/breakout13/src/Brick.lua index 6e21019..c5918a0 100644 --- a/breakout13/src/Brick.lua +++ b/breakout13/src/Brick.lua @@ -12,6 +12,11 @@ the ball will bounce away depending on the angle of collision. When all bricks are cleared in the current map, the player should be taken to a new layout of bricks. + + Update to LÖVE v11 and few bugs fixation by: Jauhari Alafi + CS50 student 2020 (online) Netherlands + jaujau088@gmail.com + - Updated ParticleSystem:setAreaSpread to ParticleSystem:setEmissionArea ]] Brick = Class{} @@ -77,7 +82,8 @@ function Brick:init(x, y) self.psystem:setLinearAcceleration(-15, 0, 15, 80) -- spread of particles; normal looks more natural than uniform - self.psystem:setAreaSpread('normal', 10, 10) + -- Old version: self.psystem:setAreaSpread, LÖVE v11: self.psystem:setEmissionArea + self.psystem:setEmissionArea('normal', 10, 10) end --[[ diff --git a/breakout13/src/states/EnterHighScoreState.lua b/breakout13/src/states/EnterHighScoreState.lua index b94eaba..ffd4a37 100644 --- a/breakout13/src/states/EnterHighScoreState.lua +++ b/breakout13/src/states/EnterHighScoreState.lua @@ -8,6 +8,11 @@ cogden@cs50.harvard.edu Screen that allows us to input a new high score in the form of three characters, arcade-style. + + Update to LÖVE v11 and few bugs fixation by: Jauhari Alafi + CS50 student 2020 (online) Netherlands + jaujau088@gmail.com + - Changed setColor values from base 255 to base 1 ]] EnterHighScoreState = Class{__includes = BaseState} @@ -93,22 +98,22 @@ function EnterHighScoreState:render() -- render all three characters of the name -- if highlightedChar == 1 then - love.graphics.setColor(103, 255, 255, 255) + love.graphics.setColor(103/255, 1, 1, 1) end love.graphics.print(string.char(chars[1]), VIRTUAL_WIDTH / 2 - 28, VIRTUAL_HEIGHT / 2) - love.graphics.setColor(255, 255, 255, 255) + love.graphics.setColor(1, 1, 1, 1) if highlightedChar == 2 then - love.graphics.setColor(103, 255, 255, 255) + love.graphics.setColor(103/255, 1, 1, 1) end love.graphics.print(string.char(chars[2]), VIRTUAL_WIDTH / 2 - 6, VIRTUAL_HEIGHT / 2) - love.graphics.setColor(255, 255, 255, 255) + love.graphics.setColor(1, 1, 1, 1) if highlightedChar == 3 then - love.graphics.setColor(103, 255, 255, 255) + love.graphics.setColor(103/255, 1, 1, 1) end love.graphics.print(string.char(chars[3]), VIRTUAL_WIDTH / 2 + 20, VIRTUAL_HEIGHT / 2) - love.graphics.setColor(255, 255, 255, 255) + love.graphics.setColor(1, 1, 1, 1) love.graphics.setFont(gFonts['small']) love.graphics.printf('Press Enter to confirm!', 0, VIRTUAL_HEIGHT - 18, diff --git a/breakout13/src/states/PaddleSelectState.lua b/breakout13/src/states/PaddleSelectState.lua index fb8ff84..23de65a 100644 --- a/breakout13/src/states/PaddleSelectState.lua +++ b/breakout13/src/states/PaddleSelectState.lua @@ -10,6 +10,13 @@ Represents the state the game is in when we've just started; should simply display "Breakout" in large text, as well as a message to press Enter to begin. + + Update to LÖVE v11 and few bugs fixation by: Jauhari Alafi + CS50 student 2020 (online) Netherlands + jaujau088@gmail.com + - Changed setColor values from base 255 to base 1 + - Changed "level" value that is passed on to serve state from 32 to 1 + so that level now starts from 1 instead of 32 ]] PaddleSelectState = Class{__includes = BaseState} @@ -51,7 +58,7 @@ function PaddleSelectState:update(dt) health = 3, score = 0, highScores = self.highScores, - level = 32, + level = 1, recoverPoints = 5000 }) end @@ -74,27 +81,27 @@ function PaddleSelectState:render() -- in a shadowy form to let us know we're as far left as we can go if self.currentPaddle == 1 then -- tint; give it a dark gray with half opacity - love.graphics.setColor(40, 40, 40, 128) + love.graphics.setColor(40/255, 40/255, 40/255, 128/255) end love.graphics.draw(gTextures['arrows'], gFrames['arrows'][1], VIRTUAL_WIDTH / 4 - 24, VIRTUAL_HEIGHT - VIRTUAL_HEIGHT / 3) -- reset drawing color to full white for proper rendering - love.graphics.setColor(255, 255, 255, 255) + love.graphics.setColor(1, 1, 1, 1) -- right arrow; should render normally if we're less than 4, else -- in a shadowy form to let us know we're as far right as we can go if self.currentPaddle == 4 then -- tint; give it a dark gray with half opacity - love.graphics.setColor(40, 40, 40, 128) + love.graphics.setColor(40/255, 40/255, 40/255, 128/255) end love.graphics.draw(gTextures['arrows'], gFrames['arrows'][2], VIRTUAL_WIDTH - VIRTUAL_WIDTH / 4, VIRTUAL_HEIGHT - VIRTUAL_HEIGHT / 3) -- reset drawing color to full white for proper rendering - love.graphics.setColor(255, 255, 255, 255) + love.graphics.setColor(1, 1, 1, 1) -- draw the paddle itself, based on which we have selected love.graphics.draw(gTextures['main'], gFrames['paddles'][2 + 4 * (self.currentPaddle - 1)], diff --git a/breakout13/src/states/StartState.lua b/breakout13/src/states/StartState.lua index 00d34a9..7fadff2 100644 --- a/breakout13/src/states/StartState.lua +++ b/breakout13/src/states/StartState.lua @@ -10,6 +10,11 @@ Represents the state the game is in when we've just started; should simply display "Breakout" in large text, as well as a message to press Enter to begin. + + Update to LÖVE v11 and few bugs fixation by: Jauhari Alafi + CS50 student 2020 (online) Netherlands + jaujau088@gmail.com + - Changed setColor values from base 255 to base 1 ]] -- the "__includes" bit here means we're going to inherit all of the methods @@ -63,21 +68,21 @@ function StartState:render() -- if we're highlighting 1, render that option blue if highlighted == 1 then - love.graphics.setColor(103, 255, 255, 255) + love.graphics.setColor(103/255, 1, 1, 1) end love.graphics.printf("START", 0, VIRTUAL_HEIGHT / 2 + 70, VIRTUAL_WIDTH, 'center') -- reset the color - love.graphics.setColor(255, 255, 255, 255) + love.graphics.setColor(1, 1, 1, 1) -- render option 2 blue if we're highlighting that one if highlighted == 2 then - love.graphics.setColor(103, 255, 255, 255) + love.graphics.setColor(103/255, 1, 1, 1) end love.graphics.printf("HIGH SCORES", 0, VIRTUAL_HEIGHT / 2 + 90, VIRTUAL_WIDTH, 'center') -- reset the color - love.graphics.setColor(255, 255, 255, 255) + love.graphics.setColor(1, 1, 1, 1) end \ No newline at end of file From 5cdec86c271db8115cdd584d0dbc37c17d14d2ec Mon Sep 17 00:00:00 2001 From: jaujau088 Date: Wed, 26 Aug 2020 13:27:36 +0200 Subject: [PATCH 2/2] changed initial difficulty to 1 --- breakout13/src/states/PaddleSelectState.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/breakout13/src/states/PaddleSelectState.lua b/breakout13/src/states/PaddleSelectState.lua index 23de65a..9b50ef0 100644 --- a/breakout13/src/states/PaddleSelectState.lua +++ b/breakout13/src/states/PaddleSelectState.lua @@ -15,8 +15,8 @@ CS50 student 2020 (online) Netherlands jaujau088@gmail.com - Changed setColor values from base 255 to base 1 - - Changed "level" value that is passed on to serve state from 32 to 1 - so that level now starts from 1 instead of 32 + - Changed "level" and "bricks" values that are passed to serve state from 32 to 1 + so that level and difficulty now starts from 1 instead of 32 ]] PaddleSelectState = Class{__includes = BaseState} @@ -54,7 +54,7 @@ function PaddleSelectState:update(dt) gStateMachine:change('serve', { paddle = Paddle(self.currentPaddle), - bricks = LevelMaker.createMap(32), + bricks = LevelMaker.createMap(1), health = 3, score = 0, highScores = self.highScores,