Allow player to move around camera using arrow keys

This commit is contained in:
jordan4ibanez 2017-07-07 01:13:55 -04:00
parent 1ecb5577ba
commit 9704bf2eb7
3 changed files with 25 additions and 2 deletions

View File

@ -44,4 +44,5 @@ function love.update(dt)
menu.animate()
mine(key)
gravity(dt)
player.move_camera(dt)
end

View File

@ -245,7 +245,7 @@ function maplib.draw()
love.graphics.setColor(ore[loaded_chunks[xx][-yy][x][y]["block"]]["rgb"][1],ore[loaded_chunks[xx][-yy][x][y]["block"]]["rgb"][2],ore[loaded_chunks[xx][-yy][x][y]["block"]]["rgb"][3],255)
love.graphics.print(ore[loaded_chunks[xx][-yy][x][y]["block"]]["image"], (((x*scale)-(player.playerx*scale))+((scale*map_max)/2))+(map_max*scale*xx), (((y*scale)-(player.playery*scale))+((scale*map_max)/2))+(map_max*scale*yy))
love.graphics.print(ore[loaded_chunks[xx][-yy][x][y]["block"]]["image"], (((x*scale)-(player.playerx*scale))+((scale*map_max)/2))+(map_max*scale*xx)+offsetx, (((y*scale)-(player.playery*scale))+((scale*map_max)/2))+(map_max*scale*yy)+offsety)
--if x == math.floor(map_max / 2) and y == math.floor(map_max / 2) then
-- love.graphics.print("X", x*scale, y*scale)
--end

View File

@ -2,6 +2,8 @@
player = {}
player.playerx,player.playery = math.random(1,map_max),math.random(1,map_max)
offsetx,offsety = 0,0
player.mining = true
player.selected = 2
@ -117,11 +119,31 @@ function mine(key)
end
end
function player.move_camera(dt)
--x axis
if love.keyboard.isDown("left") then
offsetx = offsetx + 3
elseif love.keyboard.isDown("right") then
offsetx = offsetx - 3
end
--y axis
if love.keyboard.isDown("up") then
offsety = offsety + 3
elseif love.keyboard.isDown("down") then
offsety = offsety - 3
end
end
player_drawnx,player_drawny = 0,0
function player.draw()
love.graphics.setFont(font)
love.graphics.setColor(255,0,0,255)
player_drawnx,player_drawny = ((scale*map_max)/2),((scale*map_max)/2)
player_drawnx,player_drawny = ((scale*map_max)/2)+offsetx,((scale*map_max)/2)+offsety
love.graphics.print("8", player_drawnx,player_drawny )
end