diff options
Diffstat (limited to 'utils/map.lua')
-rw-r--r-- | utils/map.lua | 71 |
1 files changed, 58 insertions, 13 deletions
diff --git a/utils/map.lua b/utils/map.lua index f8f4043..a26168f 100644 --- a/utils/map.lua +++ b/utils/map.lua @@ -4,24 +4,37 @@ STI = require("libs.sti") Moonshine = require("libs.moonshine") Camera = require("libs.hump.camera") + +zoomFactor = 3 +player = { + x=0, + y=0, + sprite=love.graphics.newImage("assets/images/player_demo.png"), + speed=5 +} +windowWidth, windowHeight = love.graphics.getDimensions() + +w = windowWidth/zoomFactor +h = windowHeight/zoomFactor + + Map = Class { init = function(self, mapName) -- TODO pass map instance parameter - width, height = love.graphics.getDimensions( ) - effect = Moonshine(width, height, Moonshine.effects.crt) + effect = Moonshine(windowWidth, windowHeight, Moonshine.effects.crt) .chain(Moonshine.effects.vignette) .chain(Moonshine.effects.scanlines) .chain(Moonshine.effects.chromasep) effect.scanlines.thickness = .2 effect.scanlines.opacity = .5 effect.chromasep.angle = 1 - effect.chromasep.radius = 5 + effect.chromasep.radius = 2 camera = Camera() - camera:zoom(1) - print("Map Manager") + camera:zoom(zoomFactor) currentMap = STI("assets/maps/"..mapName..".lua") if currentMap.layers["entities"] then for i,obj in pairs(currentMap.layers["entities"].objects) do - print(obj.name) + player.x = obj.x + player.y = obj.y end end end, @@ -29,23 +42,55 @@ Map = Class { } function Map:update(dt) - print("Map Update") + if love.keyboard.isDown("up") then + player.y = player.y - player.speed + end + + if love.keyboard.isDown("down") then + player.y = player.y + player.speed + end + + if love.keyboard.isDown("left") then + player.x = player.x - player.speed + end + + if love.keyboard.isDown("right") then + player.x = player.x + player.speed + end + + camera:lookAt(player.x, player.y) currentMap:update(dt) + + if camera.x < w/2 then + camera.x = w/2 + end + + if camera.y < h/2 then + camera.y = h/2 + end + + local mapWidth = currentMap.width * currentMap.tilewidth + local mapHeight = currentMap.height * currentMap.tileheight + + if camera.x > (mapWidth - w/2) then + camera.x = (mapWidth - w/2) + end + + if camera.y > (mapHeight - h/2) then + camera.y = (mapHeight - h/2) + end end function Map:draw() - print("Map Draw") - camera:attach() effect(function() - + camera:attach() currentMap:drawLayer(currentMap.layers["ground"]) - + love.graphics.draw(player.sprite, player.x, player.y) + camera:detach() end) - camera:detach() end function Map:keypressed(key, scancode) - end return Map
\ No newline at end of file |