浏览代码

Scaling issues; Bugfixes;

bjorn 11 年之前
父节点
当前提交
2493af9ce4

+ 5 - 7
data/hud/hudclassselect.lua

@@ -15,7 +15,6 @@ end
 
 function HudClassSelect:update()
   self.angle = (self.angle + .65 * tickRate) % (2 * math.pi)
-  if ctx.id and not ctx.players:get(ctx.id).active then self.active = true end
   if not love.mouse.isVisible() then love.mouse.setVisible(true) end
 end
 
@@ -55,7 +54,8 @@ function HudClassSelect:draw()
       g.setColor(255, 255, 255, 150)
     end
 
-    g.draw(data.class[i].sprite, w(.09) * i + w(.04), h(.326) + w(.04), self.angle, data.class[i].scale, data.class[i].scale, data.class[i].anchorx, data.class[i].anchory)
+    local s = data.class[i].scale * ctx.view.scale * .75
+    g.draw(data.class[i].sprite, w(.09) * i + w(.04), h(.326) + w(.04), self.angle, s, s, data.class[i].anchorx, data.class[i].anchory)
   end
 
   g.setColor(hover and white or gray)
@@ -91,7 +91,9 @@ function HudClassSelect:keypressed(key)
   end
 end
 
-function HudClassSelect:mousepressed(x, y, button)
+function HudClassSelect:mousepressed() return self.active end
+
+function HudClassSelect:mousereleased(x, y, button)
   if self.active and button == 'l' then
     for i = 1, #data.class do
       if math.inside(x, y, w(.09) * i, h(.326), w(.08), w(.08)) then
@@ -120,10 +122,6 @@ function HudClassSelect:mousepressed(x, y, button)
   return self.active
 end
 
-function HudClassSelect:mousereleased(x, y, button)
-  return self.active
-end
-
 function HudClassSelect:drawClassDetails(index)
   local fh = g.getFont():getHeight()
   g.setColor(255, 255, 255)

+ 1 - 1
data/hud/huddebug.lua

