Advertisement
builderman_build

Untitled

Nov 2nd, 2016
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.25 KB | None | 0 0
  1. spawntimer = 0
  2. bullets = {}
  3.  
  4. function Update()
  5. spawntimer = spawntimer + 1
  6. if spawntimer%5 == 0 then --This happens every 30 frames.
  7. local posx = (50 - math.random(100))*5 --Set a random X position between -30 and 30
  8. local posy = 300 --and set the Y position to 65, on the top edge of the arena.
  9. local bullet = CreateProjectile('bullet', posx, posy)
  10. xHor = -posx/100
  11. bullet.SetVar('velx', xHor) -- We'll use this for horizontal speed.
  12. bullet.SetVar('vely', -10) -- We'll use this for fall speed. We're starting without downward movement.
  13. table.insert(bullets, bullet) -- Add this new Bullet object to the bullets table up there.
  14. end
  15.  
  16.  
  17. -- This part updates every bullet in the bullets table. --
  18. for i=1,#bullets do -- #bullets in Lua means 'length of bullets table'.
  19. local bullet = bullets[i] -- For convenience, so we don't have to use bullets[i]
  20. local velx = bullet.GetVar('velx') -- Get the X/Y velocity we just set
  21. local vely = bullet.GetVar('vely')
  22. local newposx = bullet.x + velx -- New position will be old position + velocity
  23. local newposy = bullet.y + vely
  24. bullet.MoveTo(newposx, newposy) -- and finally, move our bullet
  25. end
  26. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement