Skip to content

Commit

Permalink
Merge pull request #12 from magnetrwn/feature/implement_game
Browse files Browse the repository at this point in the history
General reformats and implementation of the main game mechanics.
  • Loading branch information
magnetrwn authored Jun 25, 2024
2 parents 00299e8 + 2a9f198 commit aa7e239
Show file tree
Hide file tree
Showing 39 changed files with 1,661 additions and 637 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/doxygen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
run: sudo apt-get install doxygen

- name: Generate Documentation
run: ./make_docs.sh
run: scripts/make_docs.sh

- name: Deploy to GitHub Pages
uses: peaceiris/actions-gh-pages@v3
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ dist
.doxygen
lib/inipp/
docs/doxygen-awesome-css/
.vscode
51 changes: 2 additions & 49 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,50 +1,3 @@
# Contributing to Raylib Bubbles
# Raylib Bubbles: Contributing

Feel free to contribute to the project if you have insights, improvements, bug fixes, or anything else!

### Creating an Issue

If you find inconsistencies, bugs, or other problems, consider creating an issue describing the problem.

**Note:** for comments, please use the *Discussions* tab instead!

### Gitflow Overview

We use the **Gitflow Workflow** for managing branches and pull requests. The main branches are:

+ **Main Branch:** Our production-ready state.
+ **Develop Branch:** Our primary development branch. All features are merged here before being released to the main branch.
+ **Feature Branches:** Branch off from `develop` when working on new features.

### Opening a Pull Request

+ *Fork* the repo.
+ *Clone* the forked repo to your local machine.
+ Checkout the `develop` branch: `git checkout develop`.
+ Update your local `develop` branch: `git pull origin develop`.
+ Create a new branch for your feature change: `git checkout -b feature/your_feature_name`. You can change `feature` to `refactor`, `bugfix` or `docsfix`, whichever fits best.
+ Make your changes and *commit* them: `git commit -m 'Added new feature'`.
+ *Push* the changes to your fork: `git push origin feature/your_feature_name`.
+ Create a *pull request* targeting the `develop` branch on the main repo.

### Code Style

| Rule | Description |
| ---- | ----------- |
| Brace Style | Use **K&R brace placement** for functions, classes, and control statements. |
| Indentations | Use **4 spaces** for indentation. Drop long initializer lists at one indent. |
| Declarations | Follow **Google C++ Style**, use separate lines. |
| Access Modifiers | Follow **Google C++ Style**, use separate lines. |
| Naming Conventions | Use **`camelCase`** for variables and methods, and **`PascalCase`** for class names. |
| New Files | Use **LF line endings**, keep exactly one newline at the end of each file, use extensions `.hpp`, `.cpp` |
| Commenting | Use **Doxygen** as code comments and in `docs/` in its corresponding documentation. |

### Non-Code Contributions

If you want to contribute backgrounds, sprites, audio or other assets, please **create an issue** to discuss the contribution! You are very welcome to contribute, but please make sure that the assets are **licensed under the MIT License** or a compatible license. If you are contributing assets you have created, please include a **`LICENSE`** file in the asset folder, stating you are the creator and that the assets are licensed under the MIT License or compatible.

### Testing and Reporting Bugs

If you find a bug, please **create an issue** describing the problem and how to reproduce it. If you have a fix, please **open a pull request**. As of now, testing is not enforced.

