Browse Source

Screenshake; Start spear shit;

bjorn 10 years ago
parent
commit
6939b53718
7 changed files with 46 additions and 27 deletions
  1. 3 9
      caveman.lua
  2. 1 1
      deps/view.lua
  3. 1 1
      dinoland.lua
  4. 2 2
      hud.lua
  5. 1 1
      map.lua
  6. 33 13
      pigeon.lua
  7. 5 0
      spear.lua

+ 3 - 9
caveman.lua

@@ -11,8 +11,8 @@ function Caveman:activate()
   self.image = data.media.graphics.dinoland[self.gender].normal
   self.direction = 1
 
-  self.state = self.panic
-  self.hasSpear = true
+  self.hasSpear = love.math.random() > .5
+  self.state = self.hasSpear and self.attack or self.panic
   self.walkTimer = 1
   self.reloadTimer = 0
 
@@ -55,10 +55,6 @@ function Caveman.panic:update()
   end
 
   self:reloadSpear()
-
-  if self.hasSpear then
-    --self:changeState('attack')
-  end
 end
 
 Caveman.attack = {}
@@ -68,10 +64,8 @@ function Caveman.attack:update()
   self.image = data.media.graphics.dinoland[self.gender].normal
 
   if self:inRange() then
-    if self.walkTimer == 0 then
-      self.hasSpear = false
+    if self.walkTimer == 0 and self.reloadTimer == 0 then
       self.reloadTimer = lume.random(unpack(self.reloadRange))
-      self:changeState('panic')
     end
   else
     if self.walkTimer == 0 then

+ 1 - 1
deps/view.lua

@@ -196,7 +196,7 @@ function View:follow()
   local margin = 0.5
 
   self.x = x - self.width * margin
-  self.y = y - self.height * margin
+  self.y = y - self.height * .75
 end
 
 function View:contain()

+ 1 - 1
dinoland.lua

@@ -1,6 +1,6 @@
 Dinoland = extend(Map)
 Dinoland.width = 2400
-Dinoland.height = 600
+Dinoland.height = 1200
 
 function Dinoland:init()
   self.zones = {}

+ 2 - 2
hud.lua

@@ -12,12 +12,12 @@ function Hud:gui()
   g.print(ctx.pigeon.fuel, 0, 0)
 
   if ctx.pigeon.state == ctx.pigeon.laser then
-    local percent = math.min(ctx.pigeon.laser.charge / (ctx.pigeon.laser.active and ctx.pigeon.laserDuration or ctx.pigeon.laserChargeDuration), 1)
+    --[[local percent = math.min(ctx.pigeon.laser.charge / (ctx.pigeon.laser.active and ctx.pigeon.laserDuration or ctx.pigeon.laserChargeDuration), 1)
     local x, y = ctx.view:screenPoint(ctx.pigeon.body:getX(), ctx.pigeon.body:getY() - 100)
     local w, h = 80, 5
     g.setColor(255, 255, 255, 80)
     g.rectangle('fill', x - w / 2, y - h / 2, w * percent, h)
     g.setColor(255, 255, 255)
-    g.rectangle('line', x - w / 2, y - h / 2, w, h)
+    g.rectangle('line', x - w / 2, y - h / 2, w, h)]]
   end
 end

+ 1 - 1
map.lua

@@ -25,7 +25,7 @@ function Map:draw()
   local image = data.media.graphics.dinoland.dinolandBackground
   local scale = self.height / image:getHeight()
   for x = 1, self.width, image:getWidth() * scale do
-    g.draw(image, x, 0, 0, scale, scale)
+    g.draw(image, x, self.height, 0, scale, scale, 0, image:getHeight())
   end
 
   g.setColor(136, 87, 44)

+ 33 - 13
pigeon.lua

@@ -55,13 +55,26 @@ function Pigeon:init()
     elseif name == 'rightStep' then
       self.slide = 'right'
       self.drop = nil
+      if self.walk.firstShake == false then
+        ctx.view:screenshake(6)
+      else
+        self.walk.firstShake = false
+      end
     elseif name == 'leftStep' then
       self.slide = 'left'
       self.drop = nil
+      if self.walk.firstShake == false then
+        ctx.view:screenshake(6)
+      else
+        self.walk.firstShake = false
+      end
     elseif name == 'leftStop' or name == 'rightStop' then
       self.slide = nil
     elseif name == 'jump' then
       self:jump()
+    elseif name == 'laser' then
+      self.laser.active = true
+      self.laser.charge = self.laserDuration
     elseif name == 'peck' and self.state == self.peck then
       self.peck.impact(self)
     end
@@ -148,6 +161,7 @@ end
 -- Helpers
 ----------------
 function Pigeon:changeState(target)
+  print('changing state to ' .. target)
   if self.state == target then return end
   f.exe(self.state.exit, self)
   self.state = self[target]
@@ -345,6 +359,10 @@ function Pigeon.idle:update()
 end
 
 Pigeon.walk = {}
+function Pigeon.walk:enter()
+  self.walk.firstShake = true
+end
+
 function Pigeon.walk:update()
   local left, right = love.keyboard.isDown('left'), love.keyboard.isDown('right')
   self.animation:set('walk')
@@ -370,6 +388,13 @@ Pigeon.air = {}
 function Pigeon.air:enter()
   self.jumped = false
   self.animation:set('jump')
+  self.air.lastVelocity = 0
+end
+
+function Pigeon.air:exit()
+  if self.air.lastVelocity > 800 then
+    ctx.view:screenshake(20 + (self.air.lastVelocity / 100))
+  end
 end
 
 function Pigeon.air:update()
@@ -387,7 +412,7 @@ function Pigeon.air:update()
   end
 
   if love.keyboard.isDown(' ') then
-    if self.fuel > 0 then
+    if self.fuel > 0 and not self.grounded then
       if (vy > 0 or math.abs(vy) < self.maxFlySpeed) then
         self.fuel = math.max(self.fuel - 33 * ls.tickrate, 0)
 
@@ -396,8 +421,11 @@ function Pigeon.air:update()
       end
 
       self.animation:set('fly')
+      self.jumped = true
     end
   end
+
+  self.air.lastVelocity = vy
 end
 
 Pigeon.peck = {}
@@ -415,35 +443,27 @@ function Pigeon.peck:exit()
 end
 
 function Pigeon.peck:impact()
-  local skeleton = self.animation.spine.skeleton
-
-  table.each(self.beak, function(beak, name)
-    --
-  end)
+  ctx.view:screenshake(20)
 end
 
 Pigeon.laser = {}
 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()
   if not self.laser.active then
-    if love.keyboard.isDown(' ') then
-      self.laser.charge = self.laser.charge + ls.tickrate
-    else
-      if self.laser.charge > self.laserChargeDuration then
-        self.laser.active = true
+    if not love.keyboard.isDown(' ') then
+      if self.animation.state.name == 'laserCharge' then
         self.laser.charge = self.laserDuration
+        --self.animation:set('laserEnd')
       else
         self:changeState('idle')
       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()

+ 5 - 0
spear.lua

@@ -0,0 +1,5 @@
+Spear = extend(Projectile)
+
+function Spear:activate()
+
+end