Expert assistant for developing top-down 2D games with C++ and raylib. Handles CMake builds, player movement, collision detection, and game loop patterns.
Expert assistant for developing top-down 2D games (Zelda-like) with C++ and raylib. Specializes in CMake build systems, player movement, collision detection, and game loop patterns.
This skill helps you build and maintain a top-down pixel RPG game written in C++ using raylib. It understands the project structure, build system, and core game architecture including player movement, boundary collision, and frame-rate independent game loops.
When working on this C++ raylib game project, follow these guidelines:
The game follows this structure:
Key architectural patterns:
Always use these commands to build:
```bash
mkdir build && cd build
cmake ..
make
./ZeldaGame
```
If raylib is not installed, guide the user through installation:
```bash
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
git clone https://github.com/raysan5/raylib.git raylib
cd raylib
mkdir build && cd build
cmake -DBUILD_SHARED_LIBS=ON ..
make
sudo make install
sudo ldconfig
```
Maintain this organization:
```
cpp_game/
├── CMakeLists.txt # Build configuration
├── README.md # Documentation
├── src/ # Implementation files
│ ├── main.cpp # Entry point
│ ├── Game.cpp/.h # Game class
│ └── Player.cpp/.h # Player class
├── include/ # Shared headers
│ └── Constants.h # Configuration constants
└── assets/ # Sprites, sounds, etc.
```
When implementing or modifying player movement:
Example pattern:
```cpp
float deltaTime = GetFrameTime();
float moveSpeed = 200.0f; // pixels per second
Vector2 movement = {0, 0};
if (IsKeyDown(KEY_W) || IsKeyDown(KEY_UP)) movement.y -= 1;
if (IsKeyDown(KEY_S) || IsKeyDown(KEY_DOWN)) movement.y += 1;
if (IsKeyDown(KEY_A) || IsKeyDown(KEY_LEFT)) movement.x -= 1;
if (IsKeyDown(KEY_D) || IsKeyDown(KEY_RIGHT)) movement.x += 1;
// Normalize diagonal movement
if (movement.x != 0 && movement.y != 0) {
float length = sqrt(movement.x * movement.x + movement.y * movement.y);
movement.x /= length;
movement.y /= length;
}
position.x += movement.x * moveSpeed * deltaTime;
position.y += movement.y * moveSpeed * deltaTime;
```
Keep player within window bounds using simple AABB collision:
Follow raylib's standard game loop structure:
```cpp
void Game::Run() {
while (!WindowShouldClose()) {
Update();
Render();
}
}
void Game::Update() {
// Update game state using GetFrameTime()
}
void Game::Render() {
BeginDrawing();
ClearBackground(RAYWHITE);
// Draw game entities
EndDrawing();
}
```
When adding new game features:
1. Check if Constants.h needs new configuration values
2. Consider if the feature belongs in Game.cpp or a new class
3. Maintain separation of concerns (update vs render)
4. Add new source files to CMakeLists.txt
5. Test boundary cases and collision scenarios
6. Rebuild with `make` after changes
**User**: "Add a simple enemy that follows the player"
**Expected Approach**:
1. Read existing Player.cpp/h to understand entity pattern
2. Create Enemy.cpp/h following similar structure
3. Add enemy movement logic that tracks player position
4. Update Game.cpp to instantiate and update enemy
5. Add enemy rendering to Game::Render()
6. Update CMakeLists.txt to include Enemy.cpp
7. Test collision and boundaries
8. Guide user to rebuild: `cd build && make && ./ZeldaGame`
**User**: "The player moves too fast"
**Expected Approach**:
1. Check Constants.h for speed configuration
2. Read Player.cpp to see how speed is applied
3. Adjust the speed constant or suggest a modification
4. Explain relationship between speed, delta time, and movement
Leave a review
No reviews yet. Be the first to review this skill!
# Download SKILL.md from killerskills.ai/api/skills/c-raylib-game-dev-assistant/raw