playMaker

Author Topic: Auto Spawn in enemies - How to do a check if the block is occupied  (Read 240 times)

BlueBarracks

  • Playmaker Newbie
  • *
  • Posts: 3
    • View Profile
Hey guys

Im new here, and Im busy with an android game a with a plants V zombies feel. I have setup tiles in an array where the player and the AI can spawn in units and towers. The blocks are in an array so the AI is setup to choose a random block from the array and spawn a random unit / tower to that block. Im trying to figure out how to set it up so that before spawning in it checks if the block is occupied by another tower. Is there anyone that can give me a bit of direction on how to do this?

Thanks in advance!

djaydino

  • Administrator
  • Hero Member
  • *****
  • Posts: 4178
    • View Profile
    • jinxtergames
Re: Auto Spawn in enemies - How to do a check if the block is occupied
« Reply #1 on: December 29, 2018, 11:12:42 PM »
hi.
You should have an array for each line of tiles, then have a 2nd array with bools corresponding to the tiles array.

So lets say you have a 10x10 grid then you will need 10 arrays for the tiles.

Make the 1st array and call it 'row 0' (best is to start with 0 as index also start with 0)
the 1st tile should be on index 0 and the last tile on index 9.

Then make a 2nd array and call it row 0 Check)
This should be a bool array (if you want to know what is on the tile an int array might be better)

Do this for each row.

Then when you place a tower on the 3rd tile in row 0 (3rd tile will be in index 2 on the array) :
Set the bool value to true on the 'row 0 Check' on index 2.

To check if a tile is occupied, select the tile, then find it in the row arrays, then get the index and use that index to check the bool value on the 'row 0 Check'

i hope you understand what i mean.
If not, let me know and i will make a video after the new year.

Best is to use arraymaker with this, its more advanced that the included array.