Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local image, x, y, fx, fy, offsetX, offsetY, width, height
- --[[
- calculates the four edges of the image, and returns them as a table:
- {
- x1,
- y1,
- x2,
- y2
- }
- ]]
- local function calculateEdges(image, x, y)
- local edges = {}
- local closeInOffset = 30
- edges[1] = x - offsetX + closeInOffset
- edges[2] = y - offsetY + closeInOffset
- edges[3] = x + offsetX - closeInOffset
- edges[4] = y + offsetY - closeInOffset
- return edges
- end
- --[[
- The default load function
- ]]
- function love.load()
- image = love.graphics.newImage("images/DVD_LOGO.PNG")
- offsetX = image:getWidth() / 2
- offsetY = image:getHeight() / 2
- fx = true
- fy = true
- love.window.setMode(1091, 699)
- width, height = love.graphics.getDimensions()
- x = math.random(50, width - 49)
- y = math.random(50, height - 49)
- end
- function love.update(dt)
- local function inc(t, n)
- if t then
- return n + 1
- else
- return n - 1
- end
- end
- x = inc(fx, x)
- y = inc(fy, y)
- local edges = calculateEdges(image, x, y)
- if edges[1] < 1 then
- fx = true
- elseif edges[3] > width - 1 then
- fx = false
- end
- if edges[2] < 1 then
- fy = true
- elseif edges[4] > height - 1 then
- fy = false
- end
- end
- function love.draw()
- love.graphics.draw(image, x, y, 0, 1, 1, offsetX, offsetY)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement