Ball (Brick Breaker Minigame) - UQcsse3200/2023-studio-2 GitHub Wiki

Description

The Ball is the core entity of this game as it bounces of the surface and the slider to destroy the bricks and one all the bricks are destroyed using the ball the game ends.

Once you press , the game will start and the ball will be off the slider.

Design of the ball

BallFactory

Entity Creation

This function, createMinigameBall, is designed to create and return a ball entity for the mini-game. Here's a short breakdown of its functionality:

  1. Retrieve an InputComponent specific to a ball from the input service.
  2. Create a new Entity object called ball.
  3. Add three components to the ball entity:
    • A TextureRenderComponent to render the ball using an image found at "images/minigame/Ball.png".
    • The inputComponent retrieved earlier to handle ball-specific input.
    • A PhysicsComponent to handle the ball's physics behavior.
  4. Set the entity type of the ball to "ball".
  5. Return the configured ball entity.

In essence, the function creates the ball entity with input and physics behavior for brick breaker mini-game.

 public static Entity createMinigameBall() {
        InputComponent inputComponent =
                ServiceLocator.getInputService().getInputFactory().createForBall();

        Entity ball =
                new Entity()
                        .addComponent(new TextureRenderComponent("images/minigame/Ball.png"))
                        .addComponent(inputComponent)
                        .addComponent(new PhysicsComponent());

        ball.setEntityType("ball");
        return ball;
}

Key components defining its behavior

  • TextureRenderComponent: Handles the rendering of the ball's visual representation.
  • PhysicsComponent: Provides the necessary physics properties to handle collision and placement.
  • inputComponent: Specifies the keys or the input required for the movement of the ball.

Spawning Ball

This spawnBall function carries out the following tasks:

  1. Create a New Ball Entity: It utilizes the BallFactory.createMinigameBall() method to create a new ball entity, which is then assigned to the newBall variable.

  2. Positioning the Ball: The function then positions or spawns this newBall entity at a specified location or configuration given by BALL_SPAWN. The spawnEntityAt method takes in four arguments:

    • The entity to spawn (newBall in this case).
    • The location/configuration (BALL_SPAWN).
    • Two boolean values (in this case, true for both), which probably control some attributes or behaviors of the spawning process. Without additional context, it's hard to say what these two booleans exactly represent.
  3. Add to Targetables: The newBall entity is added to a list (or similar collection) named targetables. This suggests that the ball might be a target for some gameplay mechanics, but without more context, this is just an assumption.

  4. Assign to Instance Variable: The newBall entity is then assigned to the instance variable ball. This implies that this class likely keeps track of a singular active or current ball, which now becomes the newBall.

  5. Return the New Ball: Finally, the newBall entity is returned by the function, potentially allowing other parts of the program to interact with or reference it immediately after it's spawned.

In summary, spawnBall creates a new ball entity, places it in the mini-game, adds it to a list of targetable entities, and updates the class's current ball reference to this new ball.

  private Entity spawnBall()
    {
        Entity newBall = BallFactory.createMinigameBall();
        spawnEntityAt(newBall, BALL_SPAWN, true, true);
        targetables.add(newBall);
        ball = newBall;
        return newBall;
    }