bjorn преди 10 години
родител
ревизия
92a302d6bf
променени са 6 файла, в които са добавени 120 реда и са изтрити 7 реда
  1. 36 0
      deps/typo.lua
  2. 1 0
      game.lua
  3. 77 5
      hud.lua
  4. 2 1
      person.lua
  5. 3 1
      pigeon.lua
  6. 1 0
      require.lua

+ 36 - 0
deps/typo.lua

@@ -0,0 +1,36 @@
+Typo = {}
+Typo.fonts = {}
+local setFont = love.graphics and love.graphics.setFont
+
+Typo.font = function(name, size)
+  if not love.graphics then return nil end
+  size = lume.round(size)
+
+  if name == 'mesmerize' then name = 'rawengulk' end
+
+  if not name then
+    Typo.fonts.default[size] = Typo.fonts.default[size] or love.graphics.newFont(size)
+    return Typo.fonts.default[size]
+  end
+
+  if Typo.fonts[name] and Typo.fonts[name][size] then return Typo.fonts[name][size] end
+  Typo.fonts[name] = Typo.fonts[name] or setmetatable({}, {__mode = 'v'})
+  Typo.fonts[name][size] = Typo.fonts[name][size] or love.graphics.newFont(name, size)
+  return Typo.fonts[name][size]
+end
+
+if love.graphics then
+  love.graphics.setFont = function(name, size)
+    if type(name) ~= 'string' then
+      setFont(name)
+    else
+      setFont(Typo.font(name, size))
+    end
+
+    return love.graphics.getFont()
+  end
+end
+
+Typo.resize = function()
+  table.clear(Typo.fonts)
+end

+ 1 - 0
game.lua

@@ -42,6 +42,7 @@ function Game:update()
   self.map:update()
   self.world:update(ls.tickrate)
   self.view:update()
+  self.hud:update()
 
   lurker.update()
 end

+ 77 - 5
hud.lua

@@ -1,22 +1,94 @@
 Hud = class()
 
 function Hud:init()
-  self.font = love.graphics.newFont('media/fonts/BebasNeueBold.otf', 24)
   ctx.event:emit('view.register', {object = self, mode = 'gui'})
+
+  self.score = 0
+  self.scoreDisplay = self.score
+
+  self.bubble = {}
+  self:resetBubble()
+end
+
+function Hud:update()
+  self.bubble.prevy = self.bubble.y
+  self.bubble.prevScale = self.bubble.scale
+  self.bubble.prevTimer = self.bubble.timer
+
+  if self.bubble.active then
+    self.bubble.y = math.lerp(self.bubble.y, self.bubble.targetY, 12 * ls.tickrate)
+    self.bubble.scale = math.lerp(self.bubble.scale, self.bubble.targetScale, 12 * ls.tickrate)
+
+    self.bubble.amountDisplay = math.lerp(self.bubble.amountDisplay, self.bubble.amount, 12 * ls.tickrate)
+
+    self.bubble.timer = timer.rot(self.bubble.timer, function()
+      self.score = self.score + self.bubble.amount * self.bubble.multiplier
+      self:resetBubble()
+    end)
+  end
+
+  self.scoreDisplay = math.lerp(self.scoreDisplay, self.score, 5 * ls.tickrate)
 end
 
 function Hud:gui()
   local g = love.graphics
-  local w, h = g.getDimensions()
+  local gw, gh = g.getDimensions()
   if ctx.debug then
     local x, y = ctx.view:worldPoint(love.mouse.getPosition())
-    g.setFont(self.font)
+    g.setFont('media/fonts/BebasNeueBold.otf', 24)
     g.setColor(0, 0, 0)
     g.print(x .. ', ' .. y, 3, 3)
     g.setColor(255, 255, 255)
     g.print(x .. ', ' .. y, 2, 2)
     x, y = love.mouse.getPosition()
