Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local w, h
- local tx, ty = 0, 0
- local circles = {}
- Camera = {} -- We define our camera as a table
- function Camera.load() -- Camera.load is now a function we can call
- w, h = love.graphics.getDimensions()
- tx, ty = -w/2, -h/2
- for i=1, 100 do
- table.insert(circles, {
- x = love.math.random(0, w * 2),
- y = love.math.random(0, h * 2),
- r = love.math.random(0, 100)
- })
- end
- end
- function Camera.mousemoved(x, y, dx, dy) -- As well as Camera.mousemoved
- if love.mouse.isDown(1) then
- tx = math.min(0, math.max(tx + dx, -w))
- ty = math.min(0, math.max(ty + dy, -h))
- end
- end
- function Camera.draw() -- And now this function will work as well
- love.graphics.translate(tx, ty)
- love.graphics.setColor(0, 255, 0, 100)
- for _, circle in ipairs(circles) do
- love.graphics.circle("fill", circle.x, circle.y, circle.r)
- love.graphics.circle("line", circle.x, circle.y, circle.r)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement