Today we are going to flexing our C skills to make the very simple game Arkanoid. We will also cover basic graphics using the raylib framework. You can view the finished project here.
Before we get started, let's start with some theory. First, in graphics coordinates work similar to reading text on a page, they start at the top left corner and increase going down right the screen.
In otherwords, the window's origin is at the top left corner. Going right means increasing x and going down means increasing y.
Raylib is a very easy-to-setup framework for game or UI development. It comes ready with many examples and a handy cheatsheet. You can also find additional support at their discord server.
To download it, head over to its itch download page, donate or just go to downloads (it's free!), and run the installer.
It should install (if you are on Windows) on your C drive included with a compiler and other tools.
Depending on your setup, I'd reccomend adding the binary directory (C:\raylib\w64devkit\bin
) to PATH (Windows only). If you are confused about this, I would honestly just recommend you lookup how to add directories to PATH.
To set up our project navigate to the projects directory (C:\raylib\raylib\projects
) and choose the project for your favorite editor; for this tutorial, I am using VSCode.
Copy the template and delete (for VSCode) /resources
, main.code-workspace
, and Makefile.Android
(none of these are needed).
Press CTRL-F5
in VSCode and you should see this:
Before proceeding, I'd also recommend commenting out "-Wl,--subsystem,windows
" on the CFLAGS
line in the Makefile
(as of now, line 210). This will allow you to print to console and view the application's runtime debug information.
Getting started in a new graphics library is easiest when you can get straight to drawing, not dealing with repetitive window management. Here's a basic template crafted just for this project. I would not recommend using this template for a large project, as you should understand a large portion of a library before starting a big project.
#include "raylib.h"
#include "raymath.h"
#include "string.h" // We'll be using this later
#include "stdio.h" // Just in case if you want to use printf or other I/O functions; helpful for debugging
// Create a type symbol for unsigned characters; I use this mostly as a boolean
typedef unsigned char u8;
void update() {
}
void draw() {
}
int main() {
InitWindow( WIDTH, HEIGHT, "Arkanoid" );
SetTargetFPS(60);
while(!WindowShouldClose()) {
update();
BeginDrawing();
ClearBackground(BLACK);
draw();
EndDrawing();
}
CloseWindow();
return 0;
}
Website last updated Tue Nov 19 15:52:15 2024 by Thbop.