Unity123

Spades attack

Sep 9th, 2020
780
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. sprite = "spade"
  2. bullets = {}
  3. timer = 0
  4. function Update()
  5.     timer = timer + 1
  6.     if timer%15 == 0 then
  7.         local rand = math.random(0, 3)
  8.         local posx = 0
  9.         local posy = 0
  10.         if rand == 0 then
  11.             posx = 30 - math.random(60)
  12.             posy = 90
  13.             DEBUG("top")
  14.         else if rand == 1 then
  15.             posx = 30 - math.random(60)
  16.             posy = -90
  17.             DEBUG("bottom")
  18.         else if rand == 2 then
  19.             posx = 90
  20.             posy = 30 - math.random(60)
  21.             DEBUG("left")
  22.         else
  23.             posx = -90
  24.             posy = 30 - math.random(60)
  25.             DEBUG("right")
  26.         end
  27.         local bullet = CreateProjectile(sprite, posx, posy)
  28.         bullet.sprite.rotation = math.deg(math.atan2(Player.y - posy, Player.x - posx))
  29.         bullet.SetVar("targetx", Player.absx)
  30.         bullet.SetVar("targety", Player.absy)
  31.         local xdifference = bullet["targetx"] - bullet.absx
  32.         local ydifference = bullet["targety"] - bullet.absy
  33.         local xdiffnorm = xdifference / (Misc.WindowWidth / (Misc.WindowHeight/480))
  34.         local ydiffnorm = ydifference / 480
  35.         bullet.SetVar("movex", xdiffnorm * 10)
  36.         bullet.SetVar("movey", ydiffnorm * 10)
  37.         table.insert(bullets, bullet)
  38.     end
  39.     end
  40.     end
  41.     for i=1,#bullets do
  42.         bullets[i].Move(bullets[i]["movex"], bullets[i]["movey"])
  43.     end
  44. end
RAW Paste Data