function loop.init()

 local worm_smoke = load_particle("worm_smoke.obj")
 local worm_spark = load_particle("worm_spark_1.obj")

 local sound_footstep = sounds["worm_footstep.wav"]
 local sound_alarm = sounds["worm_alarm.wav"]

  function bindings.playerUpdate(player)
  local worm = player:worm()
  local health = worm:health()

--SMOKE/ALARM/SPARKS WHEN DEADISH

  if health < 20 and health > 0 then

   if math.random(-20,40) > health then
    worm:shoot(worm_smoke, 1, 0, 0, 0, 0, 360, 0, 3)
   end

   if math.random(-1000,30) > health then
    local direction = math.random(0,360)
    worm:shoot(worm_spark, 4, 0.85, 0.3, 0, 0, 30, direction, 1)
   end

   local alarm = worm:data().alarm
   if alarm then
    alarm = alarm + 1
    if alarm > 280 then
     alarm = 1
     sound_alarm:play(worm,nil,33,1,0)
    end
   else
    alarm = 1
    sound_alarm:play(worm,nil,100,1,0)
   end
   worm:data().alarm = alarm

  end

  

--MOVEMENT FRAME COUNTER

  local dx, dy =worm:spd()
  local x, y = worm:pos()

  local frame = worm:data().frame
  local spd = math.abs(dx)
  if frame then
   if spd > 0.01 and health > 0 then
    frame = frame + spd * 3
    if frame > 100 then
     frame = 0
     sound_footstep:play(worm,nil,100,1,0)
    end
    if frame > 50 and frame < 52 then
     sound_footstep:play(worm,nil,100,1,0)
     frame = 52
    end
   else
    frame = 90
   end
  else
   frame = 0
  end
  if map_is_particle_pass(x, y+6) and map_is_particle_pass(x+3, y+6) and map_is_particle_pass(x-3, y+6) then
   frame = 0
  end
  worm:data().frame = frame

--WEAPON CHANGING EFFECT
  local weapon_changing = player:data().weapon_changing
  if weapon_changing then
   player:data().weapon_changing = weapon_changing * 0.9
  else
   player:data().weapon_changing = 0
  end
 end

end
