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