Bladeren bron

Weapon swtich timers;

bjorn 11 jaren geleden
bovenliggende
commit
be714fe82b
4 gewijzigde bestanden met toevoegingen van 25 en 15 verwijderingen
  1. 3 2
      data/weapon/shotgun.lua
  2. 3 2
      data/weapon/smg.lua
  3. 10 7
      lib/core/weapon.lua
  4. 9 4
      lib/player.lua

+ 3 - 2
data/weapon/shotgun.lua

@@ -14,8 +14,9 @@ Shotgun.type = 'weapon'
 ----------------
 Shotgun.image = data.media.graphics.shotgun
 Shotgun.damage = 25
-Shotgun.fireSpeed = .65
-Shotgun.reloadSpeed = 2
+Shotgun.fireTime = .65
+Shotgun.reloadTime = 2
+Shotgun.switchTime = .75
 Shotgun.clip = 4
 Shotgun.ammo = 16
 Shotgun.spread = math.rad(12)

+ 3 - 2
data/weapon/smg.lua

@@ -14,8 +14,9 @@ SMG.type = 'weapon'
 ----------------
 SMG.image = data.media.graphics.smg
 SMG.damage = 14
-SMG.fireSpeed = .15
-SMG.reloadSpeed = 1.6
+SMG.fireTime = .15
+SMG.reloadTime = 1.6
+SMG.switchTime = .5
 SMG.clip = 12
 SMG.ammo = 120
 SMG.spread = .03

+ 10 - 7
lib/core/weapon.lua

@@ -2,9 +2,9 @@ Weapon = class()
 
 function Weapon:activate(owner)
   self.timers = {}
-  self.timers.switch = 0
   self.timers.shoot = 0
   self.timers.reload = 0
+  self.timers.switch = 0
   
   self.currentAmmo = self.ammo
   self.currentClip = self.clip
@@ -18,6 +18,7 @@ function Weapon:update(owner)
     self.currentAmmo = self.currentAmmo - amt
     ctx.event:emit('sound.play', {sound = 'reload'})
   end)
+  self.timers.switch = timer.rot(self.timers.switch)
 end
 
 function Weapon:draw(owner)
@@ -30,28 +31,30 @@ function Weapon:draw(owner)
 end
 
 function Weapon:select(owner)
-
+  self.timers.switch = self.switchTime
 end
 
 function Weapon:canFire(owner)
-  return self.timers.shoot == 0 and self.timers.reload == 0 and self.currentClip > 0
+  return self.timers.switch == 0 and self.timers.shoot == 0 and self.timers.reload == 0 and self.currentClip > 0
 end
 
 function Weapon:fire(owner)
   ctx.spells:activate(owner.id, data.spell[self.code])
   
-  self.timers.shoot = self.fireSpeed
+  self.timers.shoot = self.fireTime
   self.currentClip = self.currentClip - 1
-  if self.currentClip == 0 then self.timers.reload = self.reloadSpeed end
+  if self.currentClip == 0 then self.timers.reload = self.reloadTime end
   owner.recoil = self.recoil
 end
 
 function Weapon:reload(owner)
   if self.currentClip < self.clip and self.timers.reload == 0 then
-    self.timers.reload = self.reloadSpeed
+    self.timers.reload = self.reloadTime
   end
 end
 
 function Weapon:value(owner)
-  return self.timers.reload > 0 and (self.timers.reload / self.reloadSpeed) or 0
+  if self.timers.switch > 0 then return self.timers.switch / self.switchTime
+  elseif self.timers.reload > 0 then return self.timers.reload / self.reloadTime
+  else return 0 end
 end

+ 9 - 4
lib/player.lua

@@ -116,12 +116,17 @@ end
 function Player:slot(input)
   input = input or {}
 
-  local weapon = self.slots[self.weapon]
-  local skill = self.slots[self.skill]
-
   if input.slot then
-    self[self.slots[input.slot].type] = input.slot
+    local k = self.slots[input.slot].type
+    if self[k] ~= input.slot then
+      self[k] = input.slot
+      local slot = self.slots[input.slot]
+      f.exe(slot.select, slot, self)
+    end
   end
+
+  local weapon = self.slots[self.weapon]
+  local skill = self.slots[self.skill]
   
   for i = 1, 5 do
     if self.slots[i].type ~= 'weapon' or self.weapon == i then