Making Games With Raylib Library As Senior Developer

jdbcdev

JDBC

Posted on December 9, 2023

Making Games With Raylib Library As Senior Developer

Photo by shark ovski on Unsplash

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?, 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 could be your best option. Let's code, just open your text editor like vim or VSCodium 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 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

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 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:

// 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
Enter fullscreen mode Exit fullscreen mode

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

 // 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)
Enter fullscreen mode Exit fullscreen mode

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

Let's code

In addition, the Huge examples collection 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, 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 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 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 for installing Raylib library on your Linux operating.

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
Enter fullscreen mode Exit fullscreen mode

Download latest version of Raylib from github repository and build the shared version of Raylib library using make command:

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.
Enter fullscreen mode Exit fullscreen mode

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

user@linuxmint:~/raylib/raylib/src$ sudo make install RAYLIB_LIBTYPE=SHARED # Dynamic shared version.
Enter fullscreen mode Exit fullscreen mode

sudo make install RAYLIB_LIBTYPE=SHARED # Dynamic shared version.

Follow the Manual installation for DotNet: use wget command to download dotnet-install.sh and execute it to complete the installation process.

user@linux:~$ wget https://dot.net/v1/dotnet-install.sh -O dotnet-install.sh
Enter fullscreen mode Exit fullscreen mode

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.

user@linux:~/raylib/first_game$ dotnet new console -n first_game
Enter fullscreen mode Exit fullscreen mode

Add Raylib C# binding library using nuget:

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
Enter fullscreen mode Exit fullscreen mode

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 to edit C# code.

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

user@linux:~$ sudo apt-get install vim
Enter fullscreen mode Exit fullscreen mode

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:

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;
    }
}
Enter fullscreen mode Exit fullscreen mode

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

user@linux:~/raylib/first_game$ dotnet build && dotnet run
Enter fullscreen mode Exit fullscreen mode

RayLib first game window

That's it, your first game window appears.

💖 💪 🙅 🚩
jdbcdev
JDBC

Posted on December 9, 2023

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related