Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- I create an array for ALL arrays
- arrayObject = {}
- -- Then I create the array for the player, enemies and bullets
- players = {}
- enemies = {}
- bullets = {}
- -- And put the arrays in arrayObject
- table.insert(arrayObject,players)
- table.insert(arrayObject,enemies)
- table.insert(arrayObject,bullets)
- -- I create a player, and 3 enemies
- Player = player(500,100)
- table.insert(players,Player)
- Enemy = enemy(-300,394,1)
- table.insert(enemies,Enemy)
- Enemy = enemy(-500,394,1)
- table.insert(enemies,Enemy)
- Enemy = enemy(-700,394,1)
- table.insert(enemies,Enemy)
- -- I go through all arrays, minus the last one, loop 1.
- for i=1,#arrayObject-1,1 do
- -- Here I check loop 1 + the remaining arrays, loop 2
- for j=i+1,#arrayObject,1 do
- -- Next I loop through the content of the array of loop 1
- for k=1,#arrayObject[i],1 do
- -- And here I loop through the content of the array of loop 2
- for m=1,#arrayObject[j],1 do
- local obj1 = arrayObject[i][k]
- local obj2 = arrayObject[j][m]
- -- I check the collision
- if (checkCollision(obj1,obj2)) then
- obj1:collision(obj2)
- obj2:collision(obj1)
- end
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment