[Leapy] Lilypad spawn system and changes in deleting off-screen lilypads


While making the lilypad spawn system i had to make some changes on how are the lilypads being deleted. 

I had the logic for deleting the lilypad in their script and now this responsability lies on the LevelManager.

This is how the Lilypad script looks like now:


The spawning system works as follows:

There are always 5 lilypads active and when one of those goes offscreen, it get's deleted and a new one is spawned.

In order to select a new lilypad to spawn, the LevelManager has an array of Lilypads to select. Which one gets selected is random, based on the probability of being selected that each lilypad has. Those rates are saved on another array that changed dynamically based on the current score of the player. The more score the player has, the rates of spawning the more hard lilypads increases.

I'll explain how the rates are calculated.

I have an array of spawn rates that starts like this:


And an array of values that is used to calculate how the rates change. These are not the final values, those will come from more testing.


Now, on the update method of LevelManager i check if the player score was modified and if it was then i calculate the new rates.


In order to calculate the rates, the array is changed from last element to first. First it set's the rate of the last element based on the current score and the percent modifier. Then, the rest of the elements gets their valued based on the current score, the percent modifier and the remaining total of percents (if the last element gets 11% the rest of the elements have to split 89%). The first element rate is calculated based on the remaining percent till that point.

This is how the code looks like.


And this is how the percent changes while playing. Each time the score changes, the rates also changes.


Now, on every Update, the LevelManager also check for lilypads out of the bottom of the screen and it check if it has to spawn new lilypads.




And it uses GetRandomLilypad to determine which lilypad to spawn.


I'll make an update with the new lilypads soon with a video of how is it working.

Get Leapy

Download NowName your own price

Leave a comment

Log in with itch.io to leave a comment.