Selaa lähdekoodia

Zones; Change sizes;

bjorn 10 vuotta sitten
vanhempi
commit
db6032bee5
8 muutettua tiedostoa jossa 44 lisäystä ja 7 poistoa
  1. 1 1
      data/animation/pigeon.lua
  2. 1 1
      deps/manager.lua
  3. 9 0
      dinoland.lua
  4. 2 1
      game.lua
  5. 14 2
      map.lua
  6. 2 2
      person.lua
  7. 2 0
      require.lua
  8. 13 0
      zone.lua

+ 1 - 1
data/animation/pigeon.lua

@@ -1,6 +1,6 @@
 local Pigeon = extend(Animation)
 
-Pigeon.scale = .5
+Pigeon.scale = .6
 Pigeon.default = 'idle'
 Pigeon.states = {}
 

+ 1 - 1
deps/manager.lua

@@ -1,7 +1,7 @@
 Manager = class()
 
 function Manager:init()
-  self.objects = {}
+  self.objects = setmetatable({}, {__mode = 'kv'})
 end
 
 function Manager:update()

+ 9 - 0
dinoland.lua

@@ -0,0 +1,9 @@
+Dinoland = extend(Map)
+Dinoland.width = 2400
+Dinoland.height = 600
+
+function Dinoland:init()
+  self.zones = {}
+
+  return Map.init(self)
+end

+ 2 - 1
game.lua

@@ -13,7 +13,7 @@ function Game:load()
   self.event = Event()
   self.world = love.physics.newWorld(0, 1000)
   self.view = View()
-  self.map = Map(ctx)
+  self.map = Dinoland()
   self.pigeon = Pigeon()
   self.enemies = Manager()
   self.buildings = Manager()
@@ -30,6 +30,7 @@ function Game:update()
   self.enemies:update()
   self.buildings:update()
   self.projectiles:update()
+  self.map:update()
   self.world:update(ls.tickrate)
   self.view:update()
 

+ 14 - 2
map.lua

@@ -1,6 +1,4 @@
 Map = class()
-Map.width = 2400
-Map.height = 600
 
 function Map:init()
   self.ground = {}
@@ -16,6 +14,10 @@ function Map:init()
   ctx.event:emit('view.register', {object = self})
 end
 
+function Map:update()
+  ctx.view.xmax = self:getMaxX()
+end
+
 function Map:draw()
   local g = love.graphics
   g.setColor(0, 50, 0)
@@ -24,3 +26,13 @@ function Map:draw()
   g.setColor(100, 80, 0)
   physics.draw('fill', self.ground)
 end
+
+function Map:getMaxX()
+  for i = 1, #self.zones do
+    if self.zones[i].active then
+      return self.zones[i].x
+    end
+  end
+
+  return self.width
+end

+ 2 - 2
person.lua

@@ -5,7 +5,7 @@ Person = extend(Enemy)
 ----------------
 function Person:activate()
   local widthRatio = self.image:getWidth() / self.image:getHeight()
-  self.h = 60
+  self.h = 45
   self.w = self.h * widthRatio
   self.scale = self.h / self.image:getHeight()
 
@@ -51,7 +51,7 @@ end
 -- Helpers
 ----------------
 function Person:hop(direction)
-  self.body:applyLinearImpulse(120 * direction, -180)
+  self.body:applyLinearImpulse(60 * direction, -90)
 end
 
 function Person:directionTo(object)

+ 2 - 0
require.lua

@@ -19,7 +19,9 @@ require 'person'
 require 'caveman'
 require 'building'
 require 'pigeon'
+require 'zone'
 require 'map'
+require 'dinoland'
 require 'goal'
 require 'projectile'
 

+ 13 - 0
zone.lua

@@ -0,0 +1,13 @@
+Zone = class()
+
+function Zone:init(x)
+  self.x = x
+  self.enemies = {}
+  self.active = true
+end
+
+function Zone:update()
+  if table.count(self.enemies) == 0 then
+    self.active = false
+  end
+end