bjorn vor 10 Jahren
Ursprung
Commit
68b33066d6
7 geänderte Dateien mit 146 neuen und 13 gelöschten Zeilen
  1. 11 3
      building.lua
  2. 82 2
      dinoland.lua
  3. 1 1
      goal.lua
  4. 36 1
      hud.lua
  5. 1 1
      map.lua
  6. 5 3
      person.lua
  7. 10 2
      pigeon.lua

+ 11 - 3
building.lua

@@ -1,4 +1,5 @@
 Building = class()
+Building.tag = 'building'
 
 Building.size = 60
 
@@ -48,7 +49,7 @@ function Building:update()
 
   if self.destroyed then
     local x, y = self.body:getLinearVelocity()
-    if (math.abs(x) < 1 and math.abs(y) < 1) or (math.abs(x) > 2000 and math.abs(y) > 2000) then
+    if (math.abs(x) < 4 and math.abs(y) < 4) or (math.abs(x) > 2000 and math.abs(y) > 2000) then
       self.alpha = timer.rot(self.alpha)
       if self.alpha < 0 then
         ctx.buildings:remove(self)
@@ -75,8 +76,15 @@ function Building:collideWith(other)
     return false
   end
 
-  if isa(other, Person) and other.state ~= other.dead and self.destroyed and select(2, self.body:getLinearVelocity()) > 30 then
+  if isa(other, Person) and other.state ~= other.dead and self.destroyed and select(2, self.body:getLinearVelocity()) > 250 then
     other:changeState('dead')
+    return false
+  elseif isa(other, Person) then
+    return false
+  end
+
+  if other == ctx.pigeon then
+    return false
   end
 
   return true
@@ -91,5 +99,5 @@ function Building:destroy()
   self.fixture:setFriction(0.25)
   self.body:applyLinearImpulse(-400 + love.math.random() * 600, -2000 + love.math.random() * -2000)
   self.body:setAngularVelocity(-20 + love.math.random() * 40)
-  ctx.hud:addScore(50)
+  ctx.hud:addScore(50, 'building')
 end

+ 82 - 2
dinoland.lua

@@ -1,5 +1,5 @@
 Dinoland = extend(Map)
-Dinoland.width = 4800
+Dinoland.width = 6400
 Dinoland.height = 900
 Dinoland.groundHeight = 100
 
@@ -30,6 +30,60 @@ function Dinoland:init()
 
   table.insert(self.obstacles, obstacle)
 
+  local obstacle = {}
+  obstacle.width, obstacle.height = 1000, 100
+  obstacle.body = love.physics.newBody(ctx.world, 4000, self.height - self.groundHeight - obstacle.height / 2)
+  obstacle.shape = love.physics.newRectangleShape(obstacle.width, obstacle.height)
+  obstacle.fixture = love.physics.newFixture(obstacle.body, obstacle.shape)
+  obstacle.fixture:setCategory(ctx.categories.oneWayPlatform)
+  obstacle.body:setUserData(obstacle)
+  obstacle.tag = 'platform'
+
+  table.insert(self.obstacles, obstacle)
+
+  local obstacle = {}
+  obstacle.width, obstacle.height = 200, 150
+  obstacle.body = love.physics.newBody(ctx.world, 4000, self.height - self.groundHeight - obstacle.height / 2 - 100)
+  obstacle.shape = love.physics.newRectangleShape(obstacle.width, obstacle.height)
+  obstacle.fixture = love.physics.newFixture(obstacle.body, obstacle.shape)
+  obstacle.fixture:setCategory(ctx.categories.oneWayPlatform)
+  obstacle.body:setUserData(obstacle)
+  obstacle.tag = 'platform'
+
+  table.insert(self.obstacles, obstacle)
+
+  local obstacle = {}
+  obstacle.width, obstacle.height = 200, 300
+  obstacle.body = love.physics.newBody(ctx.world, 5100, self.height - self.groundHeight - obstacle.height / 2)
+  obstacle.shape = love.physics.newRectangleShape(obstacle.width, obstacle.height)
+  obstacle.fixture = love.physics.newFixture(obstacle.body, obstacle.shape)
+  obstacle.fixture:setCategory(ctx.categories.oneWayPlatform)
+  obstacle.body:setUserData(obstacle)
+  obstacle.tag = 'platform'
+
+  table.insert(self.obstacles, obstacle)
+
+  local obstacle = {}
+  obstacle.width, obstacle.height = 200, 200
+  obstacle.body = love.physics.newBody(ctx.world, 4950, self.height - self.groundHeight - obstacle.height / 2)
+  obstacle.shape = love.physics.newRectangleShape(obstacle.width, obstacle.height)
+  obstacle.fixture = love.physics.newFixture(obstacle.body, obstacle.shape)
+  obstacle.fixture:setCategory(ctx.categories.oneWayPlatform)
+  obstacle.body:setUserData(obstacle)
+  obstacle.tag = 'platform'
+
+  table.insert(self.obstacles, obstacle)
+
+  local obstacle = {}
+  obstacle.width, obstacle.height = 200, 100
+  obstacle.body = love.physics.newBody(ctx.world, 4800, self.height - self.groundHeight - obstacle.height / 2)
+  obstacle.shape = love.physics.newRectangleShape(obstacle.width, obstacle.height)
+  obstacle.fixture = love.physics.newFixture(obstacle.body, obstacle.shape)
+  obstacle.fixture:setCategory(ctx.categories.oneWayPlatform)
+  obstacle.body:setUserData(obstacle)
+  obstacle.tag = 'platform'
+
+  table.insert(self.obstacles, obstacle)
 
   Map.init(self)
 end
