Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DOCUMENTATION: Add raylib wrapper documentation #35

Merged
merged 7 commits into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@
- [Server](developer-guide/server/README.md)

- [Client](developer-guide/client/README.md)
- [Audio](developer-guide/client/audio/README.md)
- [Events](developer-guide/client/events/README.md)
- [Geometry](developer-guide/client/geometry/README.md)
- [Graphic](developer-guide/client/graphic/README.md)

-----------

Expand Down
21 changes: 21 additions & 0 deletions docs/developer-guide/client/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# 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.

Explore the following sections to understand and utilize different aspects of the Raylib library:

- [**Audio**](audio/index.html): Learn how to add sounds, music, and other audio effects to your game.
TTENSHII marked this conversation as resolved.
Show resolved Hide resolved

- [**Geometry**](inputs/index.html): Learn about the different data structures and how to use them.

- [**Events**](events/index.html): Detect and respond to application events like mouse clicks and keyboard inputs.

- [**Graphics**](graphics/index.html): Learn about advanced graphic rendering, music, animations...
TTENSHII marked this conversation as resolved.
Show resolved Hide resolved
124 changes: 124 additions & 0 deletions docs/developer-guide/client/audio/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
# 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.

## Sound Class
TTENSHII marked this conversation as resolved.
Show resolved Hide resolved

### Constructors

```cpp
Raylib::Sound(const std::string& fileName, float volume = 0.5f);
```
Create a sound object from the specified audio file.

### Methods

```cpp
void unload();
void play() const;
void stop() const;
void pause() const;
void resume() const;
bool isPlaying() const;
void setVolume(float volume) const;
void setPitch(float pitch) const;
void setPan(float pan) const;
bool NeedToPlay() const;
void setNeedToPlay(bool needToPlay);
std::string getPath() const;
TTENSHII marked this conversation as resolved.
Show resolved Hide resolved
```

### Example usage

```cpp
Raylib::Sound mySound("path/to/soundfile.wav");
mySound.play();
mySound.setVolume(0.8f);
```

## Music Class
TTENSHII marked this conversation as resolved.
Show resolved Hide resolved

### Constructors

```cpp
Raylib::Music(const std::string& fileName, float volume = 0.5f);
```

Create a music object from the specified audio file.

### Methods

```cpp
void unload();
bool isReady() const;
void play() const;
bool isPlaying() const;
void update() const;
void stop() const;
void pause() const;
void resume() const;
void setVolume(float volume) const;
void setPitch(float pitch) const;
void setPan(float pan) const;
float getTimeLength() const;
float getTimePlayed() const;
bool NeedToPlay() const;
void setNeedToPlay(bool needToPlay);
std::string getPath() const;
```

### Example usage

```cpp
Raylib::Music myMusic("path/to/musicfile.ogg");
myMusic.play();
myMusic.setVolume(0.6f);
```

## Audio Device Management

### Functions

```cpp
void initAudioDevice();
void closeAudioDevice();
bool isAudioDeviceReady();
void 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");

initAudioDevice();
// game loop
while (!WindowShouldClose()) {
// stuff
//for every music
UpdateMusicStream(music);
}
closeAudioDevice();
}
```

## Audio File Formats

Raylib supports the following audio file formats:

- WAV
- OGG
- MP3
- XM
- QOA
- MOD
- FLAC

## 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).
83 changes: 83 additions & 0 deletions docs/developer-guide/client/events/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
# Input Handling

In your game client, we use and enum to represent keyboard and mouse keys. The enum is defined in `inputs.hpp` and is called `KeyboardKey` and `MouseButton`. The enum values are the same as the ones defined in `raylib.h`.

## Input-related functions: keyboard

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

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

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

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

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

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

- `int getCharPressed();`
Get the last character pressed (unicode).
TTENSHII marked this conversation as resolved.
Show resolved Hide resolved

## Input-related functions: mouse

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

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

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

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

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

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

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

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

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

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

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

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

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

- `void setMouseCursor(int cursor);`
Set the mouse cursor style.
TTENSHII marked this conversation as resolved.
Show resolved Hide resolved

## Example

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

## Vector2 Structure

Represents a 2D vector.

- `Vector2(float x, float y);`
Constructor to create a 2D vector with specified `x` and `y` values.

## Vector3 Structure

Represents a 3D vector.

- `Vector3(float x, float y, float z);`
Constructor to create a 3D vector with specified `x`, `y`, and `z` values.

## Vector4 Structure

Represents a 4D vector.

- `Vector4(float x, float y, float z, float w);`
Constructor to create a 4D vector with specified `x`, `y`, `z`, and `w` values.

## Rectangle Structure

Represents a rectangle.

- `Rectangle(float x, float y, float width, float height);`
Constructor to create a rectangle with specified `x`, `y`, `width`, and `height` values.

## Color Structure

Represents a color.

- `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.
TTENSHII marked this conversation as resolved.
Show resolved Hide resolved

### 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`

These constants represent predefined colors for convenience in your graphical applications.
Loading
Loading