Raylib Game Tutorial : Space Invaders using VSCode
Raylib is a fairly new game framework around. While other game engines are aiming to be as simple as possible, Raylib goes the most raw way, coding in C with no fancy interface, no visual helpers, no auto-debugging etc. I’ve checked it with VSCode, I thought why not write a tutorial about it.
Here’s the Game we are going to make.
Setting up Stuffs
Running an Example
Make a copy of the VSCode project folder and rename it SpaceInvaders or something. Open VSCode and choose file – open workspace, and select main.code-workspace inside the folder. Now use Ctrl+Shift+P and type Build, choose Build Task,
Splitting the Game
We are going to split the game into several functions for ease of organizing things. In C, function follows a declaration and a definition later. like this.
Setting up Player
Player is setup using struct. Here we do the movements also.
Main Game Loop
Our main game loop will look like this
Now in the update logic, we check if player press Space to shoot, and update the bullet movements.
Setting up the enemies
Here we setup enemies. Only enemies alive are drawn.
Check Collision of Bullet with Enemy
Check if the rectangle of the bullet cross with the enemy rectangle area. And make it inactive to not draw on the frame next time. inside if(shoot[i].active) code add this code.
Download the sound files from Google Drive. Copy those two files into the game folder. Add the below code and play the game.
Full Tutorial Source Code – Here
Code Previews created with the awesome Carbon Code Editor. Let me know your comments and thoughts.