summaryrefslogtreecommitdiffhomepage
path: root/main.lua
diff options
context:
space:
mode:
authorAki <nthirtyone@gmail.com>2016-05-13 15:00:13 +0200
committerAki <nthirtyone@gmail.com>2016-05-13 15:00:13 +0200
commit0506e2dd9cb9641486bbfc7908c0399b26e1ce3c (patch)
tree1d673944ed31946959f4b08c9c412cc8f2df12d5 /main.lua
parent7d4251e3a9c08b89d25ef724270752f36649f765 (diff)
downloadroflnauts-0506e2dd9cb9641486bbfc7908c0399b26e1ce3c.zip
roflnauts-0506e2dd9cb9641486bbfc7908c0399b26e1ce3c.tar.gz
roflnauts-0506e2dd9cb9641486bbfc7908c0399b26e1ce3c.tar.bz2
Basic camera added
Diffstat (limited to 'main.lua')
-rw-r--r--main.lua12
1 files changed, 9 insertions, 3 deletions
diff --git a/main.lua b/main.lua
index d5b4d1a..3a895bf 100644
--- a/main.lua
+++ b/main.lua
@@ -3,6 +3,7 @@
require "ground"
require "player"
+require "camera"
debug = false
@@ -15,7 +16,7 @@ function love.load ()
love.physics.setMeter(64)
world = love.physics.newWorld(0, 9.81*64, true)
world:setCallbacks(beginContact, endContact, preSolve, postSolve)
-
+
-- Platforms (`Ground`)
Platforms = {}
table.insert(Platforms, Ground:new(world, 290/2, 180/2, {-91,0, 90,0, 90,10, 5,76, -5,76, -91,10}, "assets/platform_big.png"))
@@ -36,11 +37,15 @@ function love.load ()
Nauts[2].key_down = "s"
Nauts[2].key_jump = "h"
Nauts[2].key_hit = "g"
+
+ -- Camera
+ camera = Camera:new()
end
function love.update (dt)
-- Put world in motion!
world:update(dt)
+ camera:moveFollow()
-- Players
for k,naut in pairs(Nauts) do
naut:update(dt)
@@ -73,14 +78,15 @@ function love.draw ()
love.graphics.setColor(179, 82, 80, 255)
love.graphics.rectangle("fill", 0, 160, love.graphics.getWidth(), 40)
+ local offset_x, offset_y = camera:getOffsets()
-- Draw ground
for k,platform in pairs(Platforms) do
- platform:draw(0, 0, debug)
+ platform:draw(offset_x, offset_y, debug)
end
-- Draw player
for k,naut in pairs(Nauts) do
- naut:draw(0, 0, debug)
+ naut:draw(offset_x, offset_y, debug)
end
end