Skip to content

Commit

Permalink
Merge pull request #35 from X-R-G-B/doc/RB-64-Raylib-encapsulation
Browse files Browse the repository at this point in the history
DOCUMENTATION: Add raylib wrapper documentation
  • Loading branch information
Saverio976 authored Oct 2, 2023
2 parents 12f62df + db7471c commit b8d5e2a
Show file tree
Hide file tree
Showing 25 changed files with 588 additions and 0 deletions.
29 changes: 29 additions & 0 deletions docs/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,35 @@
- [Server](developer-guide/server/README.md)

- [Client](developer-guide/client/README.md)
- [Audio](developer-guide/client/audio/README.md)
- [Audio settings](developer-guide/client/audio/audioSettings.md)
- [Audio file formats](developer-guide/client/audio/fileFormats.md)
- [Music](developer-guide/client/audio/music.md)
- [Sounds](developer-guide/client/audio/sounds.md)

- [Events]()
- [keyboard](developer-guide/client/events/keyboard.md)
- [Mouse](developer-guide/client/events/mouse.md)

- [Geometry]()
- [Color](developer-guide/client/geometry/color.md)
- [Rectangle](developer-guide/client/geometry/rectangle.md)
- [Vector2](developer-guide/client/geometry/vector2.md)
- [Vector3](developer-guide/client/geometry/vector3.md)
- [Vector4](developer-guide/client/geometry/vector4.md)

- [Graphic]()
- [Colors pixels](developer-guide/client/graphic/colorsPixels.md)
- [Config flags](developer-guide/client/graphic/configFlags.md)
- [Cursor](developer-guide/client/graphic/cursor.md)
- [Drawing](developer-guide/client/graphic/drawing.md)
- [Frame rate](developer-guide/client/graphic/frameRate.md)
- [Image](developer-guide/client/graphic/image.md)
- [Misc](developer-guide/client/graphic/misc.md)
- [Shapes](developer-guide/client/graphic/shapes.md)
- [Sprite](developer-guide/client/graphic/sprite.md)
- [Text](developer-guide/client/graphic/text.md)
- [Window](developer-guide/client/graphic/window.md)

-----------

Expand Down
11 changes: 11 additions & 0 deletions docs/developer-guide/client/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# C++ Client Documentation

