So, I,ve been struggling to make this work for a while now and need help. What I have right now is a bunch of spawns from a spawnInt counter, and they seem to place spawns directly behind others - which is something I don’t want for this game.
Is there a way I can make the spawns check and see if they are behind another, and if it is, move slightly to the left or right side?
Here is how I am spawning enemies:
local function spawnEnemy() local xPos = math.random(20,300) -- Value 160 for testing local r = math.floor(math.random() \* 3) -- Random colors are assigned to \>\> 0 = Blue(Rectangle) | 1 = Red(Cross) | 2 = Green(Circle) if(r == 0) then blue = display.newSprite(imageSheetRectangle, sequenceDataRectangle ) blue.name = "Blue" physics.addBody(blue, { isSensor = true }) blue.x = xPos blue:setSequence("blueRect") blue:setFrame(3) --blue:play() blue.y = display.contentHeight - 550 blue:toFront() print(xPos) enemyGroup:insert(blue) elseif(r == 1) then red = display.newSprite(imageSheetCross, sequenceDataCross) red.name = "Red" physics.addBody(red, {isSensor = true }) red.x = xPos red:setSequence("blueCross") red:setFrame(1) red:toFront() --red:play() print(xPos) red.y = display.contentHeight - 550 enemyGroup:insert(red) elseif(r == 2) then green = display.newSprite(imageSheetCircle, sequenceDataCircle ) green.name = "Green" physics.addBody(green, { isSensor = true }) green.x = xPos green:setSequence("blueCirc") green:setFrame(2) green:toFront() print(xPos) --green:play() green.y = display.contentHeight - 550 -- 550 default print(xPos) enemyGroup:insert(green) end if spawned == spawnAmount then --start a new wave in 3 seconds. spawnInt = 100 --stops the gameloop. wave = wave + 1 --Increase the wave we are on spawned = 0 --Reset so that the next wave starts from 0. spawnAmount = perWave + (wave \* perWaveIncrease) local timer = timer.performWithDelay(6000, function() spawnInt = 0; waveText.text = "Wave: "..wave; waveText.x = \_W\*0.1; end, 1) else spawnInt = 0 end end
