Browse Source

Fuck with laser;

bjorn 10 years ago
parent
commit
4de51c8edf
2 changed files with 34 additions and 16 deletions
  1. 5 2
      map.lua
  2. 29 14
      pigeon.lua

+ 5 - 2
map.lua

@@ -32,10 +32,13 @@ function Map:draw()
   local g = love.graphics
 
   g.setColor(255, 255, 255)
-  local image = data.media.graphics.dinoland.dinolandBackground
+  local image = data.media.graphics.dinoland.dinolandBackground1
   local scale = self.height / image:getHeight()
-  for x = 1, self.width, image:getWidth() * scale do
+  for x = 1, self.width, image:getWidth() * scale * 2 do
+    image = data.media.graphics.dinoland.dinolandBackground1
     g.draw(image, x, self.height, 0, scale, scale, 0, image:getHeight())
+    image = data.media.graphics.dinoland.dinolandBackground2
+    g.draw(image, x + image:getWidth() * scale, self.height, 0, scale, scale, 0, image:getHeight())
   end
 
   g.setColor(136, 87, 44)

+ 29 - 14
pigeon.lua

@@ -6,11 +6,11 @@ Pigeon = class()
 Pigeon.walkForce = 600
 Pigeon.maxSpeed = 350
 Pigeon.jumpForce = 3000
-Pigeon.flySpeed = 500
+Pigeon.flySpeed = 50
 Pigeon.rocketForce = 500
 Pigeon.maxFlySpeed = 300
 Pigeon.maxFuel = 25
-Pigeon.laserTurnSpeed = .35
+Pigeon.laserTurnSpeed = .75
 Pigeon.laserChargeDuration = 2
 
 ----------------
@@ -131,11 +131,20 @@ function Pigeon:draw()
     g.polygon('line', points)
   end
 
-  if self.state == self.laser and self.laser.active then
+  if self.state == self.laser then
     local x1, y1, x2, y2 = self:getLaserRaycastPoints()
+    local dis, dir = math.vector(x1, y1, x2, y2)
+    local len = dis
+    ctx.world:rayCast(x1, y1, x2, y2, function(fixture, x, y, xn, yn, f)
+      if lume.find({fixture:getCategory()}, ctx.categories.ground) then
+        len = math.min(len, dis * f)
+        return len
+      end
+      return 1
+    end)
     g.setColor(255, 0, 0)
-    g.setLineWidth(10)
-    g.line(x1, y1, x2, y2)
+    g.setLineWidth(self.laser.active and 10 or 1)
+    g.line(x1, y1, x1 + len * math.cos(dir), y1 + len * math.sin(dir))
     g.setLineWidth(1)
   end
 
@@ -180,7 +189,7 @@ end
 function Pigeon:getLaserRaycastPoints()
   local x1, y1 = self.animation.spine.skeleton.x + self.animation.spine.skeleton:findBone('beakbottom').worldX, self.animation.spine.skeleton.y - self.animation.spine.skeleton:findBone('beakbottom').worldY
   local dir = self.laser.direction
-  local x2, y2 = x1 + math.cos(dir) * 500, y1 + math.sin(dir) * 500
+  local x2, y2 = x1 + math.cos(dir) * 2000, y1 + math.sin(dir) * 2000
   return x1, y1, x2, y2
 end
 
@@ -456,7 +465,14 @@ end
 
 function Pigeon.laser:update()
   if not self.laser.active then
-    if not love.keyboard.isDown(' ') then
+
+    if love.keyboard.isDown('up', 'right') then
+      self.laser.direction = self.laser.direction - self.laserTurnSpeed * ls.tickrate * math.sign(math.pi / 2 - self.laser.direction)
+    elseif love.keyboard.isDown('down', 'left') then
+      self.laser.direction = self.laser.direction + self.laserTurnSpeed * ls.tickrate * math.sign(math.pi / 2 - self.laser.direction)
+    end
+
+    if not love.keyboard.isDown(' ') or self.animation.state.name == 'laserCharge' then
       if self.animation.state.name == 'laserCharge' or self.animation.state.name == 'laserEnd' then
         self.animation:set('laserEnd')
       else
@@ -465,20 +481,19 @@ function Pigeon.laser:update()
     end
   else
     local x1, y1, x2, y2 = self:getLaserRaycastPoints()
-    ctx.world:rayCast(x1, y1, x2, y2, function(fixture)
+    local dis = math.distance(x1, y1, x2, y2)
+    ctx.world:rayCast(x1, y1, x2, y2, function(fixture, x, y, xn, yn, fraction)
       local object = fixture:getBody():getUserData()
       if object and isa(object, Person) and object.state ~= object.dead then
         object:changeState('dead')
+        return -1
+      elseif lume.find({fixture:getCategory()}, ctx.categories.ground) then
+        return fraction * dis
       end
 
       return 1
     end)
-
-    if love.keyboard.isDown('up', 'right') then
-      self.laser.direction = self.laser.direction - self.laserTurnSpeed * ls.tickrate
-    elseif love.keyboard.isDown('down', 'left') then
-      self.laser.direction = self.laser.direction + self.laserTurnSpeed * ls.tickrate
-    end
   end
+
 end