Skip to content

Breakout is a classic arcade game from the 1970s, still cherished today. Players control a horizontal paddle, aiming to break a wall of colorful bricks above. They use a bouncing ball to hit the bricks and earn points. The game tests hand-eye coordination and reflexes, with increasing difficulty as players progress.

Notifications You must be signed in to change notification settings

NimraBasit7/Breakout_Game

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 

Repository files navigation

This code represents a simple Breakout game implemented using JavaFX. Breakout is a classic arcade game where the player controls a paddle to bounce a ball and break a wall of bricks. Let's break down the code and explain each part:

  1. Importing JavaFX and Java utilities:
  2. Defining the Group_Breakout class that extends Application:
  3. public class Group_Breakout extends Application {
  4. Overriding the start method which serves as the entry point for the application: public void start(Stage PrimaryStage) {
  5. Creating the main menu scene with buttons and title: // Creating pane for the main menu Pane main_menu = new Pane(); main_menu.setStyle("-fx-background-color:NAVAJOWHITE"); main_menu.setPrefSize(610, 400); // Game Title stored in text Text title = new Text("Breakout Game\nWELCOME!"); // Other properties like position, font, and color are set here // Creating buttons Button strt = new Button("Start Game"); // Other properties like position, font, and color are set here Button ex = new Button("Exit Game "); // Other properties like position, font, and color are set here // Adding the title and buttons to the main menu pane main_menu.getChildren().addAll(strt, ex, title); // Creating the scene for the main menu Scene display = new Scene(main_menu); // Creating a secondary stage for the main menu Stage second = new Stage(); second.setTitle("Main Menu"); second.setScene(display);second.show();
  6. Handling the "Start Game" button action to set up the game scene and mechanics: strt.setOnAction(e -> { // Creating pane for the main layout of the game Pane align = new Pane(); align.setStyle("-fx-background-color: BISQUE"); align.setPrefSize(610, 400); // Creating bricks and adding them to the align // … // Creating the ball and adding animation // ... // Creating the rectangular paddle // ... // Adding the ball, paddle, and text to the scene // … // Creating the infinite bouncing of the ball using Timeline // … // Controlling the movement of the paddle using KeyFrame and setOnKeyPressed // … PrimaryStage.setTitle("Breakout! (My First Game) "); PrimaryStage.setScene(scn); PrimaryStage.show(); PrimaryStage.setResizable(false); });
  7. Handling the "Exit Game" button action to close the application. ex.setOnAction(e -> System.exit(0) });
  8. The main method, which is the entry point for Java applications. public static void main(String[] args) { launch(args); } This code sets up a basic Breakout game where the player can start the game from the main menu, control the paddle using the left and right arrow keys, and break bricks with the ball. The game has basic collision detection and scoring mechanics. If all bricks are broken, a "YOU WON!" message is displayed, and if the player runs out of lives, a "GAME OVER :(" message is shown.

About

Breakout is a classic arcade game from the 1970s, still cherished today. Players control a horizontal paddle, aiming to break a wall of colorful bricks above. They use a bouncing ball to hit the bricks and earn points. The game tests hand-eye coordination and reflexes, with increasing difficulty as players progress.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages