2
0
Эх сурвалжийг харах

Core player updates; Collision fixes;

Bjorn 11 жил өмнө
parent
commit
e06badb1d2

+ 1 - 1
data/buff/bloodlust.lua

@@ -33,7 +33,7 @@ function Bloodlust:update()
     self.owner:heal({amount = self.heal * self.rate})
     self.healTimer = math.round(Bloodlust.rate / tickRate)
     self.timer = self.timer - self.rate
-    if self.timer <= 0 then ctx.buffs:remove(self.owner, 'bloodlust') end
+    if self.timer <= 0 then ctx.buffs:remove(self.owner, self.code) end
   end
 end
 

+ 4 - 2
data/hud/hudplayers.lua

@@ -6,10 +6,12 @@ local w, h = g.width, g.height
 function HudPlayers:draw()
   g.setFont('aeromatics', h(.02))
   ctx.players:each(function(p)
-    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
     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)
+    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
     g.printCenter(p.username, (px - vx) * ctx.view.scale, ((py - vy) * ctx.view.scale) - 60)
 
     if not p.ded then

+ 1 - 1
data/spell/smg.lua

@@ -16,7 +16,7 @@ SMG.activate = function(self)
   dx, dy = data.weapon.smg.tipx, data.weapon.smg.tipy
   self.x = self.x + math.dx(dx, dir) - math.dy(dy, dir)
   self.y = self.y + math.dy(dx, dir) + math.dx(dy, dir)
-  
+
   self.angle = self.owner.angle
   self.angle = self.angle - (data.weapon.smg.spread / 2) + (love.math.random() * data.weapon.smg.spread)
   local hit, dis = ctx.collision:lineTest(self.x, self.y, self.x + math.dx(900, self.angle), self.y + math.dy(900, self.angle), {tag = 'wall', first = true})

+ 3 - 1
lib/core/collision.lua

@@ -63,9 +63,11 @@ function Collision:resolve(obj)
   shape.owner = obj
   obj.shape = shape
   self.hc:update()
-  self.hc:remove(shape)
 
   obj.shape = oldShape
+  obj.shape:moveTo(shape:center())
+
+  self.hc:remove(shape)
 end
 
 function Collision:pointTest(x, y, options)

+ 2 - 2
lib/core/spells.lua

@@ -6,12 +6,12 @@ function Spells:init()
   if ctx.view then ctx.view:register(self) end
 end
 
-function Spells:activate(owner, kind)
+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
-  s:activate()
+  s:activate(...)
   return s
 end
 

+ 7 - 7
lib/netserver.lua

@@ -8,16 +8,16 @@ NetServer.signatures[evtSync] = {
   {'id', '4bits'},
   {'tick', '16bits'},
   {'ack', '16bits'},
-  {'x', '12bits'},
-  {'y', '12bits'},
+  {'x', '12bits'}, {'y', '12bits'},
   {'angle', '10bits'},
-  {'health', '10bits'},
-  {'shield', '10bits'},
-  {'weapon', '3bits'},
-  {'skill', '3bits'},
+  {'health', '10bits'}, {'shield', '10bits'},
+  {'weapon', '3bits'}, {'skill', '3bits'},
   delta = {'x', 'y', 'angle', 'health', 'shield', 'weapon', 'skill'}
 }
-NetServer.signatures[evtFire] = {{'id', '4bits'}, {'slot', '3bits'}}
+NetServer.signatures[evtFire] = {
+  {'id', '4bits'}, {'slot', '3bits'}, {'mx', '12bits'}, {'my', '12bits'},
+  delta = {{'mx', 'my'}}
+}
 NetServer.signatures[evtDamage] = {{'id', '4bits'}, {'amount', 'string'}, {'from', '4bits'}}
 NetServer.signatures[evtDead] = {{'id', '4bits'}, {'kill', '4bits'}, {'assists', {{'id', '4bits'}}}}
 NetServer.signatures[evtSpawn] = {{'id', '4bits'}}

+ 15 - 8
lib/player.lua

@@ -47,6 +47,7 @@ function Player:init()
 
   self.lifesteal = 0
   self.haste = 0
+  self.cloak = 0
 
   self.depth = 0
   self.recoil = 0
@@ -70,13 +71,17 @@ function Player:activate()
   self.depth = -self.id
 end
 
-Player.update = f.empty
+function Player:update()
+  if self.recoil > 0 then self.recoil = math.lerp(self.recoil, 0, math.min(5 * tickRate, 1)) end
+  self.cloak = timer.rot(self.cloak)
+end
 
 function Player:draw()
   local g, c = love.graphics, self.class
