love.graphics.newImage("images/Blue.png") faceType = 0 Draw: if(smiley.getFaceType() == 1) then love.graphics.draw(smileyImage,smiley.getX(),smiley.getY()) else love.graphics.draw(blueImage,smiley.getX(),smiley.getY()) end Mouse Release: function love.mousereleased(x, y, button) if button == "l" then if(faceType == 0) then hitFace = inRect(x,y,smileyX,smileyY,smileyWidth,smileyHeight) love.audio.play(squishSfx) score = score + 10 faceType = 1 end end end 17 Saturday, May 25, 13
then isInRect = false end if x > (smileyX + smileyWidth) then isInRect = false end if y < smileyY then isInRect = false end if y > (smileyY + smileyHeight) then isInRect = false end return isInRect end 18 Saturday, May 25, 13
1 smileyYVelocity = 1 New Function: function love.update(dt) smileyX = smileyX + smileyXVelocity smileyY = smileyY + smileyYVelocity if smileyX < 0 or smileyX + smileyWidth > gameWidth then smileyXVelocity = -smileyXVelocity end if smileyY < 0 or smileyY + smileyHeight > gameHeight then smileyYVelocity = - smileyYVelocity end end 20 Saturday, May 25, 13
VARIABLES local self = {} local width = imageWidth or 64 local height = imageHeight or 64 local faceType = 0 local x = math.random(love.graphics.getWidth() - width) local y = math.random(love.graphics.getHeight() - height) local maxVelocity = 50 local xVelocity = (math.random(maxVelocity)-(maxVelocity/2))/100 local yVelocity = (math.random(maxVelocity)-(maxVelocity/2))/100 21 Saturday, May 25, 13
end self.getHeight = function() return height end self.getFaceType = function() return faceType end self.getX = function() return x end self.getY = function() return y end self.getXVelocity = function() return xVelocity end self.getYVelocity = function() return yVelocity end -- #SETTERS self.setFaceType = function(newFaceType) faceType = newFaceType end 22 Saturday, May 25, 13
(dt) x = x + xVelocity y = y + yVelocity if ((x < 0) or ((x + width) > love.graphics.getWidth())) then xVelocity = -xVelocity end if ((y < 0) or ((y + height) > love.graphics.getHeight())) then yVelocity = -yVelocity end end self.inSmiley = function(xLoc,yLoc) local isInRect = true if xLoc < x then isInRect = false end if xLoc > (x + width) then isInRect = false end if yLoc < y then isInRect = false end if yLoc > (y + height) then isInRect = false end return isInRect end return self end 23 Saturday, May 25, 13
if(smiley.getFaceType() == 1) then love.graphics.draw(smileyImage,smiley.getX(),smiley.getY()) else love.graphics.draw(blueImage,smiley.getX(),smiley.getY()) end end love.graphics.print('Score: ' .. score, 700, 10) end 26 Saturday, May 25, 13
"l" then hitOne = false for i,smiley in ipairs(smileys) do hit = checkSmiley(x,y,smiley) if hit == true then hitOne = true end end if hitOne == true then score = score + 10 else score = score - 1 end if #newSmileys > 0 then for i,smiley in ipairs(newSmileys) do table.insert(smileys,smiley) end newSmileys = {} end end end 27 Saturday, May 25, 13
0) then hitFace = smiley.inSmiley(x,y) if(hitFace) then love.audio.play(squishSfx) smiley.setFaceType(1) hit = true table.insert(newSmileys,Smiley.new(blueImage:getWidth(), blueImage:getHeight())) end end return hit end function love.update(dt) for i,smiley in ipairs(smileys) do smiley.moveSmiley(dt) end end 28 Saturday, May 25, 13