Browse Source

Add laser animations; Improve controls a bit;

bjorn 10 years ago
parent
commit
7e64f52807
3 changed files with 40 additions and 21 deletions
  1. 18 4
      data/animation/pigeon.lua
  2. 1 1
      game.lua
  3. 21 16
      pigeon.lua

+ 18 - 4
data/animation/pigeon.lua

@@ -1,6 +1,6 @@
 local Pigeon = extend(Animation)
 
-Pigeon.scale = .75
+Pigeon.scale = .7
 Pigeon.default = 'idle'
 Pigeon.states = {}
 
@@ -10,7 +10,10 @@ Pigeon.states.idle = {
 
 Pigeon.states.walk = {
   loop = true,
-  speed = .85
+  speed = .85,
+  mix = {
+    walk = 1
+  }
 }
 
 Pigeon.states.peck = {
@@ -19,14 +22,25 @@ Pigeon.states.peck = {
 }
 
 Pigeon.states.jump = {
-  loop = false
+  loop = false,
+  speed = .85
 }
 
 Pigeon.states.fly = {
   loop = false
 }
 
-Pigeon.states.laser = {
+Pigeon.states.laserStart = {
+  loop = false,
+  speed = .5
+}
+
+Pigeon.states.laserCharge = {
+  loop = true,
+  speed = .5
+}
+
+Pigeon.states.laserEnd = {
   loop = false
 }
 

+ 1 - 1
game.lua

@@ -22,7 +22,7 @@ function Game:load()
   self.goal = Goal()
 
   for i = 1, 50 do
-    self.enemies:add(Caveman, {x = 300 + love.math.random() * 500, y = 300})
+    self.enemies:add(Caveman, {x = 300 + love.math.random() * 1500, y = 300})
   end
 
   --self.buildings:add(Building, {x = 300, width = 200, height = 80})

+ 21 - 16
pigeon.lua

@@ -6,7 +6,7 @@ Pigeon = class()
 Pigeon.walkForce = 600
 Pigeon.maxSpeed = 350
 Pigeon.jumpForce = 3000
-Pigeon.flySpeed = 10000
+Pigeon.flySpeed = 500
 Pigeon.rocketForce = 500
 Pigeon.maxFlySpeed = 300
 Pigeon.maxFuel = 50
@@ -19,7 +19,7 @@ Pigeon.laserDuration = 1
 ----------------
 function Pigeon:init()
   self.shapeSize = 50
-  self.body = love.physics.newBody(ctx.world, self.shapeSize / 2, ctx.map.height - ctx.map.ground.height - self.shapeSize / 2, 'dynamic')
+  self.body = love.physics.newBody(ctx.world, 300, ctx.map.height - ctx.map.ground.height - self.shapeSize / 2 - 300, 'dynamic')
   self.shape = love.physics.newRectangleShape(self.shapeSize, self.shapeSize)
   self.fixture = love.physics.newFixture(self.body, self.shape)
 
@@ -41,6 +41,8 @@ function Pigeon:init()
       self.animation:set('idle')
     elseif event.state.name == 'peck' then
       self:changeState('idle')
+    elseif event.state.name == 'laserStart' then
+      self.animation:set('laserCharge')
     end
   end)
 
@@ -103,16 +105,17 @@ function Pigeon:draw()
   g.setColor(self.grounded and {0, 255, 0} or {255, 0, 0})
   g.line(x1, y1, x2, y2)
 
-  g.setColor(255, 255, 255)
-  local points = {self.feet.left.body:getWorldPoints(self.feet.left.shape:getPoints())}
-  g.polygon('line', points)
-  local points = {self.feet.right.body:getWorldPoints(self.feet.right.shape:getPoints())}
-  g.polygon('line', points)
-  local points = {self.beak.top.body:getWorldPoints(self.beak.top.shape:getPoints())}
-  g.polygon('line', points)
-  local points = {self.beak.bottom.body:getWorldPoints(self.beak.bottom.shape:getPoints())}
-  g.polygon('line', points)
-
+  if false and debug then
+    g.setColor(255, 255, 255)
+    local points = {self.feet.left.body:getWorldPoints(self.feet.left.shape:getPoints())}
+    g.polygon('line', points)
+    local points = {self.feet.right.body:getWorldPoints(self.feet.right.shape:getPoints())}
+    g.polygon('line', points)
+    local points = {self.beak.top.body:getWorldPoints(self.beak.top.shape:getPoints())}
+    g.polygon('line', points)
+    local points = {self.beak.bottom.body:getWorldPoints(self.beak.bottom.shape:getPoints())}
+    g.polygon('line', points)
+  end
 
   if self.state == self.laser and self.laser.active then
     local x1, y1, x2, y2 = self:getLaserRaycastPoints()
@@ -281,18 +284,18 @@ function Pigeon:move()
   if left then
     self.animation.flipped = true
 
-    if self.slide then
+    if self.state == self.walk and self.slide then
       self.body:setX(self.body:getX() - self.slideSpeeds[self.slide] * ls.tickrate * (self.animation.state.speed or 1) * self.animation.scale)
     elseif not self.grounded then
-      self.body:applyForce(self.body:getX() - self.flySpeed * ls.tickrate, 0)
+      self.body:applyLinearImpulse(-self.flySpeed, 0)
     end
   elseif right then
     self.animation.flipped = false
 
-    if self.slide then
+    if self.state == self.walk and self.slide then
       self.body:setX(self.body:getX() + self.slideSpeeds[self.slide] * ls.tickrate * (self.animation.state.speed or 1) * self.animation.scale)
     elseif not self.grounded then
-      self.body:applyForce(self.body:getX() + self.flySpeed * ls.tickrate, 0)
+      self.body:applyLinearImpulse(self.flySpeed, 0)
     end
   end
 
@@ -424,6 +427,7 @@ function Pigeon.laser:enter()
   self.laser.active = false
   self.laser.charge = 0
   self.laser.direction = self.animation.flipped and 3 * math.pi / 4 or math.pi / 4
+  self.animation:set('laserStart')
 end
 
 function Pigeon.laser:update()
@@ -439,6 +443,7 @@ function Pigeon.laser:update()
       end
     end
   else
+    self.animation:set('laserEnd')
     local x1, y1, x2, y2 = self:getLaserRaycastPoints()
     ctx.world:rayCast(x1, y1, x2, y2, function(fixture)
       local object = fixture:getBody():getUserData()