Browse Source

Enemy base class;

bjorn 10 years ago
parent
commit
ee8a4f7358
6 changed files with 18 additions and 7 deletions
  1. 2 1
      data/animation/pigeon.lua
  2. 1 1
      deps/animation.lua
  3. 7 0
      enemy.lua
  4. 3 3
      game.lua
  5. 4 2
      person.lua
  6. 1 0
      require.lua

+ 2 - 1
data/animation/pigeon.lua

@@ -9,7 +9,8 @@ Pigeon.states.idle = {
 }
 
 Pigeon.states.walk = {
-  loop = true
+  loop = true,
+  speed = .75
 }
 
 Pigeon.states.peck = {

+ 1 - 1
deps/animation.lua

@@ -51,7 +51,7 @@ function Animation:draw(x, y, options)
 end
 
 function Animation:tick(delta)
-  self.spine.animationState:update(delta * (--[[self.state.speed]]1 or 1) * self.speed)
+  self.spine.animationState:update(delta * (self.state.speed or 1) * self.speed)
   self.spine.animationState:apply(self.spine.skeleton)
 end
 

+ 7 - 0
enemy.lua

@@ -0,0 +1,7 @@
+Enemy = class()
+
+function Enemy:activate()
+  if self.zone then
+    -- Add myself to the zone's list of enemies
+  end
+end

+ 3 - 3
game.lua

@@ -15,19 +15,19 @@ function Game:load()
   self.view = View()
   self.map = Map(ctx)
   self.pigeon = Pigeon()
-  self.people = Manager()
+  self.enemies = Manager()
   self.buildings = Manager()
   self.projectiles = Manager()
   self.hud = Hud()
   self.goal = Goal()
 
-  --self.people:add(Caveman, {x = 500, y = 300})
+  self.enemies:add(Caveman, {x = 500, y = 300})
   self.buildings:add(Building, {x = 600, width = 200, height = 80})
 end
 
 function Game:update()
   self.pigeon:update()
-  self.people:update()
+  self.enemies:update()
   self.buildings:update()
   self.projectiles:update()
   self.world:update(ls.tickrate)

+ 4 - 2
person.lua

@@ -1,4 +1,4 @@
-Person = class()
+Person = extend(Enemy)
 
 ----------------
 -- Core
@@ -23,6 +23,8 @@ function Person:activate()
   self.phlerp = PhysicsInterpolator(self.body)
 
   ctx.event:emit('view.register', {object = self})
+
+  Enemy.activate(self)
 end
 
 function Person:update()
@@ -80,7 +82,7 @@ end
 function Person.dead:update()
   local x, y = self.body:getLinearVelocity()
   if (math.abs(x) < 1 and math.abs(y) < 1) or (math.abs(x) > 5000 and math.abs(y) > 5000) then
-    ctx.people:remove(self)
+    ctx.enemies:remove(self)
     self.body:destroy()
     ctx.event:emit('view.unregister', {object = self})
   end

+ 1 - 0
require.lua

@@ -14,6 +14,7 @@ require 'deps/physicsinterpolator'
 
 require 'context'
 require 'game'
+require 'enemy'
 require 'person'
 require 'caveman'
 require 'building'