## Table of Contents
- [Introduction](#introduction)
- [Raylib Library](#raylib-library)

## Introduction
The C++ client is a simple game client that uses the Raylib library to handle graphics and audio. The client is designed to be simple and easy to use, but it is also very flexible and can be used to create more complex games.

## Raylib Library
We use the Raylib library to handle our graphics and audio. Raylib is a simple and easy-to-use library that provides a wide range of features. The Raylib library is written in C, but we have wrapped it in C++ classes to make it easier to use.
33 changes: 33 additions & 0 deletions docs/developer-guide/client/audio/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# Using Audio in our game client

In your C++ client application, you can manage audio using the Raylib library. This guide explains how to work with sounds and music using our Raylib wrapper classes. Before looking at the other pages, we advise you to look at the rest of this page. Initialize the audio correctly is essential to use it in our client.

## Audio Device Management

### Functions

```cpp
void Raylib::initAudioDevice();
void Raylib::closeAudioDevice();
bool Raylib::isAudioDeviceReady();
void Raylib::setMasterVolume(float volume);
```
## Example usage
You need to initialize the audio device before using any audio functions. You can do this by calling the initAudioDevice() function. You can then use the other functions to manage the audio device. If you want to player music, every frame you need to call the UpdateMusicStream() function.
```cpp
int main() {
Raylib::Music music("path/to/musicfile.ogg");
Raylib::initAudioDevice();
// game loop
while (!Raylib::WindowShouldClose()) {
// stuff
//for every music
Raylib::UpdateMusicStream(music);
}
Raylib::closeAudioDevice();
}
```
5 changes: 5 additions & 0 deletions docs/developer-guide/client/audio/audioSettings.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
## Volume, pitch, and pan

- The pitch base level is 1.0f (normal pitch).
- The volume base level is 1.0f (maximum volume).
- The pan base level is 0.5f (center).
11 changes: 11 additions & 0 deletions docs/developer-guide/client/audio/fileFormats.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
## Audio File Formats

Raylib supports the following audio file formats:

- WAV
- OGG
- MP3
- XM
- QOA
- MOD
- FLAC
38 changes: 38 additions & 0 deletions docs/developer-guide/client/audio/music.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
## Music Class

### Constructors

```cpp
Raylib::Music(const std::string& fileName, float volume = 0.5f);
```
Create a music object from the specified audio file.
### Methods
```cpp
void Raylib::Music::unload();
bool Raylib::Music::isReady() const;
void Raylib::Music::play() const;
bool Raylib::Music::isPlaying() const;
void Raylib::Music::update() const;
void Raylib::Music::stop() const;
void Raylib::Music::pause() const;
void Raylib::Music::resume() const;
void Raylib::Music::setVolume(float volume) const;
void Raylib::Music::setPitch(float pitch) const;
void Raylib::Music::setPan(float pan) const;
float Raylib::Music::getTimeLength() const;
float Raylib::Music::getTimePlayed() const;
bool Raylib::Music::NeedToPlay() const;
void Raylib::Music::setNeedToPlay(bool needToPlay);
std::string Raylib::Music::getPath() const;
```

### Example usage

```cpp
Raylib::Music myMusic("path/to/musicfile.ogg");
myMusic.play();
myMusic.setVolume(0.6f);
```
33 changes: 33 additions & 0 deletions docs/developer-guide/client/audio/sounds.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
## Sound Class

### Constructors

```cpp
Raylib::Sound(const std::string& fileName, float volume = 0.5f);
```
Create a sound object from the specified audio file.
### Methods
```cpp
void Raylib::Sound::unload();
void Raylib::Sound::play() const;
void Raylib::Sound::stop() const;
void Raylib::Sound::pause() const;
void Raylib::Sound::resume() const;
bool Raylib::Sound::isPlaying() const;
void Raylib::Sound::setVolume(float volume) const;
void Raylib::Sound::setPitch(float pitch) const;
void Raylib::Sound::setPan(float pan) const;
bool Raylib::Sound::NeedToPlay() const;
void Raylib::Sound::setNeedToPlay(bool needToPlay);
std::string Raylib::Sound::getPath() const;
```

### Example usage

```cpp
Raylib::Sound mySound("path/to/soundfile.wav");
mySound.play();
mySound.setVolume(0.8f);
```
22 changes: 22 additions & 0 deletions docs/developer-guide/client/events/keyboard.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
## Input-related functions: keyboard

- `bool Raylib::isKeyPressed(Raylib::KeyboardKey key);`
Check if a key has been pressed once.

- `bool Raylib::isKeyDown(Raylib::KeyboardKey key);`
Check if a key is being pressed.

- `bool Raylib::isKeyReleased(Raylib::KeyboardKey key);`
Check if a key has been released once.

- `bool Raylib::isKeyUp(Raylib::KeyboardKey key);`
Check if a key is NOT being pressed.

- `void Raylib::setExitKey(Raylib::KeyboardKey key);`
Set a key to exit the application.

- `int Raylib::getKeyPressed();`
Get the key pressed (keycode).

- `int Raylib::getCharPressed();`
Get the last character pressed (unicode).
56 changes: 56 additions & 0 deletions docs/developer-guide/client/events/mouse.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
## Input-related functions: mouse

- `bool Raylib::isMouseButtonPressed(Raylib::MouseButton button);`
Check if a mouse button has been pressed once.

- `bool Raylib::isMouseButtonDown(Raylib::MouseButton button);`
Check if a mouse button is being pressed.

- `bool Raylib::isMouseButtonReleased(Raylib::MouseButton button);`
Check if a mouse button has been released once.

- `bool Raylib::isMouseButtonUp(Raylib::MouseButton button);`
Check if a mouse button is NOT being pressed.

- `int Raylib::getMouseX();`
Get the X position of the mouse cursor.

- `int Raylib::getMouseY();`
Get the Y position of the mouse cursor.

- `Vector2 Raylib::getMousePosition();`
Get the current position of the mouse cursor.

- `Vector2 Raylib::getMouseDelta();`
Get the mouse delta movement.

- `void Raylib::setMousePosition(int x, int y);`
Set the position of the mouse cursor.

- `void Raylib::setMouseOffset(int offsetX, int offsetY);`
Set an offset for the mouse position.

- `void Raylib::setMouseScale(float scaleX, float scaleY);`
Set the scaling factor for the mouse position.

- `float Raylib::getMouseWheelMove();`
Get the mouse wheel movement.

- `Vector2 Raylib::getMouseWheelMoveV();`
Get the mouse wheel movement as a vector.

- `void Raylib::setMouseCursor(int cursor);`
Set the mouse cursor style.

## Example

```cpp
if (Raylib::isKeyDown(Raylib::KeyboardKey::KB_RIGHT))
{
// Move right
}
else if (Raylib::isKeyDown(Raylib::KeyboardKey::KB_LEFT))
{
// Move left
}
```
33 changes: 33 additions & 0 deletions docs/developer-guide/client/geometry/color.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
## Color Structure

Represents a color.

- `Raylib::Color(uint8_t r, uint8_t g, uint8_t b, uint8_t a);`
Constructor to create a color with specified `r` (red), `g` (green), `b` (blue), and `a` (alpha) values.

### Color Constants

- `Raylib::DarkGray`
- `Raylib::Yellow`
- `Raylib::Gold`
- `Raylib::Orange`
- `Raylib::Pink`
- `Raylib::Red`
- `Raylib::Maroon`
- `Raylib::Green`
- `Raylib::Lime`
- `Raylib::DarkGreen`
- `Raylib::SkyBlue`
- `Raylib::Blue`
- `Raylib::DarkBlue`
- `Raylib::Purple`
- `Raylib::Violet`
- `Raylib::DarkPurple`
- `Raylib::Beige`
- `Raylib::Brown`
- `Raylib::DarkBrown`
- `Raylib::White`
- `Raylib::Black`
- `Raylib::Blank`
- `Raylib::Magenta`
- `Raylib::RayWhite`
6 changes: 6 additions & 0 deletions docs/developer-guide/client/geometry/rectangle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
## Rectangle Structure

Represents a rectangle.

- `Raylib::Rectangle(float x, float y, float width, float height);`
Constructor to create a rectangle with specified `x`, `y`, `width`, and `height` values.
6 changes: 6 additions & 0 deletions docs/developer-guide/client/geometry/vector2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
## Vector2 Structure

Represents a 2D vector.

- `Raylib::Vector2(float x, float y);`
Constructor to create a 2D vector with specified `x` and `y` values.
6 changes: 6 additions & 0 deletions docs/developer-guide/client/geometry/vector3.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
## Vector3 Structure

Represents a 3D vector.

- `Raylib::Vector3(float x, float y, float z);`
Constructor to create a 3D vector with specified `x`, `y`, and `z` values.
6 changes: 6 additions & 0 deletions docs/developer-guide/client/geometry/vector4.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
## Vector4 Structure

Represents a 4D vector.

- `Raylib::Vector4(float x, float y, float z, float w);`
Constructor to create a 4D vector with specified `x`, `y`, `z`, and `w` values.
16 changes: 16 additions & 0 deletions docs/developer-guide/client/graphic/colorsPixels.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
## Colors/pixels related functions

- `Raylib::Color Raylib::fade(Raylib::Color color, float alpha);`
Fade a color by a specified alpha value.

- `int Raylib::colorToInt(Raylib::Color color);`
Convert a Color to a 32-bit integer.

- `Vector4 Raylib::colorNormalize(Raylib::Color color);`
Normalize a Color struct to a Vector4.

- `Raylib::Color Raylib::colorFromNormalized(Raylib::Vector4 normalized);`
Create a Color from a normalized Vector4.

- `Raylib::Color Raylib::getColor(unsigned int hexValue);`
Create a Color from a hex value.
24 changes: 24 additions & 0 deletions docs/developer-guide/client/graphic/configFlags.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
## Enum ConfigFlags

You can use the following flags to configure the window:

- `Raylib::ConfigFlags::ConfigFlags::FLAG_FULLSCREEN_MODE`: Set fullscreen mode.
- `Raylib::ConfigFlags::FLAG_WINDOW_RESIZABLE`: Allow the window to be resized.
- `Raylib::ConfigFlags::FLAG_WINDOW_UNDECORATED`: Disable window decoration (frame and buttons).
- `Raylib::ConfigFlags::FLAG_WINDOW_TRANSPARENT`: Allow the window to be transparent.
- `Raylib::ConfigFlags::FLAG_WINDOW_HIDDEN`: Hide the window.
- `Raylib::ConfigFlags::FLAG_WINDOW_MINIMIZED`: Minimize the window.
- `Raylib::ConfigFlags::FLAG_WINDOW_MAXIMIZED`: Maximize the window.
- `Raylib::ConfigFlags::FLAG_WINDOW_UNFOCUSED`: Disable window focus.
- `Raylib::ConfigFlags::FLAG_WINDOW_TOPMOST`: Set the window to be always on top.
- `Raylib::ConfigFlags::FLAG_WINDOW_HIGHDPI`: Enable high-DPI mode.
- `Raylib::ConfigFlags::FLAG_WINDOW_ALWAYS_RUN`: Allow the window to run in the background.
- `Raylib::ConfigFlags::FLAG_MSAA_4X_HINT`: Enable 4x MSAA.
- `Raylib::ConfigFlags::FLAG_VSYNC_HINT`: Enable V-Sync.

## Example

```cpp
Raylib::setWindowState(Raylib::ConfigFlags::WINDOW_RESIZABLE);
Raylib::setWindowState(Raylib::ConfigFlags::WINDOW_RESIZABLE | Raylib::ConfigFlags::FLAG_VSYNC_HINT);
```
19 changes: 19 additions & 0 deletions docs/developer-guide/client/graphic/cursor.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
## Cursor-related functions

- `void Raylib::showCursor();`
Show the cursor.

- `void Raylib::hideCursor();`
Hide the cursor.

- `bool Raylib::isCursorHidden();`
Check if the cursor is currently hidden.

- `void Raylib::enableCursor();`
Enable cursor (unlock it).

- `void Raylib::disableCursor();`
Disable cursor (lock it).

- `bool Raylib::isCursorOnScreen();`
Check if the cursor is within the game window.
10 changes: 10 additions & 0 deletions docs/developer-guide/client/graphic/drawing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
## Drawing-related functions

- `void Raylib::clearBackground(Raylib::Color color);`
Clear the background with a specified color.

- `void Raylib::beginDrawing();`
Begin drawing.

- `void Raylib::endDrawing();`
End drawing and swap buffers.
Loading

0 comments on commit b8d5e2a

Please sign in to comment.