function sparkthrower.init()

 local gun_rail = load_particle("sparkthrower_gun_rail.obj")
 local gun_sparks = load_particle("sparkthrower_gun_sparks.obj")
 local gun_laser = load_particle("sparkthrower_gun_laser.obj")
 local gun_laserdot = load_particle("sparkthrower_gun_laserdot.obj")

 local wallsparkle_1 = load_particle("sparkthrower_wallsparkle_1.obj")
 local wallsparkle_2 = load_particle("sparkthrower_wallsparkle_2.obj")


 local sound_discharge = sounds["sparkthrower_discharge.wav"]

 local dischargechance = 1

 function sparkthrower.gun(worm)

  local angle = worm:angle()
  local rail_1 = worm:shoot(gun_rail, 1, 0, 0, 0, 0, 0, 30, 2)
  local rail_2 = worm:shoot(gun_rail, 1, 0, 0, 0, 0, 0, -30, 2)
  local dx, dy = angle_vector(angle,4)
  rail_1:set_spd(dx,dy)
  rail_2:set_spd(dx,dy)

  for a=1, 8 do
   local laser = worm:shoot(gun_laser, 1, 0, 0, 0, 0, 0, 30, 4)
   laser:set_spd(dx * a * 0.01, dy * a * 0.01)
  end

  local laserdot = worm:shoot(gun_laserdot, 1, 0, 0, 0, 0, 0, 30, 4)
  laserdot:set_spd(dx * 0.25, dy * 0.25)

  local sparkthrower_sparkling = worm:data().sparkthrower_sparkling
  if not sparkthrower_sparkling and math.random(0,100000)*0.001 < dischargechance then
   sparkthrower_sparkling = 1
   sound_discharge:play(worm,nil,100,1,0.1)
  end
  if sparkthrower_sparkling then
   if sparkthrower_sparkling > 0 then
    worm:shoot(gun_sparks, 1, 0, 0, 0, 0, 0, 0, 2 + sparkthrower_sparkling)
   end
   sparkthrower_sparkling = sparkthrower_sparkling + 0.2
   if sparkthrower_sparkling > 8.5 then
    sparkthrower_sparkling = nil
   end
  end
  worm:data().sparkthrower_sparkling = sparkthrower_sparkling
 end

 function sparkthrower.shoot(worm)
  worm:data().sparkthrower_sparkling = -40
 end

 function sparkthrower.wallsparkle_1(object)
  for a=1, 4 do
   local wallsparkle = object:shoot( wallsparkle_1, 1, 1, 0, 0, 0, 360, 0, 4)
   wallsparkle:data().target = object
  end
 end

 function sparkthrower.wallsparkle_2(object)
  local target = object:data().target
  local wallsparkle = object:shoot( wallsparkle_2, 1, 0, 0, 0, 0, 0, 0, 0)
  wallsparkle:set_pos(target:pos())
  object:remove()
 end

end
