aboutsummaryrefslogtreecommitdiff
path: root/utils
diff options
context:
space:
mode:
Diffstat (limited to 'utils')
-rw-r--r--utils/constants.lua2
-rw-r--r--utils/map.lua71
2 files changed, 59 insertions, 14 deletions
diff --git a/utils/constants.lua b/utils/constants.lua
index 2210d65..5284e6d 100644
--- a/utils/constants.lua
+++ b/utils/constants.lua
@@ -1,6 +1,6 @@
constants = {}
-constants.resetBgColor = {0, 0, 0}
+constants.resetBgColor = {0.15, 0.15, 0.15}
constants.resetFgColor = {1, 1, 1}
function constants:resetColors()
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