summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--camera.lua25
-rw-r--r--ground.lua6
-rw-r--r--maps/default.lua2
-rw-r--r--player.lua2
-rw-r--r--world.lua18
5 files changed, 48 insertions, 5 deletions
diff --git a/camera.lua b/camera.lua
index cb367a3..04590d1 100644
--- a/camera.lua
+++ b/camera.lua
@@ -43,6 +43,10 @@ function Camera:getPosition ()
return self.x, self.y
end
+function Camera:getPositionScaled ()
+ return self.x*self.scale, self.y*self.scale
+end
+
-- Destination
function Camera:setDestination (x, y)
local x = x or 0
@@ -53,6 +57,27 @@ end
function Camera:getDestination ()
return self.dest_x, self.dest_y
end
+
+-- Translate points
+function Camera:translatePosition(x, y)
+ local x = x or 0
+ local y = y or 0
+ return x-self.x*self.scale, y-self.y*self.scale
+end
+
+function Camera:translatePoints(...)
+ local a = {...}
+ local r = {}
+ local x,y = self:getOffsets()
+ for k,v in pairs(a) do
+ if k%2 == 1 then
+ table.insert(r, (v + x) * self.scale)
+ else
+ table.insert(r, (v + y) * self.scale)
+ end
+ end
+ return r
+end
-- Shake it
-- Really bad script, but for now it works
diff --git a/ground.lua b/ground.lua
index db3d090..d9d6bde 100644
--- a/ground.lua
+++ b/ground.lua
@@ -10,10 +10,11 @@ Ground = {
body = nil,
shape = nil,
fixture = nil,
+ world = nil,
sprite = nil
}
-- Constructor of `Ground`
-function Ground:new (world, x, y, shape, sprite)
+function Ground:new (game, world, x, y, shape, sprite)
local o = {}
setmetatable(o, self)
self.__index = self
@@ -23,6 +24,7 @@ function Ground:new (world, x, y, shape, sprite)
o.sprite = love.graphics.newImage(sprite)
o.fixture:setCategory(1)
o.fixture:setFriction(0.2)
+ o.world = game
return o
end
@@ -39,6 +41,6 @@ function Ground:draw (offset_x, offset_y, scale, debug)
-- debug draw
if debug then
love.graphics.setColor(220, 220, 220, 100)
- love.graphics.polygon("fill", self.body:getWorldPoints(self.shape:getPoints()))
+ love.graphics.polygon("fill", self.world.camera:translatePoints(self.body:getWorldPoints(self.shape:getPoints())))
end
end \ No newline at end of file
diff --git a/maps/default.lua b/maps/default.lua
index 09cd48f..6c33955 100644
--- a/maps/default.lua
+++ b/maps/default.lua
@@ -1,7 +1,7 @@
-- Default map from original roflnauts
return {
center_x = 0,
- center_y = 0,
+ center_y = 30,
width = 320,
height = 240,
color_top = {193, 100, 99, 255},
diff --git a/player.lua b/player.lua
index e00fbce..76d694f 100644
--- a/player.lua
+++ b/player.lua
@@ -266,7 +266,7 @@ function Player:draw (offset_x, offset_y, scale, debug)
-- debug draw
if debug then
love.graphics.setColor(50, 255, 50, 100)
- love.graphics.polygon("fill", self.body:getWorldPoints(self.shape:getPoints()))
+ love.graphics.polygon("fill", self.world.camera:translatePoints(self.body:getWorldPoints(self.shape:getPoints())))
love.graphics.setColor(255,255,255,255)
end
end
diff --git a/world.lua b/world.lua
index 2580e0e..cb54b42 100644
--- a/world.lua
+++ b/world.lua
@@ -85,7 +85,7 @@ end
-- Add new platform to the world
function World:createPlatform(x, y, polygon, sprite)
- table.insert(self.Platforms, Ground:new(self.world, x, y, polygon, sprite))
+ table.insert(self.Platforms, Ground:new(self, self.world, x, y, polygon, sprite))
end
-- Add new naut to the world
@@ -205,6 +205,22 @@ function World:draw()
platform:draw(offset_x, offset_y, scale, debug)
end
+ -- draw center
+ if debug then
+ local c = self.camera
+ local w, h = love.graphics.getWidth(), love.graphics.getHeight()
+ love.graphics.setColor(130,130,130)
+ love.graphics.setLineWidth(1)
+ love.graphics.setLineStyle("rough")
+ local cx, cy = c:getPositionScaled()
+ local x1, y1 = c:translatePosition(self.map.center_x, cy)
+ local x2, y2 = c:translatePosition(self.map.center_x, cy+h)
+ love.graphics.line(x1,y1,x2,y2)
+ local x1, y1 = c:translatePosition(cx, self.map.center_y)
+ local x2, y2 = c:translatePosition(cx+w, self.map.center_y)
+ love.graphics.line(x1,y1,x2,y2)
+ end
+
-- Draw HUDs
for _,naut in pairs(self.Nauts) do
-- I have no idea where to place them T_T