Changed readme.

This commit is contained in:
Kapendev 2025-01-25 10:38:17 +02:00
parent f2ec195d81
commit 071f03b44f
3 changed files with 19 additions and 301 deletions

View file

@ -1,8 +0,0 @@
# Projects Made With Parin
This is a place for people to showcase their projects built with Parin.
If you would like your project listed here, feel free to add it and submit a PR!
* [Clean & Haunted](https://kapendev.itch.io/clean-haunted)
* [Runani](https://kapendev.itch.io/runani)
* [A Short Metamorphosis](https://kapendev.itch.io/a-short-metamorphosis)

View file

@ -1,7 +1,7 @@
# Parin
A lightweight and beginner-friendly 2D game engine for the D programming language.
It focuses on providing a simple foundation for building 2D games.
A delightfully simple and lightweight 2D game engine for the D programming language,
offering a solid foundation for creating 2D games.
```d
import parin;
@ -20,49 +20,30 @@ void finish() { }
mixin runGame!(ready, update, finish);
```
## Features
## Batteries Included
* Immediate Mode UI: Build UIs quickly.
* Dialogue System: Create interactive stories using a stack-oriented scripting language.
* Sprite Animation Support: Manage animations for characters and objects.
* Tile Map Support: Create and draw tile-based maps.
* Intuitive immediate mode UI
* Flexible dialogue system with a stack-oriented scripting language
* Atlas-based animation library
* ...and more!
## Supported Platforms
* PC: Windows, Linux, macOS
* Web
* PC: Windows, Linux, Mac
* WebAssembly
## Projects Made With Parin
A list of projects made with Parin is available in the [PROJECTS.md](PROJECTS.md) file.
A list of projects made with Parin is available in the [projects](https://kapendev.github.io/parin-website/pages/projects.html) page.
## Installation
This guide shows how to install Parin and its dependencies using [DUB](https://dub.pm/).
While DUB simplifies the process, Parin itself doesn't require DUB.
Parin has the following dependencies:
* [Joka](https://github.com/Kapendev/joka): A simple nogc utility library.
* [raylib](https://github.com/raysan5/raylib): A simple graphics library.
### Installation Steps
Create a new folder and run inside the following commands:
```sh
```cmd
dub init -n
dub run parin:setup
```
The final line modifies the default app.d and dub.json files, downloads raylib, and creates the necessary folders for Parin to function properly. The following folders will be created:
* assets: This folder is used to store assets.
* web: This folder is used for exporting to the web.
Once the installation is complete, run the following command:
```sh
dub run
```
@ -72,56 +53,25 @@ If everything is set up correctly, a window will appear showing the message "Hel
Some libraries for sound, graphics, and input handling are required before using Parin on Linux. Below are installation commands for some Linux distributions.
**Ubuntu:**
Ubuntu:
```sh
```cmd
sudo apt install libasound2-dev libx11-dev libxrandr-dev libxi-dev libgl1-mesa-dev libglu1-mesa-dev libxcursor-dev libxinerama-dev libwayland-dev libxkbcommon-dev
```
**Fedora:**
Fedora:
```sh
```cmd
sudo dnf install alsa-lib-devel mesa-libGL-devel libX11-devel libXrandr-devel libXi-devel libXcursor-devel libXinerama-devel libatomic
```
**Arch:**
Arch:
```sh
```cmd
sudo pacman -S alsa-lib mesa libx11 libxrandr libxi libxcursor libxinerama
```
## Documentation
For an initial understanding, the [examples](examples) folder can be a good starting point.
For a more detailed overview, check the [TOUR.md](TOUR.md) file.
## Web Support
To export to the web, the project must be compatible with BetterC.
The [web](web) folder contains a helper script to assist with the web export process and it can be used with DUB by running the following command:
```sh
dub run parin:web
```
## Alternative Game Development Libraries
While Parin provides a good game development experience in D, it might not fit everyone's needs.
Here are some other notable alternatives to consider:
* [raylib-d](https://github.com/schveiguy/raylib-d)
* [HipremeEngine](https://github.com/MrcSnm/HipremeEngine)
* [PixelPerfectEngine](https://github.com/ZILtoid1991/pixelperfectengine)
* [Godot-DLang](https://github.com/godot-dlang/godot-dlang)
## Note
I add things to Parin when I need them.
For an overview of what I like and don't like, check the [PREFERENCES.md](PREFERENCES.md) file.
Also, developers using Parin are called Parinists (a name suggested by AI).
## License
The project is released under the terms of the MIT License.
Please refer to the LICENSE file.
Start with the [examples](https://github.com/Kapendev/parin/tree/main/examples) folder for a quick overview.
For more details, check the [tour](https://kapendev.github.io/parin-website/pages/tour.html) page.

224
TOUR.md
View file

@ -1,224 +0,0 @@
# Tour (WIP)
## Understanding the Code
To begin, open the main project file and copy-paste the following code:
```d
import parin;
void ready() {
lockResolution(320, 180);
}
bool update(float dt) {
drawDebugText("Hello world!", Vec2(8));
return false;
}
void finish() { }
mixin runGame!(ready, update, finish);
```
This code will create a window that displays the message "Hello world!".
Here is a breakdown of how this code works:
1. The Ready Function
```d
void ready() {
lockResolution(320, 180);
}
```
This function is the starting point of the game.
It is called once when the game starts and, in this example, locks the game resolution to 320 pixels wide and 180 pixels tall.
2. The Update Function
```d
bool update(float dt) {
drawDebugText("Hello world!", Vec2(8));
return false;
}
```
This function is the main loop of the game.
It is called every frame while the game is running and, in this example, draws the message "Hello world!" at position `Vec2(8)`.
The `return false` statement indicates that the game should continue running.
If `true` were returned, the game would stop running.
3. The Finish Function
```d
void finish() { }
```
This function is the ending point of the game.
It is called once when the game ends and, in this example, does nothing.
4. The Mixin
```d
mixin runGame!(ready, update, finish);
```
This line sets up a main function that will run the game.
In essence, a Parin game typically relies on three key functions:
* A ready function.
* An update function.
* A finish function.
## Input
Parin provides a set of input functions inside the `parin.engine` module.
```d
bool isDown(char key);
bool isDown(Keyboard key);
bool isDown(Mouse key);
bool isDown(Gamepad key, int id = 0);
bool isPressed(char key);
bool isPressed(Keyboard key);
bool isPressed(Mouse key);
bool isPressed(Gamepad key, int id = 0);
bool isReleased(char key);
bool isReleased(Keyboard key);
bool isReleased(Mouse key);
bool isReleased(Gamepad key, int id = 0);
Keyboard dequeuePressedKey();
dchar dequeuePressedRune();
Vec2 wasd();
Vec2 wasdPressed();
Vec2 wasdReleased();
Vec2 mouse();
Vec2 deltaMouse();
float deltaWheel();
```
## Sound
Parin provides a set of sound functions inside the `parin.engine` module.
```d
void playSound(Sound sound);
void stopSound(Sound sound);
void pauseSound(Sound sound);
void resumeSound(Sound sound);
void updateSound(Sound sound);
```
## Drawing
Parin provides a set of drawing functions inside the `parin.engine` module.
While drawing is not pixel-perfect by default, it can be by calling the `setIsPixelPerfect` or `setIsPixelSnapped` functions.
```d
void drawRect(Rect area, Color color = white);
void drawHollowRect(Rect area, float thickness, Color color = white);
void drawCirc(Circ area, Color color = white);
void drawHollowCirc(Circ area, float thickness, Color color = white);
void drawVec2(Vec2 point, float size, Color color = white);
void drawLine(Line area, float size, Color color = white);
void drawTexture(Texture texture, Vec2 position, DrawOptions options = DrawOptions());
void drawTextureArea(Texture texture, Rect area, Vec2 position, DrawOptions options = DrawOptions());
void drawTexturePatch(Texture texture, Rect area, Rect target, bool isTiled, DrawOptions options = DrawOptions());
void drawViewport(Viewport viewport, Vec2 position, DrawOptions options = DrawOptions());
void drawViewportArea(Viewport viewport, Rect area, Vec2 position, DrawOptions options = DrawOptions());
void drawRune(Font font, dchar rune, Vec2 position, DrawOptions options = DrawOptions());
void drawText(Font font, IStr text, Vec2 position, DrawOptions options = DrawOptions());
void drawDebugText(IStr text, Vec2 position, DrawOptions options = DrawOptions());
```
Some of these functions also accept managed resources.
Additional drawing functions can be found in other modules, such as `parin.sprite`.
### Draw Options
Draw options are used for configuring drawing parameters. The data structure looks something like this:
```d
struct DrawOptions {
Vec2 origin = Vec2(0.0f); /// The origin point of the drawn object. This value can be used to force a specific value when needed and is not used if it is set to zero.
Vec2 scale = Vec2(1.0f); /// The scale of the drawn object.
float rotation = 0.0f; /// The rotation of the drawn object, in degrees.
Color color = white; /// The color of the drawn object.
Hook hook = Hook.topLeft; /// A value representing the origin point of the drawn object when origin is set to zero.
Flip flip = Flip.none; /// A value representing flipping orientations.
Alignment alignment = Alignment.left; /// A value represeting alignment orientations.
int alignmentWidth = 0; /// The width of the aligned object. It is used as a hint and is not enforced. Usually used for text drawing.
float visibilityRatio = 1.0f; /// Controls the visibility ratio of the object, where 0.0 means fully hidden and 1.0 means fully visible. Usually used for text drawing.
bool isRightToLeft = false; /// Indicates whether the content of the object flows in a right-to-left direction, such as for Arabic or Hebrew text. Usually used for text drawing.
}
```
Some of these parameters can also be configured via the constructors.
```d
this(float rotation);
this(Vec2 scale);
this(Color color);
this(Hook hook);
this(Flip flip);
this(Alignment alignment, int alignmentWidth = 0);
```
## Loading and Saving Resources
Parin provides a set of loading functions inside the `parin.engine` module.
Functions that start with the word load/save will always try to read/write resources from/to the assets folder.
These functions handle both forward slashes and backslashes in file paths, ensuring compatibility across operating systems.
```d
TextureId loadTexture(IStr path);
Result!Texture loadRawTexture(IStr path);
FontId loadFont(IStr path, int size, int runeSpacing, int lineSpacing, IStr32 runes = "");
FontId loadFontFromTexture(IStr path, int tileWidth, int tileHeight);
Result!Font loadRawFont(IStr path, int size, int runeSpacing, int lineSpacing, IStr32 runes = "");
Result!Font loadRawFontFromTexture(IStr path, int tileWidth, int tileHeight);
SoundId loadSound(IStr path, float volume, float pitch);
Result!Sound loadRawSound(IStr path, float volume, float pitch);
Fault loadRawTextIntoBuffer(IStr path, ref LStr buffer);
Result!LStr loadRawText(IStr path);
Result!IStr loadTempText(IStr path);
Fault saveText(IStr path, IStr text);
```
Additional loading functions can be found in other modules, such as `parin.map`.
### Managed Resources
Managed resources are cached by their path they were loaded with.
To free these resources, use the `freeResources` function or the `free` method on the resource identifier.
The resource identifier is automatically invalidated when the resource is freed.
### Raw Resources
Raw resources are managed directly by the user and are not cached or grouped.
They must be freed manually when no longer needed.
### Temporary Resources
Temporary resources are only valid until the function that provided them is called again.
They dont need to be freed manually.
## Sprites and Tile Maps
Sprites and tile maps can be implemented in various ways.
To avoid enforcing a specific approach, Parin provides optional modules for these features, allowing users to include or omit them as needed.
Parin provides a sprite type inside the `parin.sprite` module and a tile map type inside the `parin.map` module.