**Thank you!**
**Note:** Refer to [Raylib Bubbles Documentation: Contributing](https://magnetrwn.github.io/raylib-bubbles/contributing.html).
3 changes: 1 addition & 2 deletions Doxyfile
Original file line number Diff line number Diff line change
Expand Up @@ -1025,7 +1025,6 @@ FILE_PATTERNS = *.c \
*.markdown \
*.md \
*.mm \
*.mp4 \
*.dox \
*.py \
*.pyw \
Expand Down Expand Up @@ -1087,7 +1086,7 @@ EXCLUDE_SYMBOLS =
# that contain example code fragments that are included (see the \include
# command).

EXAMPLE_PATH =
EXAMPLE_PATH = static/bubbles.ini docs/early_demo.mp4

# If the value of the EXAMPLE_PATH tag contains directories, you can use the
# EXAMPLE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp and
Expand Down
24 changes: 7 additions & 17 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,21 +1,11 @@
MIT License
Copyright 2024 magnetrwn

Copyright (c) 2024 magnetrwn
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

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:
1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

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.
3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
118 changes: 2 additions & 116 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,117 +1,3 @@
**Note:** This README.md (as all other Markdown in the root) is outdated. Please check [GitHub Pages](https://magnetrwn.github.io/raylib-bubbles/) for the latest documentation.
# Raylib Bubbles: Introduction

# Raylib Bubbles

[![CodeFactor](https://www.codefactor.io/repository/github/magnetrwn/raylib-bubbles/badge)](https://www.codefactor.io/repository/github/magnetrwn/raylib-bubbles) [![DeepSource](https://app.deepsource.com/gh/magnetrwn/raylib-bubbles.svg/?label=active+issues&show_trend=true&token=k0LxdMtn2JdcCFcNwl_0DyZp)](https://app.deepsource.com/gh/magnetrwn/raylib-bubbles/) [![DeepSource](https://app.deepsource.com/gh/magnetrwn/raylib-bubbles.svg/?label=resolved+issues&show_trend=true&token=k0LxdMtn2JdcCFcNwl_0DyZp)](https://app.deepsource.com/gh/magnetrwn/raylib-bubbles/) [![Hits](https://hits.seeyoufarm.com/api/count/incr/badge.svg?url=https%3A%2F%2Fgithub.com%2Fmagnetrwn%2Fraylib-bubbles&count_bg=%239757D0&title_bg=%23555555&icon=&icon_color=%23E7E7E7&title=hits&edge_flat=false)](https://hits.seeyoufarm.com)

![Early Demo GIF](docs/early_demo.gif)

## Description

**Raylib Bubbles** is a compact puzzle game following the classic bubble shooter game concept. It relies on the [Raylib](https://www.raylib.com/) library for rendering and input handling.

The game is written in C++11 and is built with CMake. It is intended to be a **well structured example of a game written with Raylib**.

### Quick Start

+ [Installation](#installation)
+ [Overview](#overview)
+ [Build Details](#build-details)
+ [Contributing](#contributing)
+ [Technical Summary](#technical-summary)

### Installation

To get started, follow these steps:

+ Clone the repository with `git clone https://github.com/magnetrwn/raylib-bubbles.git`.
+ Install Raylib, which can be done on Debian by running `sudo apt install raylib`.
+ Build with `./build.sh`, and check the `build` directory for the built executable, or the zipped bundle `dist/bubbles_build[timestamp].zip`.
+ Run `./bubbles` to start the game.

For instructions on how to play, see the [instructions file](build/INSTRUCTIONS.md) in the build folder.

### Overview

The game is structured in a way that allows for easy modification and extension.

The following libraries are used in the project:

+ **[Raylib](https://www.raylib.com/)**: Graphics and input, linked statically.
+ **[inipp.h](https://github.com/mcmtroffaes/inipp)**: Configuration file parsing (header-only), Git submodule.
+ **[doxygen-awesome-css](https://github.com/jothepro/doxygen-awesome-css)**: Doxygen CSS theme, Git submodule.

To summarize the structure of the project, here is a short description of each header file, in alphabetical order:

| Include Header | Description |
| -------------- | ----------- |
| **`src/animation/action.hpp`** | Acts as a list for animations to be applied concurrently and detached to the game state, while keeping track of their action state and referencing the board. |
| **`src/animation/lissajous.hpp`** | Provides state object for Lissajous curves. |
| **`src/game/board.hpp`** | Provides a way to build an hexagonal grid of bubbles and to manipulate it through a straightforward API. |
| **`src/game/game.hpp`** | **TODO** |
| **`src/raylib/window.hpp`** | Manages the window and contains the Raylib game loop. **This is the only header that interacts with Raylib, all others are independent and repurposable.** |
| **`src/utility/util.hpp`** | Contains static utilities. |

An extended description of each building block of the game can be found in the [Technical Summary](#technical-summary) section.

### Build Details

The `static` folder contains all files to bundle with the compiled executable. After running `./build.sh`, which will run `cmake` among things, the executable will be placed alongside resources and files to include with it:

+ `res/`: Contains the fonts and textures used in the game.
+ `bubbles`: The compiled executable.
+ `bubbles.ini`: The configuration file for the game.
+ `INSTRUCTIONS.md`: A file containing instructions on how to play the game.
+ `LICENSE`: The license file for the game, same as the project license.

As mentioned earlier, there will also be a zipped build generated in the `dist` project directory, with the name `bubbles_build[timestamp].zip`. It contains all necessary files to run the game.

**Note:** The build resources such as fonts and textures may fall under a different license, please check the related folders for license information.

## Contributing

Please make sure to **read the [CONTRIBUTING.md](CONTRIBUTING.md) file** for relevant information on how to contribute to the project.

When contributing, adhere to the code style and Gitflow branching guidelines outlined in the file.

If you wish to discuss contributions or talk about the project in a more detached manner, please use the *Discussions* tab.

## Technical Summary

The project is written in C++11 and, while it uses Raylib for rendering graphics, the API has not been mixed in an inseparable manner with the game logic. You will find **all uses of Raylib are located in the `GameWindow` class**, in `src/raylib/window.hpp`. It is purposefully not difficult to replace Raylib with another library, or to use the game logic in a different context.

### [Board](src/game/board.hpp)

The `GameBoard` class in `src/game/board.hpp` provides an interface to conveniently access elements of an hexagonal grid through offset coordinates, as in a rectangular grid with a slight right shift on each odd row.

Specifically, the class first allocates a 1D array of `Bubble` objects, which are accessed by internally calculating offsets to the required element.

As in bubble shooter games usually are, when a board with an even number of columns is generated, each odd row will have one less `Bubble` than the even rows. This is internally accounted for, and optimal space allocation and cache locality should be possible.

On changing the state of some cell on the board, the `GameBoard` class will automatically update the number of neighbors of the bubble cell with non-empty bubble color.

Neighbor counting allows efficient popping of bubbles, since the game only checks if a launched bubble that just attached to the board has made the number of neighbors of a bubble reach the minimum for a possible pop, if the color is matching.

### [Bubble](src/game/board.hpp)

Available as a public member of `GameBoard`, the `BubbleCell` class is a simple container for bubble color (including empty space) and tracking the number of neighbors with non-empty bubble color. It provides operators to generate self-documenting code, but should not be used outside of the `GameBoard` abstraction.

This is different from the `BubbleData` struct in `src/animation/action.hpp`, which is used to keep status for animating bubbles and is not part of the board abstraction.

### [Action](src/animation/action.hpp)

An action is something that takes place on the window with bubbles, but is not snapped to the board grid. This is essential to allow effects and animations to be displayed.

The `GameActionMgr` class in `src/animation/action.hpp` handles a list of actions, which are applied concurrently. Each action has a state, and the queue is abstracted to be processed in the game loop transparently. The state of each action is stepped on every cycle, and eventually *pruned* when the action has left the visible screen area, or `pruneFlag` is raised. The action is removed from the queue when it is done.

More specifically, the queue is made up of `ActionType` objects, which identify each action through an enum class, while keeping track of their parent manager and allowing to check their state, as well as their board location.

There is also a basic container struct `BubbleData`, which holds the state (coordinates, speed and hue) of a bubble during the animation.

**Note:** The `GameActionMgr` uses a `std::forward_list` to keep track of actions instead of a `std::vector`, because the game loop will cause the manager to iterate over the list and occasionally prune actions. Also, it makes it straightforward by using `std::forward_list::remove_if` with a lambda.

### [Lissajous](src/animation/lissajous.hpp)

The `LissajousView` class in `src/animation/lissajous.hpp` is a simple class abstracting the state of a Lissajous curve, which is used to animate the background texture along the viewport (the visible screen area). This is why backgrounds are larger than the viewport. The Lissajous curve is defined by the parameters encapsulated in the `LissajousInit` struct, which is used to initialize the curve.

**TODO**
**Note:** Refer to [Raylib Bubbles Documentation: Introduction](https://magnetrwn.github.io/raylib-bubbles/index.html).
2 changes: 1 addition & 1 deletion docs/contributing.dox
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ We use the **Gitflow Workflow** for managing branches and pull requests. The mai
<br>
\section other-contrib Non-Code Contributions

If you want to contribute backgrounds, sprites, audio or other assets, please **create an issue** to discuss the contribution! You are very welcome to contribute, but please make sure that the assets are **licensed under the MIT License** or a compatible license. If you are contributing assets you have created, please include a `LICENSE` file in the asset folder, stating you are the creator and that the assets are licensed under the MIT License or compatible.
If you want to contribute backgrounds, sprites, audio or other assets, please **create an issue** to discuss the contribution! You are very welcome to contribute, but please make sure that the assets are **licensed under a compatible license**. If you are contributing assets you have created, please include a `LICENSE` file in the asset folder, stating you are the creator and that the assets are licensed under the MIT License or compatible.

<br>
\section testing-reporting Testing and Reporting Bugs
Expand Down
Binary file removed docs/early_demo.gif
Binary file not shown.
Binary file modified docs/early_demo.mp4
Binary file not shown.
Loading

0 comments on commit aa7e239

Please sign in to comment.