aboutsummaryrefslogtreecommitdiff
path: root/utils/map.lua
diff options
context:
space:
mode:
authorIndrajith K L2022-02-27 19:36:21 +0530
committerIndrajith K L2022-02-27 19:36:21 +0530
commit16db60e07d19f8c7c2138839a004b73242e80b19 (patch)
tree8e9bc6a9be1e3f671d8de0ef91a62a631ea3ce42 /utils/map.lua
parent62ff5245c26c305e35a2903cc64a60cb20718e96 (diff)
downloadYEAD-16db60e07d19f8c7c2138839a004b73242e80b19.tar.gz
YEAD-16db60e07d19f8c7c2138839a004b73242e80b19.tar.bz2
YEAD-16db60e07d19f8c7c2138839a004b73242e80b19.zip
Player Follow Camera - Done
Camera Zoom and Camera Map boundary bound - Done
Diffstat (limited to 'utils/map.lua')
-rw-r--r--utils/map.lua71
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