Skip to content

Brick (Brick Breaker Minigame)

Anshul Dadhwal edited this page Oct 5, 2023 · 2 revisions

Description

The Bricks here are used as a block which when comes in contact with the ball, it disappears.

The final condition for the game to finish is when you destroy all these bricks using the ball in the Brick Breaker Mini-game.

Design of the Brick (will be updated)

CameraBasic

Methods used for spawning the Bricks

Method to spawn all bricks together

The spawnBrickLayout method spawns a vertical column of six static bricks on a 2D grid. Each brick has a size of 20. They are positioned at the x-coordinate 5, with y-coordinates ranging from 10 to 15, indicating a stacked layout. The spawnStaticBrickRight method is responsible for placing each brick at its specified position.

private void spawnBrickLayout(){
        spawnStaticBrickRight(20,new GridPoint2(5,10));
        spawnStaticBrickRight(20,new GridPoint2(5,11));
        spawnStaticBrickRight(20,new GridPoint2(5,12));
        spawnStaticBrickRight(20,new GridPoint2(5,13));
        spawnStaticBrickRight(20,new GridPoint2(5,14));
        spawnStaticBrickRight(20,new GridPoint2(5,15));

    }
Screenshot 2023-10-05 at 10 06 55 AM

spawnStaticBrickRight(int n, GridPoint2 pos) Code

This method defines a recursive function spawnStaticBrickRight that spawns static brick entities to the right of a specified position. It takes the number of entities to spawn (n) and the starting position (pos). The function creates a static brick entity and spawns it at the current position. It then increments the X-coordinate of the position to move it to the right. This process continues recursively until n reaches 0, at which point the recursion stops.

private void spawnStaticBrickRight(int n, GridPoint2 pos){
        Entity asteroid_length = ObstacleFactory.createStaticBrick(1f,1f);
        if (n <= 0) {
            return;
        }
        spawnEntityAt(asteroid_length, pos, false, false);
        // Increment the position for the next asteroid
        pos.x += 1;
        pos.y += 0;
        spawnStaticBrickRight(n - 1, pos); // Recursive call
    }
Clone this wiki locally