Scores are an integral part of many games as they provide a measure of progress and achievement for players.

In Python, the Arcade library offers a simple and efficient way to manage scores in games. By effectively managing scores, you can enhance user engagement and provide a more immersive gaming experience.

Create a Simple Game

Before starting, make sure you have pip installed on your device. Use this command to install the arcade library:

 pip install arcade 

Now, create a simple game using Python's Arcade library.

The code used in this article is available in this GitHub repository and is free for you to use under the MIT license.

In this game, the player can move left and right using the arrow keys, while an obstacle is placed on the same y-axis.

 import arcade

# Set up window dimensions
SCREEN_WIDTH = 800
SCREEN_HEIGHT = 600

class MyGame(arcade.Window):
    def __init__(self, width, height):
        super().__init__(width, height)
        self.player_x = width // 3
        self.score = 0

    def on_key_press(self, key, modifiers):
        if key == arcade.key.LEFT:
            self.player_x -= 10
        elif key == arcade.key.RIGHT:
            self.player_x += 10

    def update(self, delta_time):
        # Update game logic here
        pass

    def on_draw(self):
        arcade.start_render()
        arcade.draw_circle_filled(self.player_x, 50, 20, arcade.color.BLUE)
        arcade.draw_rectangle_filled(400, 50, 100, 50, arcade.color.RED)

def main():
    game = MyGame(SCREEN_WIDTH, SCREEN_HEIGHT)
    arcade.run()

if __name__ == "__main__":
    main()

Score Tracking and Calculation

To track the score in your game, you can create a mechanism to increase the score whenever a specific condition is met. For example, the score increases whenever the player moves in your game and successfully touches the obstacle. You can change the update method to include score calculation logic:

 class MyGame(arcade.Window):
    def __init__(self, width, height):
        super().__init__(width, height)
        self.player_x = width // 3
        self.score = 0

    def on_key_press(self, key, modifiers):
        if key == arcade.key.LEFT:
            self.player_x -= 10
        elif key == arcade.key.RIGHT:
            self.player_x += 10

    def update(self, delta_time):
        if self.player_x > 330 and self.player_x < 470:
            self.score += 1

Displaying the Score

To display the score to the player, modify the on_draw method to include a text rendering:

 class MyGame(arcade.Window):
    # ...

    def on_draw(self):
        arcade.start_render()
        arcade.draw_circle_filled(self.player_x, 50, 20, arcade.color.BLUE)
        arcade.draw_rectangle_filled(400, 300, 100, 50, arcade.color.RED)

        score_text = f"Score: {self.score}"
        arcade.draw_text(score_text, 10, 10, arcade.color.WHITE, 14)

By adding the above code, you can display the score at the bottom left corner of the game window.

Storing the High Score

To provide a sense of achievement and competition for players, it's essential to store and display the high score. You can use a simple file-based approach for this.

Use the load_high_score method to read the high score from a file called high_score.txt and return it. After that, you can save the new high score to the file using the save_high_score method.

 class MyGame(arcade.Window):
    def __init__(self, width, height):
        super().__init__(width, height)
        self.player_x = width // 3
        self.score = 0
        self.high_score = self.load_high_score()

    def load_high_score(self):
        try:
            with open("high_score.txt", "r") as file:
                return int(file.read())
        except FileNotFoundError:
            return 0

    def save_high_score(self):
        with open("high_score.txt", "w") as file:
            file.write(str(self.high_score))

    def update(self, delta_time):
        # ...

        if self.score > self.high_score:
            self.high_score = self.score
            self.save_high_score()

Displaying High Score

Similar to displaying the current score, you can add a text rendering to display the high score:

 class MyGame(arcade.Window):
    # ...

    def on_draw(self):
        # ...

        high_score_text = f"High Score: {self.high_score}"
        arcade.draw_text(high_score_text, 10, 30, arcade.color.WHITE, 14)

By including the above code in the on_draw method, you can display the high score just above the current score.

