Hello Raylib C# is a lightweight, beginner-friendly starter template for game development using C# and Raylib. It includes a fully functional Pong game implementation that demonstrates core game development concepts like collision detection, sprite movement, and game state management.
Perfect for learning game development with C# or as a foundation for your next Raylib project!
- ๐ฏ Complete Pong Implementation - Two-player pong game with score tracking
- ๐ Modern C# Stack - Built on .NET 10 with C# 14.0
- ๐จ Clean Architecture - Well-organized utility functions for game logic
- โก High Performance - Optimized rendering with monitor refresh rate sync
- ๐ง Easy to Extend - Simple, modular code structure for adding new features
- ๐ฆ Minimal Dependencies - Only requires Raylib-cs package
- .NET 10 SDK
- Visual Studio 2026 Community or any .NET-compatible IDE
- Basic C# knowledge
HelloRaylibCs/
โโโ Program.cs # Main game loop and initialization
โโโ lib/
โ โโโ utils.cs # Utility functions (collision detection, paddle movement)
โโโ ping-pong.png # Game icon (PNG format)
โโโ ping-pong.ico # App icon (Windows format)
โโโ HelloRaylibCs.csproj # Project configuration
โโโ README.md # This file
git clone https://github.com/Ayush2006128/HelloRaylibCs.git
cd HelloRaylibCsdotnet builddotnet runOr run the compiled executable from the bin/Debug/net10.0/ directory.
Left Player (WASD Keys)
- W - Move paddle up
- S - Move paddle down
Right Player (Arrow Keys)
- โฌ๏ธ Up - Move paddle up
- โฌ๏ธ Down - Move paddle down
General
- ESC - Close the game
- The ball bounces off the top and bottom walls
- Each player tries to prevent the ball from reaching their side
- The ball bounces off paddles and reverses direction
- Score is displayed for tracking game progress
public static void CheckBallCollisions(float ballX, float ballY, int ballRadius,
Rectangle leftpaddle, Rectangle rightpaddle, ref float ballSpeedX, ref float ballSpeedY)
{
// Wall collision
if (ballY <= 0 || ballY >= 450)
ballSpeedY = -ballSpeedY;
// Paddle collision
if (ballX - ballRadius <= leftpaddle.X + leftpaddle.Width &&
ballY >= leftpaddle.Y && ballY <= leftpaddle.Y + leftpaddle.Height)
ballSpeedX = -ballSpeedX;
}public static void Movepaddle(ref Rectangle paddle, string keyGroup, float changeValue)
{
KeyboardKey upKey = keyGroup == "arrows" ? KeyboardKey.Up : KeyboardKey.W;
KeyboardKey downKey = keyGroup == "arrows" ? KeyboardKey.Down : KeyboardKey.S;
if (Raylib.IsKeyDown(upKey) && paddle.Y > 0)
paddle.Y -= changeValue;
else if (Raylib.IsKeyDown(downKey) && paddle.Y < 360)
paddle.Y += changeValue;
}- Raylib-cs (v7.0.2) - C# bindings for Raylib graphics library
- High-level graphics and game framework
- Cross-platform support (Windows, Linux, macOS)
-
Add Sound Effects - Use Raylib's audio functions
Sound pingSound = Raylib.LoadSound("./ping.wav"); Raylib.PlaySound(pingSound);
-
Add AI Opponent - Implement computer player logic
-
Add Power-ups - Extend the game with special items
-
Improve Graphics - Add sprites, animations, and visual effects
-
Add Menu System - Create start/pause/game over screens
Edit Program.cs to customize:
- Window size:
Raylib.InitWindow(800, 450, "Title") - Frame rate:
Raylib.SetTargetFPS(60) - Paddle size/speed
- Ball physics
Contributions are welcome! Here's how:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
Ayush - GitHub Profile
Have questions or found a bug? Feel free to:
- Open an issue
- Check existing discussions and FAQs
- Reach out via GitHub discussions
Made with โค๏ธ using C# and Raylib
โญ If you found this helpful, please consider giving it a star!
