Browse Source

View scrolling; Bigger map;

bjorn 10 years ago
parent
commit
31afeed673
3 changed files with 17 additions and 2 deletions
  1. 10 0
      deps/view.lua
  2. 4 1
      map.lua
  3. 3 1
      pigeon.lua

+ 10 - 0
deps/view.lua

@@ -53,6 +53,7 @@ function View:update()
   self.x = self.x + self.vx * ls.tickrate
   self.y = self.y + self.vy * ls.tickrate
 
+  self:follow()
   self:contain()
 
   self.shake = lume.lerp(self.shake, 0, 8 * ls.tickrate)
@@ -188,6 +189,15 @@ function View:threeDepth(x, y, z)
   return math.clamp(lume.distance(x, y, self.x + self.width / 2, self.y + self.height / 2) * self.scale - 1000 - z, -4096, -16)
 end
 
+function View:follow()
+  if not self.target then return end
+
+  local margin = 0.5
+
+  self.x = self.target.x - self.width * margin
+  self.y = self.target.y - self.height * margin
+end
+
 function View:contain()
   self.x = math.clamp(self.x, 0, self.xmax - self.width)
   self.y = math.clamp(self.y, 0, self.ymax - self.height)

+ 4 - 1
map.lua

@@ -1,5 +1,5 @@
 Map = class()
-Map.width = 800
+Map.width = 1600
 Map.height = 600
 
 function Map:init()
@@ -9,6 +9,9 @@ function Map:init()
   self.ground.shape = love.physics.newRectangleShape(self.width, self.ground.height)
 
   self.ground.fixture = love.physics.newFixture(self.ground.body, self.ground.shape)
+
+  ctx.view.xmax = self.width
+  ctx.view.ymax = self.height
   ctx.event:emit('view.register', {object = self})
 end
 

+ 3 - 1
pigeon.lua

@@ -19,6 +19,8 @@ function Pigeon:init()
 
   self.animation = data.animation.pigeon()
 
+  ctx.view.target = self
+
   ctx.event:emit('view.register', {object = self})
 end
 
@@ -119,5 +121,5 @@ function Pigeon:draw()
     g.setLineWidth(1)
   end
 
-  self.animation:draw(self.x, self.y)
+  self.animation:draw(x, y)
 end