@@ -40,7 +94,33 @@ function Dinoland:spawnHuts()
   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})
 
+  ctx.buildings:add(Building, {x = 2800, y = self.height - self.ground.height})
+  ctx.buildings:add(Building, {x = 3000, y = self.height - self.ground.height})
+  ctx.buildings:add(Building, {x = 3200, y = self.height - self.ground.height})
+
+  ctx.buildings:add(Building, {x = 3800, y = self.height - self.ground.height - 100})
+  ctx.buildings:add(Building, {x = 4200, y = self.height - self.ground.height - 100})
+
+  ctx.buildings:add(Building, {x = 4000, y = self.height - self.ground.height - 250})
+
+  ctx.buildings:add(Building, {x = 5300, y = self.height - self.ground.height})
+  ctx.buildings:add(Building, {x = 5400, y = self.height - self.ground.height})
+  ctx.buildings:add(Building, {x = 5500, y = self.height - self.ground.height})
+  ctx.buildings:add(Building, {x = 5600, y = self.height - self.ground.height})
+
+  for i = 1, 20 do
+    ctx.enemies:add(Caveman, {x = 2700 + love.math.random() * 600, y = self.height - self.ground.height})
+  end
+
+  for i = 1, 20 do
+    ctx.enemies:add(Caveman, {x = 1600 - 150 + love.math.random() * 300, y = self.height - self.ground.height - 200})
+  end
+
+  for i = 1, 20 do
+    ctx.enemies:add(Caveman, {x = 3500 + love.math.random() * 900, y = self.height - self.ground.height - 150})
+  end
+
   for i = 1, 20 do
-    ctx.enemies:add(Caveman, {x = 1600 - 150 + love.math.random() * 300, y = self.height - 200})
+    ctx.enemies:add(Caveman, {x = 5100 + love.math.random() * 400, y = self.height - self.ground.height})
   end
 end

+ 1 - 1
goal.lua

@@ -2,7 +2,7 @@ Goal = class()
 Goal.size = 25
 
 function Goal:init()
-  self.x = ctx.map.width - self.size
+  self.x = ctx.map.width - ctx.view.width / 2
   self.y = ctx.map.height - ctx.map.ground.height - self.size
   ctx.event:emit('view.register', {object = self})
 end

+ 36 - 1
hud.lua

@@ -8,9 +8,15 @@ function Hud:init()
 
   self.bubble = {}
   self:resetBubble()
+
+  self.rainbowShitCounter = 0
+  self.rainbowShitDisplay = 0
+  self.prevRainbowShitDisplay = 0
 end
 
 function Hud:update()
+  self.prevRainbowShitDisplay = self.rainbowShitDisplay
+
   self.bubble.prevy = self.bubble.y
   self.bubble.prevScale = self.bubble.scale
   self.bubble.prevTimer = self.bubble.timer
@@ -27,6 +33,8 @@ function Hud:update()
     end)
   end
 
+  self.rainbowShitDisplay = math.lerp(self.rainbowShitDisplay, self.rainbowShitCounter, 8 * ls.tickrate)
+
   self.scoreDisplay = math.lerp(self.scoreDisplay, self.score, 5 * ls.tickrate)
 end
 
@@ -66,6 +74,25 @@ function Hud:gui()
     g.setColor(255, 255, 255, 255 * alpha)
     g.print(str, gw / 2 - textWidth / 2, y)
   end
