Guest User

Untitled

a guest
Apr 15th, 2013
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.17 KB | None | 0 0
  1.  
  2.     -- I create an array for ALL arrays
  3.     arrayObject = {}
  4.     -- Then I create the array for the player, enemies and bullets
  5.     players = {}
  6.     enemies = {}
  7.     bullets = {}
  8.     -- And put the arrays in arrayObject
  9.     table.insert(arrayObject,players)
  10.     table.insert(arrayObject,enemies)
  11.     table.insert(arrayObject,bullets)
  12.     -- I create a player, and 3 enemies
  13.     Player = player(500,100)
  14.     table.insert(players,Player)   
  15.     Enemy = enemy(-300,394,1)
  16.     table.insert(enemies,Enemy)
  17.     Enemy = enemy(-500,394,1)
  18.     table.insert(enemies,Enemy)
  19.     Enemy = enemy(-700,394,1)
  20.     table.insert(enemies,Enemy)
  21.  
  22. -- I go through all arrays, minus the last one, loop 1.
  23. for i=1,#arrayObject-1,1 do
  24.         -- Here I check loop 1 + the remaining arrays, loop 2
  25.         for j=i+1,#arrayObject,1 do
  26.             -- Next I loop through the content of the array of loop 1
  27.             for k=1,#arrayObject[i],1 do
  28.                 -- And here I loop through the content of the array of loop 2
  29.                 for m=1,#arrayObject[j],1 do
  30.                     local obj1 = arrayObject[i][k]
  31.                     local obj2 = arrayObject[j][m]
  32.                     -- I check the collision
  33.                     if (checkCollision(obj1,obj2)) then
  34.                         obj1:collision(obj2)
  35.                         obj2:collision(obj1)
  36.                     end
  37.                 end
  38.             end
  39.         end
  40.     end
Advertisement
Add Comment
Please, Sign In to add comment