Minigame Monday: Keeping On

 Keeping On:

  • The concept:

This was a minigame that evolved quite a lot as I made it. I started with the idea of some sort of autoscrolling survival game, where the terrain for the player moved from right to left and the player's goal was simply to live as long as possible. The details of how this were going to work I wasn't sure about however, and so I started with my main goal, getting randomly generated terrain to scroll towards the player and doing so in a configurable way.

  • The challenge:

 Drawing the road was an interesting challenge; I've previously done similar random generation based on applying a random change to the current height, but doing that here efficiently is something that would take a bit more thinking. Doing this on a pixel by pixel level would obviously involve a lot of storage (one variable for every pixel in the width of the screen), so I wanted to do this more efficiently. I also had the scrolling aspect to consider.

To solve this, I had a list of locations to store points, and I drew a polygon involving all of these points to create the path for the player. This way I was only storing a list of points, rather than a list of y values for all x values. Splitting this into two parts, first was the part controlling the scroll:

for i in range(0, len(self.roadPoses)):
    if (self.roadPoses[i][0] == ROADRIGHTX):
        newLocation = True
    self.roadPoses[i] = (self.roadPoses[i][0] - self.speed, self.roadPoses[i][1])
    self.roadBotPoses[i] = (self.roadBotPoses[i][0] - self.speed, self.roadBotPoses[i][1])
    if i < len(self.roadPoses) - 1:
        if (self.roadPoses[i + 1][0] < 0):
            #Make sure the next position is off screen before removing
            toRemove.append(i)

Because of working with position tuples this can get a bit messy, so I'll talk you through it. This loops through the list of locations, subtracting self.speed from the x co-ordinate of each, thus moving them to the left. There are two other things happening: first, if we're moving a co-ordinate away from the right edge of the screen, we need a new location to replace it. Upon review, this isn't strictly needed, as we will always be moving a point from the right with this implementation, but it shows how I was thinking when writing the code. The other thing happening is flagging positions to be removed, if the position after them has been scrolled off the edge of the screen and so they can safely be removed. 

The second part was generating the new points randomly. This was pretty straight forward; I'd add a new point, varying from the point before it based on a random number, and with an X co-ordinate on the edge of the screen. This did actually lead to a stretching effect if the Y co-ord didn't vary too much which could be fixed by spawning the points infront over the edge of the screen, not on it, but I actually rather liked how the effect looked so I kept it.

The other major challenge was less of a coding one; instead it was balencing the gameplay for a gentle increase in difficulty. Facilitating this however did involve a little code, in particular exposing as many variables for the generation of the path as I needed to be varied as the player continued playing. These parameters could then be changed as the game continued. The ones I used were the speed of the road, the width of the road, and how likely the road was to move up or down.

  • The result:

 

 I'm not the happiest with the code for this minigame actually; there's plenty that could use neatening up, potentially with helper functions or better naming conventions (but if you want to look at it, it's available on my github). The gameplay however, I do like; it plays smoothly and it's fun seeing how far you can get. You can try it for youself at https://reddragonmakesgames.itch.io/keeping-on.

Comments

Popular posts from this blog

Armageddump (Boss Rush Jam 2023)

Introducing: Minigame Monday! (3D Minesweeper)

Minigame Monday: Covert Behaviour