Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local keiki = require("keiki")
- --[[
- * a usual (slow) game's code goes something like this:
- *
- * list = keiki.new(100)
- * while wait() do
- * list:iter(list_update_function)
- * end
- --]]
- --> a list of bullets. each has a 2D position, speed, and angle.
- local list_bullet = keiki.new(512,function(may,i,o)
- o.position = Vector2.new()
- o.speed = 0
- o.angle = 0
- end)
- --> loops through all bullets in the list, to move them all at once.
- local function bullet_update(list,i,o)
- -- if the current object is dead, then don't update it!
- if not o.dead then
- local angle = o.angle
- local speed = o.speed
- local velocity = speed * Vector2.new(math.cos(angle),math.sin(angle))
- o.position = o.position + velocity
- end
- end
- --> creates a new bullet in the list.
- local function bullet_add(pos,spd,ang)
- -- > 0 is the first argument, since there aren't
- -- >>any other types of bullets.
- list_bullet:add(0,function(list,i,o)
- o.position = pos
- o.speed = spd
- o.angle = ang
- end)
- end
- --> now let's actually shoot some damn bullets for once
- local timer = 0
- game:GetService("RunService").Heartbeat:Connect(function(dt)
- -- every 0.5 seconds, add a new bullet.
- if timer>=0.5 then
- timer = 0
- bullet_add( Vector2.new(0,0),4,math.rad(timer*10) )
- end
- -- now, update the bullets.
- list_bullet:iter( bullet_update )
- -- wait and add to the timer
- timer = timer + dt
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement