Jelajahi Sumber

Shell particle;

bjorn 11 tahun lalu
induk
melakukan
39100b01b7
4 mengubah file dengan 53 tambahan dan 0 penghapusan
  1. TEMPAT SAMPAH
      data/media/graphics/effects/shell.png
  2. 35 0
      data/particle/shell.lua
  3. 9 0
      data/spell/shotgun.lua
  4. 9 0
      data/spell/smg.lua

TEMPAT SAMPAH
data/media/graphics/effects/shell.png


+ 35 - 0
data/particle/shell.lua

@@ -0,0 +1,35 @@
+local Shell = {}
+
+Shell.name = 'Shell'
+Shell.code = 'shell'
+
+Shell.activate = function(self)
+  self.speed = love.math.random(250, 500)
+  self.angularVelocity = love.math.random(-1, 1) * 2 * math.pi
+  self.angle = love.math.random() * 2 * math.pi
+  self.alpha = .8
+  self.image = data.media.graphics.effects.shell
+  self.scale = 1
+  self.speedDecay = 5 + love.math.random() * 3
+end
+
+Shell.update = function(self)
+  self.angularVelocity = math.lerp(self.angularVelocity, 0, math.min(4 * tickRate, 1))
+  self.angle = self.angle + self.angularVelocity * tickRate
+  self.speed = math.lerp(self.speed, 0, math.min(self.speedDecay * tickRate, 1))
+  self.x = self.x + math.dx(self.speed * tickRate, self.direction)
+  self.y = self.y + math.dy(self.speed * tickRate, self.direction)
+  if self.speed < .5 then
+    self.alpha = math.lerp(self.alpha, 0, math.min(4 * tickRate, 1))
+    if self.alpha < .01 then
+      return true
+    end
+  end
+end
+
+Shell.draw = function(self)
+  love.graphics.setColor(255, 255, 255, self.alpha * 255)
+  love.graphics.draw(self.image, self.x, self.y, self.angle, self.scale, self.scale, self.image:getWidth() / 2, self.image:getHeight() / 2)
+end
+
+return Shell

+ 9 - 0
data/spell/shotgun.lua

@@ -96,6 +96,15 @@ Shotgun.activate = function(self)
     }
   })
 
+  ctx.event:emit('particle.create', {
+    kind = 'shell',
+    vars = {
+      x = self.x,
+      y = self.y,
+      direction = self.owner.angle + love.math.random() * .8 - .4
+    }
+  })
+
   ctx.event:emit('sound.play', {sound = 'shotgun', x = self.x, y = self.y})
   if ctx.view then ctx.view:screenshake(5) end
 end

+ 9 - 0
data/spell/smg.lua

@@ -79,6 +79,15 @@ SMG.activate = function(self)
     }
   })
 
+  ctx.event:emit('particle.create', {
+    kind = 'shell',
+    vars = {
+      x = self.x,
+      y = self.y,
+      direction = self.owner.angle + love.math.random() * .8 - .4
+    }
+  })
+
   ctx.event:emit('sound.play', {sound = 'smg', x = self.x, y = self.y})
 end