@@ -6,6 +6,7 @@ local w, h = g.width, g.height
 function HudDebug:draw()
   ctx.players:each(function(p)
     g.push()
+    g.scale(ctx.view.scale)
     g.translate(-ctx.view.x, -ctx.view.y)
     if p.team == purple then g.setColor(190, 160, 220, p.alpha * 100)
     else g.setColor(240, 160, 140, p.alpha * 100) end
@@ -20,7 +21,6 @@ function HudDebug:draw()
 
   g.setColor(255, 255, 255, 100)
   local debug = love.timer.getFPS() .. 'fps'
-  debug = debug .. ', tick' .. math.round(tick / 10) * 10
   if ctx.net.server then
     debug = debug .. ', ' .. ctx.net.server:round_trip_time() .. 'ms'
     debug = debug .. ', ' .. math.floor(ctx.net.host:total_sent_data() / 1000 + .5) .. 'tx'

+ 6 - 5
data/hud/hudicons.lua

@@ -29,6 +29,7 @@ function HudIcons:update()
 end
 
 function HudIcons:draw()
+  local top = h(.1)
   local p = ctx.players:get(ctx.id)
   if p then
     local width = data.media.graphics.icons[p.slots[1].code]:getWidth()
@@ -36,9 +37,9 @@ function HudIcons:draw()
     for i = 1, 5 do
       local icon = data.media.graphics.icons[p.slots[i].code]
       local alpha = math.min(math.lerp(self.prevLabelAlphas[i], self.labelAlphas[i], tickDelta / tickRate), 1) * 200
-      local iconx = w(.5) - g.minUnit(.213) + g.minUnit(.106 * (i - 1))
+      local iconx = w(.5) - g.minUnit(.213) + g.minUnit(.1065 * (i - 1))
       g.setColor(255, 255, 255, math.max(alpha, 100) * (255 / 200))
-      g.draw(icon, iconx - (width / 2), h(.093), 0, s, s)
+      g.draw(icon, iconx - (width * s / 2), top, 0, s, s)
 
       local prc = 0      
       if p.slots[i].value then
@@ -46,7 +47,7 @@ function HudIcons:draw()
       end
 
       g.setColor(0, 0, 0, 128)
-      local x, y = iconx, h(.093)
+      local x, y = iconx, top
       
       local points = {}
       local function insert(x, y)
@@ -93,12 +94,12 @@ function HudIcons:draw()
       local strw, strh = g.getFont():getWidth(str), g.getFont():getHeight()
       
       g.setColor(0, 0, 0, alpha)
-      g.rectangle('fill', iconx - ((strw + 3) / 2), h(.093) + width + 1, strw + 3, strh + 2)
+      g.rectangle('fill', iconx - ((strw + 3) / 2), top + (width * s) + 1, strw + 3, strh + 2)
       
       if p.slots[i].type == 'weapon' then g.setColor(255, 150, 150, alpha)
       elseif p.slots[i].type == 'skill' then g.setColor(150, 150, 255, alpha)
       else g.setColor(255, 255, 255, alpha) end
-      g.printCenter(str, iconx, h(.093) + width + 2, true, false)
+      g.printCenter(str, iconx, top + (width * s) + 2, true, false)
     end
   end
 end

+ 4 - 2
data/hud/hudleft.lua

@@ -4,11 +4,13 @@ local g = love.graphics
 local w, h = g.width, g.height
 
 function HudLeft:draw()
+  local s = ctx.view.scale
+
   g.setColor(255, 255, 255, 64)
-  g.draw(data.media.graphics.hud.leftBg, -w(.0825), -h(.0083))
+  g.draw(data.media.graphics.hud.leftBg, -w(.0825), -h(.0083), 0, s, s)
   
   g.setColor(255, 255, 255)
-  g.draw(data.media.graphics.hud.left, -w(.08), -h(.013))
+  g.draw(data.media.graphics.hud.left, -w(.08), -h(.013), 0, s, s)
   
   local p = ctx.players:get(ctx.id)
   if p then

+ 8 - 7
data/hud/hudplayers.lua

@@ -8,10 +8,11 @@ function HudPlayers:draw()
   ctx.players:each(function(p)
     local vx, vy = math.lerp(ctx.view.prevx, ctx.view.x, tickDelta / tickRate), math.lerp(ctx.view.prevy, ctx.view.y, tickDelta / tickRate)
     local px, py = p:drawPosition()
-    g.setColor(0, 0, 0, 100)
+    local alpha = p.alpha * (1 - (p.cloak / (p.team == ctx.players:get(ctx.id).team and 2 or 1)))
+    g.setColor(0, 0, 0, 100 * alpha)
     g.printCenter(p.username, (px - vx) * ctx.view.scale + 1, ((py - vy) * ctx.view.scale) - 60 + 1)
-    if p.team == purple then g.setColor(190, 160, 220, p.alpha * 255)
-    elseif p.team == orange then g.setColor(240, 160, 140, p.alpha * 255) end
+    if p.team == purple then g.setColor(190, 160, 220, alpha * 255)
+    elseif p.team == orange then g.setColor(240, 160, 140, alpha * 255) end
     g.printCenter(p.username, (px - vx) * ctx.view.scale, ((py - vy) * ctx.view.scale) - 60)
 
     if not p.ded then
@@ -20,16 +21,16 @@ function HudPlayers:draw()
       local healthWidth, shieldWidth = (p.health / p.maxHealth) * 80, (p.shield / p.maxHealth) * 80
       local totalWidth = math.max(healthWidth + shieldWidth, 80)
 
-      g.setColor(0, 0, 0, 128 * p.alpha) -- Dark background
+      g.setColor(0, 0, 0, 128 * alpha) -- Dark background
       g.rectangle('fill', x0, y0, totalWidth, 10)
       
-      g.setColor(200, 0, 0, 128 * p.alpha) -- Health
+      g.setColor(200, 0, 0, 128 * alpha) -- Health
       g.rectangle('fill', x0 + .5, y0 + .5, healthWidth - 1, 10 - 1)
       
-      g.setColor(220, 220, 220, 128 * p.alpha) -- Shield
+      g.setColor(220, 220, 220, 128 * alpha) -- Shield
       g.rectangle('fill', x0 + healthWidth, y0, shieldWidth, 10)
       
-      g.setColor(150, 0, 0, 255 * p.alpha) -- Frame
+      g.setColor(150, 0, 0, 255 * alpha) -- Frame
       g.rectangle('line', x0, y0, totalWidth, 10)
     end
   end)

+ 4 - 2
data/hud/hudright.lua

@@ -4,11 +4,13 @@ local g = love.graphics
 local w, h = g.width, g.height
 
 function HudRight:draw()
+  local s = ctx.view.scale
+
   g.setColor(255, 255, 255, 64)
-  g.draw(data.media.graphics.hud.rightBg, w(.81375), -h(.003))
+  g.draw(data.media.graphics.hud.rightBg, w(.81375), -h(.003), 0, s, s)
   
   g.setColor(255, 255, 255, 255)
-  g.draw(data.media.graphics.hud.right, w(.80375), -h(.01))
+  g.draw(data.media.graphics.hud.right, w(.80375), -h(.01), 0, s, s)
   
   local p = ctx.players:get(ctx.id)
   if p then

+ 2 - 11
data/spell/dagger.lua

@@ -1,8 +1,8 @@
 local Dagger = {}
 Dagger.code = 'dagger'
 Dagger.hp = .5
-Dagger.radius = 14
-Dagger.distance = 55
+Dagger.radius = 18
+Dagger.distance = 45
 
 function Dagger:activate(owner)
   self.hp = Dagger.hp
@@ -29,13 +29,4 @@ function Dagger:update(owner)
   self.hp = timer.rot(self.hp, function() ctx.spells:deactivate(self) end)
 end
 
-function Dagger:draw()
-  local g = love.graphics
-  local alpha = 255 * (self.hp / Dagger.hp) * self.owner.alpha
-  g.setColor(self.target and {0, 255, 0, alpha * (100 / 255)} or {255, 0, 0, alpha * (100 / 255)})
-  g.circle('fill', self.x, self.y, self.radius)
-  g.setColor(self.target and {0, 255, 0, alpha * (100 / 255)} or {255, 0, 0, alpha * (100 / 255)})
-  g.circle('line', self.x, self.y, self.radius)
-end
-
 return Dagger

+ 2 - 4
data/spell/dusk.lua

@@ -26,9 +26,7 @@ function Dusk:update()
   end
 
   self.distance = self.distance - (self.speed * tickRate)
-  if self.distance <= 0 then
-    ctx.spells:deactivate(self)
-  end
+  if self.distance <= 0 then ctx.spells:deactivate(self) end
 end
 
-return Dusk
+return Dusk

+ 3 - 5
data/spell/smokescreen.lua

@@ -6,17 +6,15 @@ Smokescreen.radius = 160
 Smokescreen.image = data.media.graphics.effects.smoke
 
 function Smokescreen:activate(mx, my)
-  self.timer = self.duration
+  self.timer = Smokescreen.duration
   self.angle = love.math.random() * math.pi * 2
   self.x, self.y = mx, my
   ctx.event:emit('sound.play', {sound = 'smoke'})
 end
 
 function Smokescreen:update()
-  if self.owner.cloak < 1 then
-    if math.distance(self.x, self.y, self.owner.x, self.owner.y) < self.radius then
-      self.owner.cloak = math.min(self.owner.cloak + (3 * tickRate), 1)
-    end
+  if self.owner.cloak < 1 and math.distance(self.x, self.y, self.owner.x, self.owner.y) < self.radius then
+    self.owner.cloak = math.min(self.owner.cloak + (3 * tickRate), 1)
   end
 
   self.timer = timer.rot(self.timer, function() ctx.spells:deactivate(self) end)

+ 33 - 15
data/weapon/dagger.lua

@@ -1,32 +1,50 @@
-local Weapon = {}
+local Dagger = {}
 
-Weapon.name = 'Dagger'
-Weapon.code = 'dagger'
-Weapon.text = 'Stabby'
-Weapon.type = 'weapon'
+Dagger.name = 'Dagger'
+Dagger.code = 'dagger'
+Dagger.text = 'Stabby'
+Dagger.type = 'weapon'
 
-Weapon.damage = 45
-Weapon.cooldown = .8
+Dagger.damage = 45
+Dagger.cooldown = .8
 
-function Weapon:activate(owner)
+function Dagger:activate(owner)
   self.timer = 0
 end
 
-function Weapon:update(owner)
+function Dagger:update(owner)
   self.timer = timer.rot(self.timer)
 end
 
-function Weapon:canFire(owner)
+function Dagger:canFire(owner)
   return self.timer == 0
 end
 
-function Weapon:fire(owner)
-  ctx.spells:activate(self.id, data.spell.dagger)
+function Dagger:fire(owner)
+  ctx.spells:activate(owner.id, data.spell.dagger)
   self.timer = self.cooldown
 end
 
-function Weapon:draw(owner)
-  --
+function Dagger:crosshair()
+  local g, p, d, x, y = love.graphics, ctx.players:get(ctx.id), data.spell.dagger, love.mouse.getPosition()
+  local v = ctx.view
+  local t = (self.timer / self.cooldown)
+  local o = (t ^ 2 * ((1 + 1.6) * t - 1.6)) * (d.radius + 10)
+
+  if math.distance(x, y, (p.x - v.x) * v.scale, (p.y - v.y) * v.scale) < d.distance * v.scale then
+    x, y = p.x + math.dx(d.distance, p.angle) - v.x, p.y + math.dy(d.distance, p.angle) - v.y
+    x, y = x * v.scale, y * v.scale
+  end
+
+  g.setColor(255, 255, 255, 255 * (1 - p.cloak / 2))
+  g.setLineWidth(2 + p.cloak)
+  for i = 1, 4 do
+    local ang = p.angle - math.pi / 4 + (i * math.pi / 2)
+    local x1, y1 = x + math.dx(d.radius - 4 - o, ang), y + math.dy(d.radius - 4 - o, ang)
+    local x2, y2 = x + math.dx(d.radius + 4 - o, ang), y + math.dy(d.radius + 4 - o, ang)
+    g.line(x1, y1, x2, y2)
+  end
+  g.setLineWidth(1)
 end
 
-return Weapon
+return Dagger

+ 4 - 4
data/weapon/shotgun.lua

@@ -33,21 +33,21 @@ Shotgun.tipy = -10
 ----------------
 function Shotgun:crosshair()
   local g, p, x, y = love.graphics, ctx.players:get(ctx.id), love.mouse.getPosition()
-  local vx, vy = ctx.view:mouseX(), ctx.view:mouseY()
+  local vx, vy, s = ctx.view:mouseX(), ctx.view:mouseY(), ctx.view.scale
   local d = math.distance(p.x, p.y, vx, vy)
   local alpha = 50 + ((300 - math.clamp(d - 200, 0, 300)) / 300) * 205
   
   local dir = p.angle
-  local dx, dy = p.class.handx * p.class.scale, p.class.handy * p.class.scale
+  local dx, dy = p.class.handx * p.class.scale * s, p.class.handy * p.class.scale * s
   x = x + math.dx(dx, dir) - math.dy(dy, dir)
   y = y + math.dy(dx, dir) + math.dx(dy, dir)
   
-  dx, dy = self.tipx * self.scale, self.tipy * self.scale
+  dx, dy = self.tipx * self.scale * s, self.tipy * self.scale * s
   x = x + math.dx(dx, dir) - math.dy(dy, dir)
   y = y + math.dy(dx, dir) + math.dx(dy, dir)
   
   g.setColor(255, 255, 255, alpha)
-  g.circle('line', x, y, math.abs(math.atan(self.spread / 2)) * math.distance(p.x, p.y, vx, vy))
+  g.circle('line', x, y, math.abs(math.atan(self.spread / 2)) * math.distance(p.x, p.y, vx, vy) * s)
 end
 
 return Shotgun

+ 11 - 10
data/weapon/smg.lua

@@ -20,7 +20,7 @@ SMG.reloadTime = 1.6
 SMG.switchTime = .5
 SMG.clip = 12
 SMG.ammo = 120
-SMG.spread = .03
+SMG.spread = .04
 SMG.recoil = 3
 SMG.anchorx = 15
 SMG.anchory = 7
@@ -32,25 +32,26 @@ SMG.tipy = 0
 ----------------
 function SMG:crosshair()
   local g, p, x, y = love.graphics, ctx.players:get(ctx.id), love.mouse.getPosition()
-  local vx, vy = ctx.view:mouseX(), ctx.view:mouseY()
+  local vx, vy, s = ctx.view:mouseX(), ctx.view:mouseY(), ctx.view.scale
   local d = math.distance(p.x, p.y, vx, vy)
-  local r = math.abs(math.atan(self.spread)) * math.distance(p.x, p.y, vx, vy) 
+  local r = math.abs(math.atan(self.spread)) * math.distance(p.x, p.y, vx, vy) * s
+  local len = 4 * s
   
   local dir = p.angle
-  local dx, dy = p.class.handx * p.class.scale, p.class.handy * p.class.scale
+  local dx, dy = p.class.handx * p.class.scale * s, p.class.handy * p.class.scale * s
   x = x + math.dx(dx, dir) - math.dy(dy, dir)
   y = y + math.dy(dx, dir) + math.dx(dy, dir)
   
-  dx, dy = self.tipx * self.scale, self.tipy * self.scale
+  dx, dy = self.tipx * self.scale * s, self.tipy * self.scale * s
   x = x + math.dx(dx, dir) - math.dy(dy, dir)
   y = y + math.dy(dx, dir) + math.dx(dy, dir)
 
   g.setColor(255, 255, 255)
-  g.circle('line', x, y, r)
-  g.line(x, y - r - 4, x, y - r + 4)
-  g.line(x - r - 4, y, x - r + 4, y)
-  g.line(x + r - 4, y, x + r + 4, y)
-  g.line(x, y + r - 4, x, y + r + 4)
+  g.circle('line', x, y, r )
+  g.line(x, y - r - len, x, y - r + len)
+  g.line(x - r - len, y, x - r + len, y)
+  g.line(x + r - len, y, x + r + len, y)
+  g.line(x, y + r - len, x, y + r + len)
 end
 
 return SMG

+ 2 - 7
lib/core/spells.lua

@@ -9,15 +9,14 @@ end
 function Spells:activate(owner, kind, ...)
   local s = new(kind)
   s.owner = ctx.players:get(owner)
-  self.spells[#self.spells + 1] = s
-  s._idx = #self.spells
+  self.spells[s] = s
   s:activate(...)
   return s
 end
 
 function Spells:deactivate(s)
   f.exe(s.deactivate, s)
-  table.remove(self.spells, s._idx)
+  self.spells[s] = nil
 end
 
 function Spells:update()
@@ -27,7 +26,3 @@ end
 function Spells:draw()
   table.with(self.spells, 'draw')
 end
-
-function Spells:post()
-  table.with(self.spells, 'post')
-end

+ 2 - 0
lib/core/view.lua

@@ -1,6 +1,8 @@
 View = class()
 
 function View:init()
+  love.window.setMode(0, 0, {fullscreen = true})
+
   self.x = 0
   self.y = 0
   self.w = 800

+ 13 - 2
lib/player.lua

@@ -72,6 +72,11 @@ function Player:activate()
   self.maxHealth = self.class.health
   self.health = self.maxHealth
 
+  ctx.buffs:removeAll(self)
+  self.lifesteal = 0
+  self.haste = 0
+  self.cloak = 0
+
   self.depth = -self.id
 end
 
@@ -151,12 +156,18 @@ function Player:slot(input)
   
   if input.l and weapon:canFire(self) then
     weapon:fire(self, input.x, input.y)
-    ctx.net:emit(evtFire, {id = self.id, slot = self.weapon, mx = input.x, my = input.y})
+
+    local msg = {id = self.id, slot = self.weapon}
+    if weapon.needsMouse then msg.mx, msg.my = input.x, input.y end
+    ctx.net:emit(evtFire, msg)
   end
   
   if input.r and skill:canFire(self) then
     skill:fire(self, input.x, input.y)
-    ctx.net:emit(evtFire, {id = self.id, slot = self.skill})
+    
+    local msg = {id = self.id, slot = self.skill}
+    if skill.needsMouse then msg.mx, msg.my = input.x, input.y end
+    ctx.net:emit(evtFire, msg)
   end
 
   if input.reload then weapon:reload(self) end

+ 1 - 0
lib/playermain.lua

@@ -8,6 +8,7 @@ function PlayerMain:activate()
   self.alpha = 1
   
   self.lastHurt = tick
+  if self.heartbeatSound then self.heartbeatSound:stop() end
   self.heartbeatSound = ctx.sound:loop({sound = 'heartbeat'})
   self.heartbeatSound:pause()