Steven Ren devlog #4 - World Instantiation


Happy almost end of quarter everyone!

There's now more resources and enemies in the game! I managed to get the plants to randomly spawn and new enemies to randomly spawn as well when killed. Plants randomly spawn anywhere on the map away from other plants and objects (except for mistletoe which only spawns at the top of the map) and enemies can spawn anywhere not next to other enemies, objects, and the player's screen!

For this vertical slice, each of the 4 plant spawns 3 copies of itself. So I use a nested for loop for the spawning. Inside the nested for loop, I create an array of gameobjects to avoid, like plants and objects. Then in a forever loop, I continuously generate random coordinates until it's a good distance away from every game object in the array. I wonder if there's a better way to implement this...

The ghoul spawning is pretty much the same with an extra winkle in the mix: it has to be off the player's current screen! It would be weird if the player kills an enemy just for another one to descent from heaven right in front of them, mocking their arrogance (lol). 

To implement this, I did some research, after all, I've never thought about the player screen before, just the world coordinates. At the end of the day, I settled on using aspect, orthographicSize, and a little math instead of ScreenToWorldPoint. I use the player's current X position and add or subtract the player's camera's aspect ratio * orthographicSize to find the left and right screen bound. Afterwards, I do a simple if statement in the spawn to check if it's out of that left and right range or not.

With those new managers combined, the world is now populated with life!

And I said let there be plants and enemies!

Get Hunter's Requiem

Leave a comment

Log in with itch.io to leave a comment.