lua - Finding free space in square to spawn enemy -


I have an area where the enemy needs to look good (they are behind a fence) and I do not The enemies want to lay eggs on each other, so I was wondering what is a good way to do this?

I created a function that fits in the next box (next enemy) all possible state (pixels by pixels), but it is slow because it is a mobile application and Enemies can sometimes be born quickly, be sure that there should be a good thread that can calculate different limitations where the next enemy can fit?

There are very good solutions.

  1. Fast and easy. You can only check limitations. Each of your squares has 2 points for the enemy. You can easily test, if two rectangles pierce each other, and if you sort your x coordinate, then you can check the difference between them. If the difference is high, then compare the width of the next enemy - check the y difference, and then place eggs there.

      Here you have left x1_1 == 25, x1_2 == 29 and x2_1 = 10, x2_2 = 15x1_1 after enemy's coordination of enemy 1, x2_2 - x 2_2 - right is. After some sorting, enemy 2's x-ray difference will be equal to x 2_1 and x1_2, so you can fit anyone here =)  
  2. Regularly grid But split your spawn location, mark as occupation, all the chambers within enemy limits. Do not see pixels, but cell to find space for spawn.

      | ----- | ----- | ----- | | 1 + - | -2- + | 3 | // 1,2,4,5 was outstanding very easy check | | | | | | // You must update that information occasionally. --- | - | --- + - - ----- | | 4 + --- 5- + | 6 | | | | | | ----- | ----- | ----- | If the spawn point is big, consider Quattree, to split it into segments again to check the places that fit. 


Comments