Compare commits
3 Commits
e82d3417da
...
0c7c1705ad
Author | SHA1 | Date |
---|---|---|
Pascal Abresch | 0c7c1705ad | |
Pascal Abresch | dd180d0a4e | |
Pascal Abresch | da55cacd04 |
|
@ -2,6 +2,7 @@ local CAM_SPEED = 10
|
|||
|
||||
camera = {}
|
||||
camera.target = 0
|
||||
camera.offset = { x = 0, y = 300 }
|
||||
local fullscreen = false
|
||||
|
||||
local altPressed, enterPressed = false
|
||||
|
@ -45,17 +46,18 @@ function camera.input(dt)
|
|||
-- TODO: rewrite for scale, so player always remains in view at max distance
|
||||
-- direct view control
|
||||
if love.keyboard.isDown("left") then
|
||||
view.x = view.x + dt * 300
|
||||
camera.offset.x = camera.offset.x + dt * 300
|
||||
end
|
||||
if love.keyboard.isDown("right") then
|
||||
view.x = view.x - dt * 300
|
||||
camera.offset.x = camera.offset.x - dt * 300
|
||||
end
|
||||
if love.keyboard.isDown("up") then
|
||||
view.y = view.y + dt * 300
|
||||
camera.offset.y = camera.offset.y + dt * 300
|
||||
end
|
||||
if love.keyboard.isDown("down") then
|
||||
view.y = view.y - dt * 300
|
||||
camera.offset.y = camera.offset.y - dt * 300
|
||||
end
|
||||
camera.offsetclamp()
|
||||
end
|
||||
|
||||
|
||||
|
@ -64,11 +66,28 @@ function camera.resize()
|
|||
end
|
||||
|
||||
|
||||
function camera.offsetclamp()
|
||||
if camera.offset.x > (window.x/2) / scale then
|
||||
camera.offset.x = (window.x/2) / scale
|
||||
end
|
||||
if camera.offset.x < -(window.x/2) / scale then
|
||||
camera.offset.x = -(window.x/2) / scale
|
||||
end
|
||||
if camera.offset.y > (window.y/2) / scale then
|
||||
camera.offset.y = (window.y/2) / scale
|
||||
end
|
||||
if camera.offset.y < -(window.y/2) / scale then
|
||||
camera.offset.y = -(window.y/2) / scale
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
function camera.setplayer()
|
||||
if camera.target == 0 then return end
|
||||
player = players[camera.target]
|
||||
local perfectx = math.floor(player.x * -1) + ((window.x -300)/2 -((player.avatar:getWidth() /2) / scale)) / scale
|
||||
local perfecty = math.floor(player.y * -1) + (window.y/2 -((player.avatar:getHeight() /2) / scale)) / scale
|
||||
camera.offsetclamp()
|
||||
local perfectx = math.floor(player.x * -1) + ((window.x -300)/2 -((player.avatar:getWidth() /2) / scale)) / scale + camera.offset.x
|
||||
local perfecty = math.floor(player.y * -1) + (window.y/2 -((player.avatar:getHeight() /2) / scale)) / scale + camera.offset.y
|
||||
|
||||
view.x = perfectx
|
||||
view.y = perfecty
|
||||
|
@ -79,8 +98,8 @@ function camera.update()
|
|||
if camera.target == 0 then return end
|
||||
player = players[camera.target]
|
||||
--[[ Update camera to track player ]]--
|
||||
local perfectx = math.floor(player.x * -1) + ((window.x -300)/2 -(player.avatar:getWidth() /2)) / scale
|
||||
local perfecty = math.floor(player.y * -1) + (window.y/2 -(player.avatar:getHeight() /2)) / scale
|
||||
local perfectx = math.floor(player.x * -1) + ((window.x -300)/2 -(player.avatar:getWidth() /2)) / scale + camera.offset.x
|
||||
local perfecty = math.floor(player.y * -1) + (window.y/2 -(player.avatar:getHeight() /2)) / scale + camera.offset.y
|
||||
|
||||
local deltax = (perfectx - view.x) / scale
|
||||
local deltay = (perfecty - view.y) / scale
|
||||
|
|
|
@ -89,7 +89,7 @@ function drawing.input(dt)
|
|||
if mouse.lastpos.x and mouse.lastpos.y then
|
||||
local x = math.abs(mouse.lastpos.x - mousex)
|
||||
local y = math.abs(mouse.lastpos.y - mousey)
|
||||
granularity = math.sqrt(x * x + y * y) / 16
|
||||
granularity = math.sqrt(x * x + y * y) / ((textures[drawing.cursor].image:getPixelWidth() + textures[drawing.cursor].image:getPixelWidth()) / 2)
|
||||
else
|
||||
mouse.lastpos.x = mousex
|
||||
mouse.lastpos.y = mousey
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 722 B |
Binary file not shown.
After Width: | Height: | Size: 731 B |
Binary file not shown.
After Width: | Height: | Size: 714 B |
Loading…
Reference in New Issue