Example: Bubble Breaker Game
Product: CODESYS Visualization
This example shows how to program the "Bubble Breaker" game with CODESYS.
![]() |
Description
The goal of this game is to arrange large areas with bubbles of the same color. The more bubbles of the same color are in an area, the more points you get: 500 points is rather good, 1000 points is excellent.
At the beginning, the field is initialized and random color values are assigned to the bubbles. The high score is loaded from a file. When you click a bubble for the first time, the game calculates the possible points for removing the area around the bubble. A second click will remove all the bubbles in the area which have the same color. Only areas with more than one bubble are removed.
In the next step, the program checks if there are any areas remaining or if the game is over. When you finish the game and have reached a new high score, it is stored in a file.
Additional information
PLC_PRG
: The main program which initializes the game, controls the user actions, and checks if the game is over. The selected bubbles are stored and the possible points calculated.GenerateColor
: Randomly generates one of five colors.GameOver
: This program checks if there is an area with at least two bubbles of the same color. If not, then the game is over.Random
: Generates a random value which is used to generate a color for the bubbles.RemoveBubbles
: Based on the selected bubble, the area with bubbles of the same color is marked and the corresponding points are calculated. When the area consists of more than one bubble of the same color, all bubbles are removed when the selected bubble is clicked again. When gaps appear, they are filled with the remaining bubbles and empty rows are removed.Visu
: The visualization shows the game field with all bubbles. Clicking the New Game button initializes a new game in thePLC_PRG
program. The High Score shows the value from the high score file. Score displays the current score. Selection Points shows the possible points for the selected area. Depending on the score at the end of the game, one of three banners is displayed.
System requirements and restrictions
Programming system | CODESYS Development System (version 3.5.14.0 or higher) |
Runtime system | CODESYS Control Win (version 3.5.14.0) |
Add-on components | - |
Note
DOWNLOAD Project