Making Games With Raylib Library As Senior Developer
Tags: raylib, gamedev, csharp, indie
Published: 2023-12-09 17:30:33


![Photo by shark ovski on Unsplash](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2a6z79pzq3da64mfsije.jpg)

Imagine you are an experienced Senior Developer, so you have decided to give you the chance to build your first indie video game.

Obviously, the natural and first option *seems* to start learning a **Game Engine** like *Unity* or *Godot* with some visual tools that help you in developing your first indie game. 

As I explained in my last article [Is it worth to use Unity Game Engine for Indie Game Developers?](https://dev.to/jdbcdev/is-it-worth-to-use-unity-game-engine-for-indie-game-developers-2g6h), *Unity engine* is not a choice for different reasons.

Also, learning *How to use a new visual tool and specific Game Engine workflow* is not the path you really want to follow.

You have the expertise of developing software for many years and do not want to begin learning from scratch. And the truth is, you really do not need it.

Maybe you really want to keep using your favorite text editor like vim or Visual Studio Code. You would rather develop your indie video game following the old-school way, just coding it, just you and your programming expertise. You do not want more visual tools, one text editor and your knowledge should be enough.

You only want to learn how to use a game library and to write your indie game using a simple text editor running on multiple platforms.

## Looking for simple Game library

In this context, three requirements are set up:

* Choose an open-source and free Game library without any visual tool I must learn from scratch. The control of source code of your game has to be full.
* The game library does not need any extra dependencies. Choose a text editor and start building.
* The game library should be cross-platform, just one single codebase to run on multiple platforms.

At this point, you are digging into multiple game frameworks or libraries which fit into those previous requirements. 

So **[Raylib library](https://www.raylib.com)** could be your best option. Let's code, just open your text editor like [vim](https://www.vim.org) or [VSCodium](https://vscodium.com) in your Windows, Linux or Mac computer and let's build our indie game with *Raylib* library, no extra dependencies are needed.

The best part is Raylib also supports multiple target platforms in any platform that supports C language and OpenGL: Windows, Linux, MacOS, Android, HTML, Raspberry PI... 

Write once, running multiple platforms is really cool feature.

## Raylib and its own history

Raylib is a simple and open-source library that was built by *Ramon Santamaria* starting in August 2013 to support a game development course.

Inspired by Windows XNA framework, the first stable version of Raylib 1.0 was published on November 2013 as an open-source library. 

Now in December 2023, ten years later, **[Raylib 5.0](https://github.com/raysan5/raylib)** has been released and, along the way, it has been ported to more than 50 programming languages, known as Raylib bindings.

In words of the creator of Raylib: *A simple and easy-to-use library to enjoy videogames programming*.

## Raylib formed by modules

Raylib architecture is defined by a set of modules named accordingly to its primary functionality.

The following image is the current Raylib 5 architecture:
![Raylib architecture image](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/uvb8dthfymeywd00eoa6.png)

Every Raylib module defines a set of functions which provides a feature to make a game easy. 

For instance, *rcore* module defines the functions to manage windows, file system and game input.

Even some of those modules can be used in standalone mode, independently of Raylib library.

## Learning Raylib

[Raylib cheatsheet](https://www.raylib.com/cheatsheet/cheatsheet.html) provides you with a quick reference for Raylib API API (functions and datatypes) in HTML and PDF format.

The *Raylib cheatshee* is listed and colored by its modules and datatypes: *rcore*, *rshapes*, *rtextures*, *rtext*, *rmodels*, and *raudio*, 

For example, the Raylib *rcore* module defines these basic functions to *init* and *close* windows:

```c
// Window-related functions
    void InitWindow(int width, int height, const char *title);  // Initialize window and OpenGL context
    void CloseWindow(void);                                     // Close window and unload OpenGL context
```

and functions to clear background and begin / end drawing on the screen:

```c
 // Drawing-related functions
    void ClearBackground(Color color);                          // Set background color (framebuffer clear color)

    void BeginDrawing(void);                                    // Setup canvas (framebuffer) to start drawing
    void EndDrawing(void);                                      // End canvas drawing and swap buffers (double buffering)
```

Take a look at these *Raylib cheatsheet* to know more about Raylib features provided.

## Let's code

In addition, the [Huge examples collection](https://www.raylib.com/examples.html) is available to acquire how to use Raylib library in a proper form.

Choose your favourite programming language and begin to use the Rayblib binding for that language.

There are Raylib binding for [+60 bindings](https://github.com/raysan5/raylib/blob/master/BINDINGS.md), no excuses if you really know one programming language to begin developing your next indie game.

For example, if you are a C# expertise developer then you will use the **[Raylib C# binding](https://github.com/ChrisDill/Raylib-cs)** to begin developing your video game.

Linux is also the favorite operating system for senior developers, but no problem at all, C# also works in Linux through [.Net](https://dotnet.microsoft.com) *free*, *open-source* and *cross-platform* framework.

Let's install *DotNet* for starting your first indie video game.

### .Net in Linux

First step is to read the [Raylib Wiki](https://github.com/raysan5/raylib/wiki/Working-on-GNU-Linux) for installing Raylib library on your Linux operating.

```bash
user@linux:~$ sudo apt-get install build-essential git cmake libasound2-dev libx11-dev libxrandr-dev libxi-dev libgl1-mesa-dev libglu1-mesa-dev libxcursor-dev libxinerama-dev
```

Download latest version of [Raylib from github repository](https://github.com/raysan5/raylib.git) and build the shared version of Raylib library using *make* command:

```bash
user@linuxmint:~/raylib/raylib/src$ git clone https://github.com/raysan5/raylib.git raylib
cd raylib/src/
make PLATFORM=PLATFORM_DESKTOP RAYLIB_LIBTYPE=SHARED # To make the dynamic shared version.
```

Install the library to the standard *usr/local/lib* directory:

```bash
user@linuxmint:~/raylib/raylib/src$ sudo make install RAYLIB_LIBTYPE=SHARED # Dynamic shared version.
```

sudo make install RAYLIB_LIBTYPE=SHARED # Dynamic shared version.

Follow the [Manual installation for DotNet](https://learn.microsoft.com/en-us/dotnet/core/install/linux-scripted-manual#scripted-install): use *wget* command to download *dotnet-install.sh* and execute it to complete the installation process.

```bash
user@linux:~$ wget https://dot.net/v1/dotnet-install.sh -O dotnet-install.sh
```

*That's all jolks*, Raylib C# binding is installed in your Linux.

Use *dotnet new* command to create a new console C# project where your indie videogame single codebase will stand.

```bash
user@linux:~/raylib/first_game$ dotnet new console -n first_game
```

Add Raylib C# binding library using *nuget*:

```bash
user@linux:~/raylib/first_game$ dotnet add package Raylib-cs
user@linux:~/raylib/first_game$ ls -ltr
total 12
-rw-rw-r-- 1 jdbc jdbc  105 dic  9 12:54 Program.cs
-rw-rw-r-- 1 jdbc jdbc  342 dic  9 12:54 first_game.csproj
drwxrwxr-x 2 jdbc jdbc 4096 dic  9 12:54 obj
```

### Editing your video game

It's time to write some C# code and execute some commands in the Linux terminal:

You could use any text editor, but we will use *[vim text editor](https://www.vim.org)* to edit C# code.

Execute the following command if you do need to install it in your Linux operating system.

```bash
user@linux:~$ sudo apt-get install vim
```

Open up *Program.cs* file with *vim* text editor and replace everything with the following Raylib C# template for opening a window and drawing some text on the screen:

```bash
user@linux:~/raylib/first_game$ vim Program.cs
using Raylib_cs;
using System.Numerics;
using System;
using System.Text;

namespace Company.FirstGame;

public class MyFirstGame
{
    public static int Main()
    {
        const int screenWidth = 800;
        const int screenHeight = 450;

        Raylib.InitWindow(screenWidth, screenHeight, "My First Game");

        // Main loop
        while (!Raylib.WindowShouldClose())
        {
            Raylib.BeginDrawing();
            Raylib.ClearBackground(Color.RAYWHITE);

            Raylib.DrawText("Let's make an indie videogame!", 190, 200, 20, Color.BLACK);

            Raylib.EndDrawing();
        }

        Raylib.CloseWindow();

        return 0;
    }
}
```

Build and run your first video game using *dotnet build && dotnet run* commands

```bash
user@linux:~/raylib/first_game$ dotnet build && dotnet run
```

![RayLib first game window](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/iis2uy3doyjambpi9lq8.png)

That's it, your first game window appears.