Open_Pong: Powerups
Written on August 4th, 2021 by AsianMario
Spawning Powerups
During the past few days I have been working on the particle systems making sure everything works as they should. After some more polishing and fixes I decided to move onto the powerups. Technically, powerups were just like any GameObject in the game but with a randomized spawn and can affect other GameObjects. I created the PowerupSpawner class that would be in-charge of spawning the objects and would have functions that would make creating, deleting and updating powerups easier. The class also consisted of a string array which had all the powerups available to choose from. There is also a max spawn integer variable that would limit the spawn rate and spawn amount of the powerups. Along with this, a active spawn variable is made to track how many powerups are spawned. To randomly spawn any powerup I would make a variable called currentPowerup
that would choose a random index according to the index of the array. For example, if I had an array with the length of 3 I would define currentPowerup
as rand() % 3
. This would randomly choose a number between 0 to 2 which matches the length of the array (initialize srand() to actually get random results). The update function of the class would call a specified powerup spawn according to currentPowerup
’s value as long that the current number of powerups are equal or less than the maxSpawn
amount. The class also has its own CPP vector which would store all the powerups in a list, they would be added to the vector when they are called to be spawned. Finally, there’s the delete function that would set the powerup as a nullpointer in the vector, reduce the active powerup amount and choose another random powerup to spawn. The reason why I dont delete the GameObject is due to the fact that the powerup calls both the PowerupSpawner
delete and Game
’s delete. Since Game
already deletes the GameObject, I cant delete it twice. So instead the PowerupSpawner
delete sets its position in the vector to a nullpointer instead.
Implementing The Powerup
Next up, I made a powerup that would increases the ball’s radius and scale when the ball hits the powerup. I plan to add more visual effects, camera effects and more but currently I’ve just implemented the basics for testing. The BallPlus
powerup would have is own spawn inside the update function which is essentially simialr to Game
’s spawn function but due to it needing special values I just made it its process in the update function. On hit, the update would call the delayEffect()
function which would reset the values of the ball to its original value after a few seconds (in this case, BallPlus has an effect time of 5 seconds). After it resets all the values it calls the Game
& PowerupSpawner
delete to destroy the object and set it as a nullpointer in all of the vectors its stored in
Since the powerup system is going to have a variety of powerups and I’m still working on fixing a few bugs and issues this feature will take a while to complete. Along with this, a texture revamp is currently in progress to prepare for the next set of features which will be visual effects and camera effects.