Minigame Monday: Round And Round

 Round And Round:

  • The concept:

Another shorter minigame this time, as I'm working on another game jam game, expect to see that in a couple of weeks. I felt like making a racing game in python for this one. As I was making the game, I thought it would be cool if the player could draw their own maps. 

  • The challenge:

The first challenge I faced was getting movement for the car that felt responsive and fun to play. Getting the car moving wasn't too difficult; just a matter of adding functions to the arrow keys to control the car. For the left and right arrows, this would change a rotation value stored in the car class. I used a momentum variable to store the movment of the car; as it turned out, this didn't end up being too different from its speed in the rotation direction, but theoretically you could make these values differ to allow the car to drift or spin out of control. For accelerating and breaking, I used some basic trigonometry to properly effect the momentum in the direction of the rotation. It took a bit of tweaking the values till I found movement I was happy with, but after making sure the cornering happened at a reasonable speed I was ready to move on to the walls. 

Making the walls was actually an interesting problem. I decided to use the trick I'd used in previous games and use the colour of walls to detect where they were. That still left the main problem however, of how I would store the positions of the walls so they could be drawn every loop. I was a bit worried about how to do this in a way that would feel sensible and easy for the player to use, but I'm very happy with the solution I found. I made two lists, one called barriers and one called lines. Barriers contained a list of all the points where the player had clicked. Lines contained a list of whether a line should be drawn between each pair of points. Here's how the lists were made:

if event.button == 1:
    #Left click, add to wall points
    self.barriers.append(pos)
    if self.isDrawing:
        self.lines.append(True)
    else:
        self.lines.append(False)
        self.isDrawing = True
elif event.button == 3:
    #Right click
    self.isDrawing = False

And here's how they were shown:

#Draw walls
if len(self.barriers) > 1:
    for i in range(0, len(self.barriers) - 1):
        if (self.lines[i + 1] == True):
            pygame.draw.line(self.screen, WALLCOLOUR,  
                        self.barriers[i], self.barriers[i + 1], WALLTHICKNESS)
if (self.isDrawing):
    pos = pygame.mouse.get_pos()
    pygame.draw.line(self.screen, WALLCOLOUR
                     self.barriers[len(self.barriers) - 1], pos, WALLTHICKNESS)

Using the list of flags, I could decide which pairs of points should have lines drawn between them, and which shouldn't. I could even use a line drawn from the last point to the mouse to show the player if and where they're drawing a line.

  • The result:


 Although this was a quick game, I think it turned out pretty well. Trying to get the fastest lap is pretty fun, and being able to draw the courses yourself makes it very replayable for a minigame. Try it for yourself at https://reddragonmakesgames.itch.io/round-and-round, and the code is available on my github.

Comments

Popular posts from this blog

Armageddump (Boss Rush Jam 2023)

Imperfect Control: Gameplay

Hair of the Wolf (GameOff 2022)