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

Description

The Slider in the BrickBreaker Mini-game plays an important role as the ball is required to touch this particular entity to bounce back, preventing the ball from leaving the game area I.e. the game will end as soon as the ball goes beyond the Slider.

It plays the role of a surface (like the boundary of our game) that allows the ball to be reverted back to its task of destroying all the Bricks in the game.

Design of the Slider

Key Bindings for the Slider

D and -- Move Right A and -- Move Left

SliderFactory

Entity Creation

This defines a static method createSlider that creates a slider entity in the mini-game. It sets up various components for the slider, including input handling, rendering, physics, and hitbox. The entity is associated with an image in the assets folder with the path being "images/brick-game/Slider.png" and a designated layer. Finally, it's tagged as a "slider" and returned as the result of the method.

public static Entity createSlider() {
        InputComponent inputComponent =
                ServiceLocator.getInputService().getInputFactory().createForSlider();
        Entity slider =
                new Entity()
                        .addComponent(new TextureRenderComponent("images/brick-game/Slider.png"))
                        .addComponent(new PhysicsComponent())
                        .addComponent(new HitboxComponent().setLayer(PhysicsLayer.SLIDER))
                        .addComponent(inputComponent);
        slider.setEntityType("slider");
        return slider;
    }

Key components defining its behavior

  • TextureRenderComponent: Handles the rendering of the slider's visual representation.
  • PhysicsComponent: Provides the necessary physics properties to handle collision and placement.
  • HitboxComponent: Specifies the hitbox layer, ensuring collision detection.
  • inputComponent: Specifies the keys or the input required for the movement of the Slider.

SliderConfigs

Acceleration of the slider is determined in this .json file.

{
  "acceleration": 1,
  "spritePath": "images/brick-game/Slider.png"
}

Spawning Slider

This defines a method called spawnSlider that creates a new slider entity, places it in the mini-game area at a predefined location, adds it to a list of targetable entities, sets it as the active slider, and finally returns the newly created slider entity.

private Entity spawnSlider()
    {
        Entity newSlider = SliderFactory.createSlider();
        spawnEntityAt(newSlider, SLIDER_SPAWN, true, true);
        targetables.add(newSlider);
        slider = newSlider;
        return newSlider;
    }