Advertisement
Guest User

Untitled

a guest
Mar 18th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.97 KB | None | 0 0
  1. local w, h
  2. local tx, ty = 0, 0
  3. local circles = {}
  4.  
  5. Camera = {} -- We define our camera as a table
  6.  
  7. function Camera.load() -- Camera.load is now a function we can call
  8.    w, h = love.graphics.getDimensions()
  9.    tx, ty = -w/2, -h/2
  10.  
  11.    for i=1, 100 do
  12.       table.insert(circles, {
  13.          x = love.math.random(0, w * 2),
  14.          y = love.math.random(0, h * 2),
  15.          r = love.math.random(0, 100)
  16.       })
  17.    end
  18. end
  19.  
  20. function Camera.mousemoved(x, y, dx, dy) -- As well as Camera.mousemoved
  21.    if love.mouse.isDown(1) then
  22.       tx = math.min(0, math.max(tx + dx, -w))
  23.       ty = math.min(0, math.max(ty + dy, -h))
  24.    end
  25. end
  26.  
  27. function Camera.draw() -- And now this function will work as well
  28.    love.graphics.translate(tx, ty)
  29.    
  30.    love.graphics.setColor(0, 255, 0, 100)
  31.    for _, circle in ipairs(circles) do
  32.       love.graphics.circle("fill", circle.x, circle.y, circle.r)
  33.       love.graphics.circle("line", circle.x, circle.y, circle.r)
  34.    end
  35. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement