Browse Source

Buildings can kill people;

bjorn 10 years ago
parent
commit
0ca1e4bf94
4 changed files with 10 additions and 5 deletions
  1. 7 3
      building.lua
  2. 1 1
      caveman.lua
  3. 1 0
      dinoland.lua
  4. 1 1
      person.lua

+ 7 - 3
building.lua

@@ -40,7 +40,7 @@ function Building:update()
 
   if self.justDestroyed then
     for i = 1, 6 do
-      ctx.enemies:add(Caveman, {x = self.x - self.size / 2 + self.size * love.math.random(), y = self.y, invincible = 1})
+      ctx.enemies:add(Caveman, {x = self.x - self.size / 2 + self.size * love.math.random(), y = self.y, invincible = 1, state = Caveman.panic})
     end
 
     self.justDestroyed = false
@@ -72,7 +72,11 @@ end
 
 function Building:collideWith(other)
   if other.tag == 'platform' and self.body:getY() > other.body:getY() then
-    return true
+    return false
+  end
+
+  if isa(other, Person) and other.state ~= other.dead and self.destroyed and select(2, self.body:getLinearVelocity()) > 30 then
+    other:changeState('dead')
   end
 
   return true
@@ -85,6 +89,6 @@ function Building:destroy()
   self.body:setFixedRotation(false)
   self.fixture:setCategory(ctx.categories.debris)
   self.fixture:setFriction(0.25)
-  self.body:applyLinearImpulse(-400 + love.math.random() * 800, -800 + love.math.random() * -500)
+  self.body:applyLinearImpulse(-400 + love.math.random() * 600, -2000 + love.math.random() * -2000)
   self.body:setAngularVelocity(-20 + love.math.random() * 40)
 end

+ 1 - 1
caveman.lua

@@ -12,7 +12,7 @@ function Caveman:activate()
   self.direction = 1
 
   self.hasSpear = love.math.random() > .5
-  self.state = self.idle
+  self.state = self.state or self.idle
   self.walkTimer = 1
   self.reloadTimer = 0
 

+ 1 - 0
dinoland.lua

@@ -38,6 +38,7 @@ function Dinoland:spawnHuts()
   ctx.buildings:add(Building, {x = 950, y = self.height - self.ground.height})
   ctx.buildings:add(Building, {x = 2000, y = self.height - self.ground.height - 200})
   ctx.buildings:add(Building, {x = 2200, y = self.height - self.ground.height - 200})
+  ctx.buildings:add(Building, {x = 2100, y = self.height - self.ground.height})
 
   for i = 1, 20 do
     ctx.enemies:add(Caveman, {x = 1600 - 150 + love.math.random() * 300, y = self.height - 200})

+ 1 - 1
person.lua

@@ -19,7 +19,7 @@ function Person:activate()
 
   self.fixture:setFriction(.75)
   self.fixture:setCategory(ctx.categories.person)
-  self.fixture:setMask(ctx.categories.person, ctx.categories.building, ctx.categories.debris)
+  self.fixture:setMask(ctx.categories.person)
 
   self.phlerp = PhysicsInterpolator(self, 'alpha')