-
Notifications
You must be signed in to change notification settings - Fork 9
Brick (Brick Breaker Minigame)
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.
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));
}
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
}
Escape Earth Game
Interaction Controller and Interactable Components
Game and Entity Configuration Files
Loading Game Configuration Files