-  g.setColor(0, 0, 0, self.alpha * 50)
+  local alpha = self.alpha * (1 - (self.cloak / (self.team == ctx.players:get(ctx.id).team and 2 or 1)))
+  g.setColor(0, 0, 0, alpha * 50)
   g.draw(c.sprite, self.x + 4, self.y + 4, self.angle, 1, 1, c.anchorx, c.anchory)
-  g.setColor(self.team == purple and {190, 160, 200, self.alpha * 255} or {240, 160, 140, self.alpha * 255})
+  g.setColor(self.team == purple and {190, 160, 200, alpha * 255} or {240, 160, 140, alpha * 255})
   g.draw(c.sprite, self.x, self.y, self.angle, 1, 1, c.anchorx, c.anchory)
   f.exe(self.slots[self.weapon].draw, self.slots[self.weapon], self)
   f.exe(self.slots[self.skill].draw, self.slots[self.skill], self)
@@ -87,6 +92,10 @@ end
 -- Behavior
 ----------------
 function Player:move(input)
+  if input.reposition then
+    self.x, self.y = input.reposition.x, input.reposition.y
+  end
+
   local w, a, s, d = input.w, input.a, input.s, input.d
   if not (w or a or s or d) then return end
   
@@ -102,7 +111,7 @@ function Player:move(input)
   local dir = (dx + dy) / 2
   local len = (self.class.speed + self.haste) * tickRate
   self.x, self.y = self.x + math.dx(len, dir), self.y + math.dy(len, dir)
-  
+
   self.x = math.clamp(self.x, 0, ctx.map.width)
   self.y = math.clamp(self.y, 0, ctx.map.height)
 
@@ -137,18 +146,16 @@ function Player:slot(input)
   end
   
   if input.l and weapon:canFire(self) then
-    weapon:fire(self)
+    weapon:fire(self, input.x, input.y)
     ctx.net:emit(evtFire, {id = self.id, slot = self.weapon})
   end
   
   if input.r and skill:canFire(self) then
-    skill:fire(self)
+    skill:fire(self, input.x, input.y)
     ctx.net:emit(evtFire, {id = self.id, slot = self.skill})
   end
 
   if input.reload then weapon:reload(self) end
-  
-  if self.recoil > 0 then self.recoil = math.lerp(self.recoil, 0, math.min(5 * tickRate, 1)) end
 end
 
 Player.hurt = f.empty

+ 2 - 1
lib/playerdummy.lua

@@ -9,8 +9,9 @@ function PlayerDummy:activate()
 end
 
 function PlayerDummy:update()
-  if self.recoil > 0 then self.recoil = math.lerp(self.recoil, 0, math.min(5 * tickRate, 1)) end
   self:slot()
+  
+  Player.update(self)
 end
 
 function PlayerDummy:get(t)

+ 7 - 4
lib/playermain.lua

@@ -3,6 +3,7 @@ PlayerMain = extend(Player)
 function PlayerMain:activate()
   self.prev = setmetatable({}, self.meta)
   self.inputs = {}
+  self.displaces = {}
 
   self.alpha = 1
   
@@ -16,7 +17,6 @@ function PlayerMain:activate()
 end
 
 function PlayerMain:get(t)
-  assert(t == tick or t == tick - 1)
   if t == tick then
     return self
   else
@@ -45,7 +45,9 @@ function PlayerMain:update()
     self.heartbeatSound:pause()
   end
  
-  ctx.net:buffer(msgInput, self.inputs[#self.inputs])
+  ctx.net:buffer(msgInput, input)
+
+  Player.update(self)
 end
 
 function PlayerMain:draw()
@@ -61,13 +63,14 @@ function PlayerMain:trace(data)
   while #self.inputs > 0 and self.inputs[1].tick < data.ack + 1 do
     table.remove(self.inputs, 1)
   end
- 
+
   -- Server reconciliation: Apply inputs that occurred after the ack.
   for i = 1, #self.inputs do
     self:move(self.inputs[i])
   end
 
-  ctx.event:emit('collision.move', {object = self, x = self.x, y = self.y})
+  ctx.collision:resolve(self)
+  self.x, self.y = self.shape:center()
 end
 
 function PlayerMain:readInput()

+ 1 - 1
lib/players.lua

@@ -22,7 +22,7 @@ function Players:init()
     if ctx.id and data.id ~= ctx.id then
       local p = self:get(data.id)
       local slot = p.slots[data.slot]
-      slot:fire(p)
+      slot:fire(p, data.mx, data.my)
     end
   end)
   

+ 2 - 0
lib/playerserver.lua

@@ -45,6 +45,8 @@ function PlayerServer:update()
       self:heal({amount = self.maxHealth * percentage * tickRate})
     end
   end
+
+  Player.update(self)
 end
 
 function PlayerServer:trace(data, ping)