Migration to Codeberg

This commit is contained in:
Joaquin Gottlebe
2026-07-30 16:38:22 +02:00
commit 17048b703a
556 changed files with 3040 additions and 0 deletions
+16
View File
@@ -0,0 +1,16 @@
CC = gcc
CFLAGS = -Wall -std=c99
INCLUDE_PATH = -I/opt/homebrew/include
LIB_PATH = -L/opt/homebrew/Cellar/raylib/5.0/lib
LDFLAGS = -lraylib -framework OpenGL -framework Cocoa -framework IOKit
TARGET = game
SRC = main.c # add here more source files
$(TARGET): $(SRC)
$(CC) $(CFLAGS) $(INCLUDE_PATH) -o $(TARGET) $(SRC) $(LIB_PATH) $(LDFLAGS)
clean:
rm -f $(TARGET)
run: clean $(TARGET)
./$(TARGET)
+51
View File
@@ -0,0 +1,51 @@
# RPG
## Overview
This project is an RPG game built using the [raylib](https://www.raylib.com/) library. The game uses raylib for rendering, input handling, and other graphical features.
## Prerequisites
Before building and running the game, ensure you have the following installed on your system:
- **raylib**: The game relies on raylib for graphical rendering. You can install it via Homebrew or other package managers. For Homebrew:
```bash
brew install raylib
```
- **Make**: A build automation tool to compile the game.
- **C Compiler**: Ensure a C compiler like `gcc` or `clang` is installed on your system.
## Configuration
Update the `Makefile` to reflect your raylib installation paths. Below is an example configuration:
```Makefile
INCLUDE_PATH = -I/opt/homebrew/include
LIB_PATH = -L/opt/homebrew/Cellar/raylib/5.0/lib
LDFLAGS = -lraylib -framework OpenGL -framework Cocoa -framework IOKit
```
Replace the paths if raylib is installed in a different location on your system.
## Building the Game
- **Build the game:**
```bash
make
```
## Running the Game
- **Run the game:**
```bash
make run
```
## Troubleshooting
- Ensure the paths in the `Makefile` point to the correct raylib installation directories.
- If raylib is not installed, install it using your package manager.
- For macOS users, ensure `-framework OpenGL`, `-framework Cocoa`, and `-framework IOKit` are included in the `LDFLAGS`.
## License
This project is distributed under the MIT License. See the `LICENSE` file for details.
## Contributions
Contributions are welcome! Feel free to fork the repository and submit pull requests.
BIN
View File
Binary file not shown.
+229
View File
@@ -0,0 +1,229 @@
#include <raylib.h>
#include <stdio.h>
const int TILEMAP_COLUMNS = 16;
const int TILEMAP_ROWS = 10;
const int TILE_WIDTH = 8;
const int TILE_HEIGHT = 8;
const int WORLD_WIDTH = 100;
const int WORLD_HEIGHT = 100;
const int screenWidth = 800;
const int screenHeight = 600;
const char *gameTitle = "RPG";
const int fps = 60;
// Camera
Camera2D camera = {0};
const Vector2 initialTarget = {0, 0};
const Vector2 initialOffset = {(float)(screenWidth / 2) - TILE_WIDTH, (float)(screenHeight / 2) - TILE_HEIGHT};
const float initialRotation = 0.0f;
const float initialZoom = 5.0f;
// Texture
const int MAX_TEXTURES = 1;
typedef enum
{
TEXTURE_TILEMAP = 0
} texture_asset;
Texture2D textures[MAX_TEXTURES];
typedef struct
{
int x;
int y;
} sTile;
sTile world[WORLD_WIDTH][WORLD_HEIGHT];
// player
typedef struct
{
int x;
int y;
} sEntity;
sEntity player;
// Audios
const int MAX_SOUNDS = 1;
typedef enum
{
SOUNDTRACK_AUDIO = 0
} audio_asset;
Sound sounds[MAX_SOUNDS];
// functions
void DrawTile(int pos_x, int pos_y, int tile_x, int tile_y)
{
Rectangle source = {
(float)(TILE_WIDTH * tile_x),
(float)(TILE_HEIGHT * tile_y),
(float)(TILE_WIDTH),
(float)(TILE_HEIGHT)};
Rectangle dest = {
(float)(pos_x),
(float)(pos_y),
(float)(TILE_WIDTH),
(float)(TILE_HEIGHT)};
Vector2 origin = {0, 0};
DrawTexturePro(textures[TEXTURE_TILEMAP], source, dest, origin, 0.0f, WHITE);
}
void GameStartup(Vector2 initialTarget, Vector2 initialOffset, float initialRotation, float initialZoom)
{
// Player setup
player = (sEntity){
.x = 0,
.y = 0};
// Camera setup
camera.target = (Vector2){player.x, player.y};
camera.offset = initialOffset;
camera.rotation = initialRotation;
camera.zoom = initialZoom;
// Audio setup
InitAudioDevice();
Wave wave = LoadWave("assets/wav/Dark Ambient 1.wav");
sounds[SOUNDTRACK_AUDIO] = LoadSoundFromWave(wave);
UnloadWave(wave);
PlaySound(sounds[SOUNDTRACK_AUDIO]);
// Texture setup
Image image = LoadImage("assets/Tilemap/colored_tilemap_packed.png");
textures[TEXTURE_TILEMAP] = LoadTextureFromImage(image);
UnloadImage(image);
// World setup
for (int i = 0; i < WORLD_WIDTH; i++)
{
for (int j = 0; j < WORLD_HEIGHT; j++)
{
world[i][j] = (sTile){
.x = i,
.y = j,
};
}
}
}
void GameUpdate()
{
// WASD Movement
if (IsKeyReleased(KEY_A))
player.x -= 8.0f;
if (IsKeyReleased(KEY_D))
player.x += 8.0f;
if (IsKeyReleased(KEY_W))
player.y -= 8.0f;
if (IsKeyReleased(KEY_S))
player.y += 8.0f;
// Arrow movement
if (IsKeyReleased(KEY_LEFT))
player.x -= 8.0f;
if (IsKeyReleased(KEY_RIGHT))
player.x += 8.0f;
if (IsKeyReleased(KEY_UP))
player.y -= 8.0f;
if (IsKeyReleased(KEY_DOWN))
player.y += 8.0f;
camera.target.x = player.x + TILE_WIDTH / 2;
camera.target.y = player.y + TILE_HEIGHT / 2;
printf("Player X%d", player.x);
// MouseWheelZoom
float wheelMove = GetMouseWheelMove();
if (wheelMove != 0)
{
const float zoomIncrement = 0.125f;
camera.zoom += wheelMove * zoomIncrement;
if (camera.zoom < 2.5f)
camera.zoom = 2.5f;
if (camera.zoom > 10.0f)
camera.zoom = 10.0f;
}
}
void GameRender(Vector2 initialTarget)
{
BeginDrawing();
ClearBackground(BLACK);
BeginMode2D(camera);
// Floor
for (int i = 0; i < WORLD_WIDTH; i++)
{
for (int j = 0; j < WORLD_HEIGHT; j++)
{
sTile tile = world[i][j];
DrawTile(tile.x * TILE_WIDTH, tile.y * TILE_HEIGHT, 4, 4);
}
}
// Grid
for (int x = -WORLD_WIDTH * TILE_WIDTH * 10; x <= WORLD_WIDTH * TILE_WIDTH * 10; x += TILE_WIDTH)
{
DrawLine(x, -1000, x, 1000, GRAY);
}
for (int y = -WORLD_WIDTH * TILE_WIDTH * 10; y <= WORLD_WIDTH * TILE_WIDTH * 10; y += TILE_WIDTH)
{
DrawLine(-1000, y, 1000, y, GRAY);
}
// Manual
DrawText("Use WASD to move the camera", 10, 10, 10, LIGHTGRAY);
DrawText("Scroll to zoom in/out", 10, 40, 10, LIGHTGRAY);
// Player
DrawTile(player.x, player.y, 15, 0);
EndMode2D();
// Debug
DrawText(TextFormat("Player X: %.2f", player.x), 10, 0, 20, LIGHTGRAY);
DrawText(TextFormat("Player Y: %.2f", player.y), 10, 20, 20, LIGHTGRAY);
DrawText(TextFormat("Zoom Level: %.2f", camera.zoom), 10, 80, 20, LIGHTGRAY);
EndDrawing();
}
void GameShutdown()
{
for (int i = 0; i < MAX_TEXTURES; i++)
{
UnloadTexture(textures[i]);
}
for (int i = 0; i < MAX_SOUNDS; i++)
{
UnloadSound(sounds[i]);
}
CloseAudioDevice();
}
int main()
{
InitWindow(screenWidth, screenHeight, gameTitle);
SetTargetFPS(fps);
GameStartup(initialTarget, initialOffset, initialRotation, initialZoom);
while (!WindowShouldClose())
{
GameUpdate();
GameRender(initialTarget);
}
GameShutdown();
CloseWindow();
return 0;
}