Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags
(1 edit)

Dev Log: 17-07-2018

**** Warning wall of text incoming! ****

So, i was having issues with the random pleacement of the enemies, so thought about different ways to randomly spawn enemies in the level.

The first method i thought about was to just choose two random numbers for X and Y axis and just spawn an enemy at those locations, however this had a few issues. First i would need to be sure that the enemies do not overlap or just spawn above each other, and that the X and Y coordinates randomly choose were actually inside de vieweing area... to check all that with the way construct works was not my first option.... 

So i came up with another idea... spawn points! I quickly created a sprite and called it portal. Then made some copies of it and spread it around the level, of course this "portals" would be invisible to the player.

Then by using construct "command" to pick a random instance of an object i spawned the enemies on those randomly choosen portals! Should work right?

Well, it kind of did, the enemies did spawned randomly where they should... however there was a small issue, sometimes 2 or more enemies could spawn at the same portal! That was not good!

So i went back to thinking... how could i avoid enemies spawning at the same place??? My first idea was random numbers!

The theory was like this, i would use an array fill it with random numers and use those numbers to choose a portal and spawn the enemy there! Welp! nope, it didnt work! Again the random number generator was giving me some numbers twice!

Ok, then... if i cant make it generate unique random numbers then i can do is shuffle the array! So i filled the array with number from 0 to 5, and then after googling a bit found an example on how to shuffle an array, so now the array had numbers from 0 to 5 but shuffled! It should work right??? Wellllll..... nope :|

Yes, the array was shuffled and without duplicates but now the issue was that since it was numbers from 0 to 5 the enemies always spawned at the first 5 portals! Thats not what i wanted!

Well.... time to think a complete different approach! Since neither of the previous ways worked, i had to think something different, so while i was staring at my motionless portals i had an idea! What if i set a local variable to each portal that indicated if an enemy spawned at it??? Welllll..... it worked!

The idea is basically the following:

I created a loop, that would repeat itself while a variable was equal to 0. Inside this loop i would pick a random instance of a portal object and checked that its local variable spawned was equal to 0, if it was i would create an object at it and set the spawned variable to 1 so it doesnt get choosen again. After all that i had another variable that i used to count the amount of enemies spawned so i increased it by one. Then... i would check if this variable was equal to another one that had the amount of maximum amounts of enemies that i wanted for that wave, if it was equal then i would set the variable that was controling the while loop to 1 making it exit the loop!

Andddd so far is working! No bugs yet! i hope it stays that way!

Edit: Typo