-    g.line(x, 0, x, h)
-    g.line(0, y, w, y)
+    g.line(x, 0, x, gh)
+    g.line(0, y, gw, y)
+  end
+
+  g.setFont('media/fonts/BebasNeueBold.otf', 24)
+  g.setColor(0, 0, 0, 150)
+  local str = math.round(self.scoreDisplay)
+  local w = math.max(g.getFont():getWidth(str), 80)
+  local h = g.getFont():getHeight()
+  g.rectangle('fill', 0, 0, w + 8, h + 8)
+  g.setColor(255, 255, 255)
+  g.print(str, 4, 4)
+
+  if self.bubble.active then
+    local y, scale = math.lerp(self.bubble.prevy, self.bubble.y, ls.accum / ls.tickrate), math.lerp(self.bubble.prevScale, self.bubble.scale, ls.accum / ls.tickrate)
+    g.setFont('media/fonts/BebasNeueBold.otf', math.max(math.round(scale / .01) * .01 * 24, 1))
+    local alpha = math.clamp(math.lerp(self.bubble.prevTimer, self.bubble.timer, ls.accum / ls.tickrate), 0, 1)
+    g.setColor(0, 0, 0, 128 * alpha)
+    local amount = math.round(self.bubble.amountDisplay)
+    local str = amount .. (self.bubble.multiplier > 1 and ('X ' .. self.bubble.multiplier) or '')
+    local textWidth = g.getFont():getWidth(str)
+    g.print(str, gw / 2 - textWidth / 2 + 1, y + 1)
+    g.setColor(255, 255, 255, 255 * alpha)
+    g.print(str, gw / 2 - textWidth / 2, y)
   end
 end
+
+function Hud:resetBubble()
+  self.bubble.active = false
+  self.bubble.amount = 0
+  self.bubble.timer = 0
+  self.bubble.multiplier = 0
+  self.bubble.targetY = 300
+  self.bubble.y = self.bubble.targetY
+  self.bubble.prevy = self.bubble.y
+  self.bubble.targetScale = 1
+  self.bubble.scale = self.bubble.targetScale
+  self.bubble.prevScale = self.bubble.scale
+end
+
+function Hud:addScore(amount)
+  self.bubble.active = true
+  self.bubble.timer = 3
+  self.bubble.amount = self.bubble.amount + amount
+  self.bubble.amountDisplay = self.bubble.amount
+  self.bubble.multiplier = self.bubble.multiplier + 1
+  --self.bubble.scale = self.bubble.scale + .2
+  self.bubble.targetScale = self.bubble.targetScale + .1
+  self.bubble.targetY = math.lerp(self.bubble.targetY, 100, .2)
+  self.bubble.prevTimer = self.bubble.timer
+end

+ 2 - 1
person.lua

@@ -94,8 +94,9 @@ function Person.dead:enter()
   self.body:setFixedRotation(false)
   self.fixture:setCategory(ctx.categories.debris)
   self.fixture:setFriction(0.25)
-  self.body:applyLinearImpulse(-200 + love.math.random() * 400, -300 + love.math.random() * -500)
+  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)
 end
 
 function Person.dead:update()

+ 3 - 1
pigeon.lua

@@ -94,7 +94,7 @@ function Pigeon:init()
   self:initBeak()
   self:initFeet()
 
-  ctx.event:emit('view.register', {object = self})
+  ctx.event:emit('view.register', {object = self, depth = -10})
 end
 
 function Pigeon:update()
@@ -172,6 +172,8 @@ function Pigeon:collideWith(other, myFixture)
     end
   elseif isa(other, Building) and not other.destroyed and self.state == self.peck and (myFixture == self.beak.top.fixture or myFixture == self.beak.bottom.fixture) then
     other:destroy()
+  elseif isa(other, Building) and not other.destroyed and self.state == self.air and select(2, self.body:getLinearVelocity()) > 0 and (myFixture == self.feet.left.fixture or myFixture == self.feet.right.fixture) then
+    other:destroy()
   end
 
   return true

+ 1 - 0
require.lua

@@ -11,6 +11,7 @@ require 'deps/event'
 require 'deps/view'
 require 'deps/manager'
 require 'deps/physicsinterpolator'
+require 'deps/typo'
 
 require 'context'
 require 'game'