I recently started playing with SSK2 and I am editing some code roaminggamer made and I was wondering, how I could modify this code to have more than one turret firing at once. I trade placing them in a table, but it did not come out so well. If anyone has any suggestions, it would be greatly appreciated, thank you.
require "ssk2.loadSSK" \_G.ssk.init( {} ) require "physics" physics.start( ) physics.setGravity(0,0) local lifetime = 5000 local projectileCount = 30 local spread = 12 local bulletSpeed = 500 local turret local fireTurret local lastTarget local character local background = display.newGroup() local content = display.newGroup() local count = 0 local function onCollision( self, event ) display.remove(self) return false end local function onCollision2( self, event ) if( event.other.myType == "bullet" ) then return false end display.remove(self) end local function activateTurret( self, event ) --[[lastTarget = ssk.display.newImageRect( content, event.x, event.y, "corona256.png", { size = 40, collision = onCollision }, { radius = 20 } )]] lastTarget = ssk.display.newRect(display.contentCenterX, display.contentCenterY, {w = 20, h = 20, fill = \_G\_}) fireTurret() end ssk.display.newRect( background, centerX, centerY, { w = fullw, h = fullh, fill = \_G\_, alpha = 0.2} ) for a = 1, 2 do turret = ssk.display.newImageRect( content, 400 + (a \* 100), bottom - 75, "rg256.png", { size = 100 } ) ssk.misc.addSmartDrag( turret ) count = count + 1 end fireTurret = function() local vec = ssk.math2d.diff( turret, lastTarget ) local angle0 = ssk.math2d.vector2Angle(vec) local angle = angle0 - spread \* (projectileCount-1)/2 for i = 1, projectileCount do local vec2 = ssk.math2d.angle2Vector( angle, true ) vec2 = ssk.math2d.normalize(vec2) vec2 = ssk.math2d.scale( vec2, bulletSpeed ) local bullet = ssk.display.newImageRect( content, turret.x, turret.y, "arrow.png", { size = 20, rotation = angle, collision = onCollision2, myType = "bullet", fill = randomColor() }, { isSensor = true, radius = 10} ) bullet:toBack() bullet:setLinearVelocity( vec2.x, vec2.y ) bullet.timer = display.remove timer.performWithDelay( lifetime, bullet ) angle = angle + spread end end timer.performWithDelay(500, activateTurret, 0)