+
+  local baseWidth = 20
+  local baseHeight = 100
+
+  if ctx.pigeon.rainbowShitTimer > 0 then
+    love.math.setRandomSeed(love.timer.getTime() * ctx.pigeon.rainbowShitTimer - self.scoreDisplay)
+    local prc = math.min(ctx.pigeon.rainbowShitTimer / 5, 1)
+    g.setColor(128 + love.math.random() * 127, 128 + love.math.random() * 127, 128 + love.math.random() * 127)
+    g.rectangle('fill', 2, 50 + baseHeight * (1 - prc), baseWidth, baseHeight * prc)
+  else
+    g.setColor(255, 0, 0)
+  end
+
+  local baseWidth = 20
+  local baseHeight = 100
+  g.rectangle('line', 2, 50, baseWidth, baseHeight)
+  local prc = math.lerp(self.prevRainbowShitDisplay, self.rainbowShitDisplay, ls.accum / ls.tickrate) / 100
+  g.setColor(255, 0, 0)
+  g.rectangle('fill', 2, 50 + baseHeight * (1 - prc), baseWidth, baseHeight * prc)
 end
 
 function Hud:resetBubble()
@@ -81,7 +108,7 @@ function Hud:resetBubble()
   self.bubble.prevScale = self.bubble.scale
 end
 
-function Hud:addScore(amount)
+function Hud:addScore(amount, kind)
   self.bubble.active = true
   self.bubble.timer = 3
   self.bubble.amount = self.bubble.amount + amount
@@ -91,4 +118,12 @@ function Hud:addScore(amount)
   self.bubble.targetScale = self.bubble.targetScale + .1
   self.bubble.targetY = math.lerp(self.bubble.targetY, 100, .2)
   self.bubble.prevTimer = self.bubble.timer
+
+  if kind == 'person' then
+    self.rainbowShitCounter = self.rainbowShitCounter + 1
+    if self.rainbowShitCounter >= 30 then
+      self.rainbowShitCounter = 0
+      ctx.pigeon:activateRainbowShit()
+    end
+  end
 end

+ 1 - 1
map.lua

@@ -75,7 +75,7 @@ function Map:draw()
   for i = 1, #self.obstacles do
     local obstacle = self.obstacles[i]
     love.math.setRandomSeed(obstacle.body:getX() + obstacle.width)
-    g.setColor(136, 87, 44)
+    g.setColor(obstacle.color or {136, 87, 44})
     physics.draw('fill', obstacle)
 
     drawGrass(obstacle)

+ 5 - 3
person.lua

@@ -56,12 +56,14 @@ function Person:draw()
 end
 
 function Person:collideWith(other)
-  if other.tag == 'platform' and self.body:getY() > other.body:getY() then
+  if other.tag == 'building' and not other.destroyed then
+    return false
+  elseif other.tag == 'platform' and self.body:getY() > other.body:getY() then
     return false
   elseif other.tag == 'person' then
     if self.state == self.dead then
       local vx, vy = self.body:getLinearVelocity()
-      if math.distance(0, 0, vx, vy) > 100 and vy > 0 and other.state ~= other.dead then
+      if math.distance(0, 0, vx, vy) > 820 and vy > 0 and other.state ~= other.dead then
         other:changeState('dead')
       end
     else
@@ -105,7 +107,7 @@ function Person.dead:enter()
   self.fixture:setFriction(0.25)
   self.body:applyLinearImpulse(-200 + love.math.random() * 400, -200 + love.math.random() * -500)
   self.body:setAngularVelocity(-20 + love.math.random() * 40)
-  ctx.hud:addScore(10)
+  ctx.hud:addScore(10, 'person')
 end
 
 function Person.dead:update()

+ 10 - 2
pigeon.lua

@@ -96,6 +96,8 @@ function Pigeon:init()
   self:initBeak()
   self:initFeet()
 
+  self.rainbowShitTimer = 0
+
   ctx.event:emit('view.register', {object = self, depth = -10})
 end
 
@@ -106,7 +108,8 @@ function Pigeon:update()
   f.exe(self.state.update, self)
   self:contain()
 
-  self.animation.speed = love.keyboard.isDown('s') and 2 or 1
+  self.animation.speed = self.rainbowShitTimer > 0 and 2 or 1
+  self.rainbowShitTimer = timer.rot(self.rainbowShitTimer)
 
   if love.keyboard.isDown('down') then
     self.downDirty = timer.rot(self.downDirty)
@@ -186,6 +189,8 @@ function Pigeon:collideWith(other, myFixture)
     other:destroy()
   end
 
+  if isa(other, Building) then return false end
+
   return true
 end
 
@@ -334,6 +339,10 @@ function Pigeon:updateFeet()
   skeleton.flipY = false
 end
 
+function Pigeon:activateRainbowShit()
+  self.rainbowShitTimer = self.rainbowShitTimer + 5
+end
+
 ----------------
 -- Actions
 ----------------
@@ -555,4 +564,3 @@ function Pigeon.laser:update()
     end
   end
 end
-