A window titled "Arcade Window" contains a blue circle overlapping a red rectangle. A score and a high score are displayed in the bottom left corner.
Screenshot by Bobby Jack for MUO

Including Additional Features

Managing scores in games often involves incorporating additional features to make the gameplay more engaging and dynamic. Let's explore some examples of how you can introduce additional features alongside score management in your game.

Power-Ups

Power-ups are special items that grant players temporary advantages or bonus points. Create an activate_power_up method that triggers the activation of the power-up, setting the power_up_active flag to True.

You can schedule the deactivate_power_up method to run after a certain duration (e.g., 10 seconds) using the arcade.schedule function. During the power-up's active period, you can use the apply_power_up_effects method to implement specific gameplay enhancements.

Here's an example of implementing a power-up feature in your game.

 class MyGame(arcade.Window):
    def __init__(self, width, height):
        super().__init__(width, height)
        self.player_x = width // 3
        self.score = 0
        self.power_up_active = False

    def update(self, delta_time):
        if self.power_up_active:
            # Apply power-up effects during gameplay
            self.apply_power_up_effects()
            self.score += 10

    def apply_power_up_effects(self):
        # Add power-up specific logic here
        pass

    def activate_power_up(self):
        self.power_up_active = True
        # Set a timer or duration for the power-up effect
        arcade.schedule(self.deactivate_power_up, 10.0)

    def deactivate_power_up(self, delta_time):
        self.power_up_active = False

Combo System

A combo system rewards players for achieving consecutive successful actions or score multipliers. Create an increase_combo_counter method that increments the combo counter and increases the score based on the current combo level.

You can call the reset_combo_counter method and reset the combo counter back to zero whenever an unsuccessful action occurs. Here's a simple implementation of a combo system:

 class MyGame(arcade.Window):
    def __init__(self, width, height):
        super().__init__(width, height)
        self.player_x = width // 3
        self.score = 0
        self.combo_counter = 0

    def update(self, delta_time):
        # Check for successful actions
        if self.check_successful_action():
            self.increase_combo_counter()
        else:
            self.reset_combo_counter()

    def increase_combo_counter(self):
        self.combo_counter += 1
        self.score += self.combo_counter

    def reset_combo_counter(self):
        self.combo_counter = 0

By incorporating additional features such as power-ups and combo systems, you can add depth and excitement to your game, providing players with extra incentives to improve their performance, strategize their actions, and achieve higher scores.

Best Practices for Score Management

When it comes to managing scores in games, following best practices can help create a more enjoyable and engaging experience for players. Here are some key practices to consider:

Meaningful Scoring Mechanisms

Design scoring mechanisms that align with the game's objectives and provide meaningful feedback to players. The scoring system should reflect the player's progress, skill, and achievements within the game.

Consider assigning different point values to different actions or events based on their difficulty or importance to the gameplay.

Visual Feedback

Provide visual feedback to players when the score changes. You can achieve this through on-screen notifications, animations, or particle effects. Visual cues create a sense of accomplishment and reinforce the player's actions, increasing their engagement with the game.

Sound Effects and Animations

Incorporate sound effects in your game related to score updates to make the experience more immersive. For example, play a celebratory sound effect or display a burst of confetti when the player reaches a significant milestone. These audio-visual elements add excitement and reinforce the positive feedback loop for players.

Balancing Difficulty and Score Scaling

Ensure a balanced relationship between difficulty and score scaling. As players progress through the game or encounter more challenging obstacles, adjust the scoring system accordingly. Scaling the score based on the game's difficulty curve helps maintain a fair and rewarding experience for players.

By adhering to these best practices, you can effectively manage your game's scores, provide players with meaningful feedback, and create a rewarding and engaging experience.

Improve Game Engagement with Score Tracking

By implementing score tracking in your game, you can significantly enhance player engagement. Scores provide a sense of accomplishment, encourage replayability, and foster competition among players.

Display scores prominently and reward high achievements—you’ll motivate players to strive for better performance and improve their skills.