Wiki

Clone wiki

Block Breaker / Home

Overview

Block Breaker is a Breakout clone written with the Swing 2D graphics API. Block Breaker also has a simple software synthesizer for sound effects.

I wrote this while learning some Java 9/10 features and IntelliJ IDEA.

blockbreaker_gameplay.png

The following shows the debug overlay, with stuff like hitboxes and marks showing the ball's previous collisions.

blockbreaker_debug.png

License

Block Breaker is released under an open-source MIT license.

MIT License

Copyright (c) 2018 David Staver

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Download

A jar is available here.

Notes

Aside from the regular gameplay controls (which are shown in-game), the following debug controls exist:

  • Ctrl + X toggles a cross overlay.

  • Ctrl + G toggles a grid overlay.

  • Ctrl + F toggles a frame counter overlay.

  • Ctrl + V toggles a velocity vector display for the ball.

  • Ctrl + T toggles an ability to throw the ball with the mouse (described below).

  • Ctrl + W toggles ball collisions with the bottom wall (instead of being lost).

  • Ctrl + C toggles marks that display where the ball has collided.

  • Ctrl + H toggles game object hit box displays.

If the program is run with the argument debug, then the game is started with all of the above-mentioned debug options enabled rather than disabled.

Throwing the ball with the mouse works like this:

  1. Press the left mouse button down to mark where the ball should start from.

  2. Drag to position the ball velocity vector.

  3. Release the left button to throw the ball.

If the game is in "launch mode", then the ball won't move from its fixed position above the paddle, but you can still click and drag to change its velocity vector.

The controls for this game were written using a KeyEventDispatcher, because I don't like the Swing key bindings API for games. The main reasons for this are as follows:

  • One of the main reasons to use the key bindings API in the first place is that it's well-integrated with the focus system, but we don't care about that for this kind of game.

  • The key bindings API makes assumptions about certain keys (such as TAB, which is generally used for focus traversal, or modifiers such as SHIFT and CTRL) which don't apply to games. For a game you generally want to be able to bind any key to any action, which the key bindings API does not do.

  • For a game, sometimes you actually want to be able to poll the control state on every frame, rather than use a command pattern.

Using a KeyEventDispatcher would be more complicated if it was necessary to have any sort of proper menu screen with Swing components like buttons and text boxes.

Interesting Files

The following files probably contain the most interesting code:

Updated