Skip to content

Ayush2006128/HelloRaylibCs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

8 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Hello Raylib C# - Pong Game Starter Template

Pong Game Icon

A modern C# Pong game starter template using Raylib

.NET C# Raylib License


๐ŸŽฎ About

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!

โœจ Features

  • ๐ŸŽฏ 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

๐Ÿ› ๏ธ Prerequisites

๐Ÿ“‹ Project Structure

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

๐Ÿš€ Quick Start

Clone the Repository

git clone https://github.com/Ayush2006128/HelloRaylibCs.git
cd HelloRaylibCs

Build the Project

dotnet build

Run the Game

dotnet run

Or run the compiled executable from the bin/Debug/net10.0/ directory.

๐ŸŽฎ How to Play

Controls

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

Gameplay

  • 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

๐Ÿ“š Code Highlights

Collision Detection (lib/utils.cs)

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;
}

Paddle Movement (lib/utils.cs)

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;
}

๐Ÿ”Œ Dependencies

  • Raylib-cs (v7.0.2) - C# bindings for Raylib graphics library
    • High-level graphics and game framework
    • Cross-platform support (Windows, Linux, macOS)

๐Ÿ› ๏ธ Extending the Project

Add New Features

  1. Add Sound Effects - Use Raylib's audio functions

    Sound pingSound = Raylib.LoadSound("./ping.wav");
    Raylib.PlaySound(pingSound);
  2. Add AI Opponent - Implement computer player logic

  3. Add Power-ups - Extend the game with special items

  4. Improve Graphics - Add sprites, animations, and visual effects

  5. Add Menu System - Create start/pause/game over screens

Modify Game Settings

Edit Program.cs to customize:

  • Window size: Raylib.InitWindow(800, 450, "Title")
  • Frame rate: Raylib.SetTargetFPS(60)
  • Paddle size/speed
  • Ball physics

๐Ÿ“– Learning Resources

๐Ÿค Contributing

Contributions are welcome! Here's how:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ‘จโ€๐Ÿ’ป Author

Ayush - GitHub Profile

๐Ÿ™‹ Support

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!

About

A pong game impimetation to learn raylib

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages