Enclosed | New Paddle & PowerUps | GAME DEVLOG #3


Enclosed | New Paddle & PowerUps | GAME DEVLOG #3


Hello!

Welcome to the fourth development log of "Enclosed"!

In this one I am excited to share the new paddle movement - I pretty much went on a new, different approach for implementing the paddle. Also, I will cover the new Power Up system & some basic power ups that were already implemented.

⏫ Basics of the power-up system ⏫

On the previous devlog we left off with the core mechanic of the game implemented: Ball-Paddle interaction. After that was done I set out on implementing a power up system to make the game-play more engaging. 

For the power ups, It was pretty obvious to me that I want power ups to spawn periodically inside the path, and if the ball collides with a power up then it is triggered & some kind of effect is applied: on the paddle, on the ball, on the path, etc...

All of the logic of the power up system is handled by a PowerUpManager object with a PowerUpManager scritpt, but first lets talk about the power ups themselves & the spawning of those power ups.

I made a PowerUp object with a PowerUp script & made a prefab out of it., and then made another. For now their sprite is just a colored circle to differentiate between two power ups:

The power up script follows these simple rules:
- Set a timer for x seconds. Destroy the object when the time is up.
- On collision with the ball, let the PowerUpManager know the type of power up to trigger & destroy the power up object.

The power up script uses a convenient "TimerCounter" script that I made in the past that counts time & triggers events, for example event on reaching timer target.

After making the prefabs, I needed a way to spawn them in the game. Fortunately for me (😎) I have made yet another useful script in the past  - "ObjSpawner" script that is just right for the job & which I can re-use !

Basically what this script does, it takes a list of game objects & instantiates a random one of those objects. I can control how fast the prefabs spawn & where. For example I can make the spawner spawn a power up every second inside an area that is visualized by the sprite of the spawner:


Later I made it so only 1 power up spawns and stays available for pickup for a few seconds. After the current power up de spawns or is taken by the player & its effect is over, only then the next one can spawn.

Now lets talk about the PowerUpManager:

The power up manager is a singleton that handles power up gains & losses. Whenever the ball collides with a power up, this manager knows about it & the PowerUpGained() function is triggered. By switching on predefined types, the correct PowerUp function is triggered. For now you can see I made ground work for two power ups: "DoublePaddle" & "LongerPaddle" which will later be renamed to "ParallelPaddles" & "DoublePaddleSize". The power up manager also uses the TimerCounter component to set a timer on 'y' seconds on power up gain. When this timer is up  then the PowerUpLost function is triggered. I implemented this structure because power ups will probably change a setting in the game & after 'y' time said setting should return to normal, for example 2x paddle length should return to normal length after 10 seconds.

This was the point at which I would like to start implementing the different power ups I had in mind... BUT, I got to thinking about the current paddle movement mechanic & I had a different approach I wanted to try first, before going through with the power ups because the new paddle implementation will effect how the power ups will do their thing.


🏓 New Paddle Movement 🏓

As I said, I got to having second thoughts about the current paddle system. For now, if I wanted to have the paddle follow exactly the path, even on corners, I would have to break it into multiple MoveOnPath objects as was see in devlog #1:

I wasn't happy with it. So then I remembered how easy it was to set up a line renderer to visualize my path, so I thought to myself, why not make the paddle be represented by a Vector2 List , like was doing all this time with the path system. But for the paddle the list will be much shorter & the points of the paddle will update with the points of the path itself! And for collision, well, I'll just use an edge collider again & update it along with the line renderer, the same way I did with the path visualization 😁

So I got to work,


first I defined a new script called "MovingLineOnPath" that will handle the points list & update them according to player inputs. On start it copies a part of the path points, depending on the _lenght of the paddle. Then after I get the points I just apply them to a line renderer & edge collider inside the UpdateLine() function.

This is the first iteration:

The first iteration of the new line paddle - visualized by the edge collider following a circle path

For the paddle movement:

The previous paddle movement was based on transform translation. With this approach this isn't an  option since this paddle is based of a list of points. To make it move depending on player inputs I just use the List.Add(),  List.Remove() & List.Insert() functions. I add a new point from the path to the paddle at the direction of movement & remove the last point from the paddle:


From there it wasn't too long until I reached the FINAL FORM of this new paddle. I made a new material with a new texture & this is the result which I am super happy about & proud of:


⭐Power Ups Implementation ⭐


After finishing with the new paddle I could return to implementing some power ups!

⭐ Double Paddle Size

Probably the first & most obvious power up that came to my mind. This power up will make the paddle grow & be 2x its length for a few seconds.

To implement it the power up system needs to have some kind of interaction with the paddle itself. For that a made a "Paddle" class which inherits from "MovingLineOnPath". The Paddle component will handle paddle manipulation to act on the power ups that effect the paddle. The PowerUpManager keeps a track of the Paddle objects in game.

For this power up:
- On power up gain - set paddle size to double.
- On power up loss - set paddle size to half.

Functions of the Paddle component that change the length of the paddle using SetLength implemented by MovingLineOnPath class


Double paddle size in action: Normal size on left, Double size on right

⭐ Parallel Paddle

The next power up I implemented is to spawn a second paddle, parallel to the original. Setting it up was pretty easy as well.

function on PowerUpManager component

- The PowerUpManager Instantiates a second Paddle prefab for 'z' seconds.


Function of Paddle component

- After Instantiating it, it calls a new function of the Paddle component to set this paddle parallel to a "source" paddle. The PowerUpManager keeps track of all paddles in game. Making the second paddle parallel to the first one is done by just setting its "start index" to be the "start index" of the source paddle + half the path points count.

start index - index of the first point in paddle line list, the index corresponds to an index on the path line list. For example a paddle can be represented by 5 points from the path. If the vector2 value of the point in index=0 in the paddle list equals [x0,y0] which is a point on the path list in index=17, Then the "start_index" of the paddle list is 17.

When activated, this is how it looks:


☕ Conclusion

This is it for this devlog, if you got this far then thank you very much for reading!

  • If any of you are interested in the "TimerCounter" or "ObjSpawner" component that I talked about in this devlog then feel free to leave a comment letting me know & I'll make sure to setup a github repo for you to get access for these neat scripts for F R E E! 💰💰
  • Do you have any suggestion for fun power ups that I should try to implement? Let me know in the comments! Actually any suggestion or idea for the project is welcome!
  • By the next devlog I hope to have some new cool power ups implemented & maybe I'll start working on some ART 🎨

Until next time,
Ken ♣



Leave a comment

Log in with itch.io to leave a comment.