Skip to content

Commit e912d43

Browse files
committed
New post about raylib game in c
1 parent 47062e6 commit e912d43

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
+++
2+
title = "Building a Game in C"
3+
description = "Building a game in C with raylib library"
4+
5+
# [extra]
6+
# [extra.shared]
7+
# LinkedIn = ""
8+
# Reddit = ""
9+
+++
10+
11+
After diving into Assembly programming, which I mention in my previous post, and gaining a better understanding of the basics of how programs work on a lower level.
12+
I decided it was time to move one level up and get some experience with [C][c_lang]. So I built a micro game as my first
13+
project.
14+
15+
Some interesting points about C programming:
16+
17+
1. C was first released in 1972. The latest stable release was in 2024 (C23), but it seems most projects are still using C99 from 1999.
18+
2. The [standard library][c_std_lib] is quite minimal. For instance, there is no built-in http server, you either need to build it
19+
from scratch or rely on an external library. Typing and data structures are also minimal. For example,
20+
there is no dynamic resizable arrays (a.k.a. vector), so once again, you either need to implement them yourself or use an external library.
21+
3. No garbage collector. For memory stored in the stack, the compiler takes care of managing the memory automatically. However,
22+
dynamic memory, which is stored in the heap, must be managed manually using functions like `malloc`, `realloc`, and `free`.
23+
24+
Some engineers might consider those points a drawback. However they also can be an advantage depending on your goal.
25+
Based on the previous points:
26+
27+
1. Most projects still using C99 because it is good enough for what they need. It also keeps compatibility with wider range of other projects that are on C99 too.
28+
2. A minimal standard library is a good thing for those looking to build a small library/program. For instance, many projects using C run on
29+
embedded systems, and even the standard library could be something they don't need. For more reasons,
30+
check out [this Reddit thread][reddit_c_std_lib].
31+
3. No garbage collector running on a program means less overhead, as the memory management where data is allocated and
32+
free is known at compile time.
33+
34+
About the game, it uses [raylib][raylib], a simple library which makes programming video games quite enjoyable. Basically, the game engine works by
35+
re-drawing elements (e.g. pixel, shape, texture, and etc.) on every frame update. On each new frame, the screen is clean and
36+
the re-drawn happens again, reflecting the current state of the game, such as a character moving or reacting to
37+
collisions.
38+
39+
In addition to rendering graphics, the game also includes sound effects, making the experience more engaging.
40+
41+
Although the game was written in C, it targets both Desktop and Web platforms. The web version compiled to WebAssembly and can be
42+
played online at [maxclaus.itch.io/falling-world][game_url].
43+
44+
Check out the [source code][repo_url] of the game if you are interested.
45+
46+
At the end, I found super cool coding it in C, and working with dynamic memory allocation was particular interesting. I am excited
47+
to experiment more with C in future side projects.
48+
49+
[c_lang]: https://en.wikipedia.org/wiki/C_(programming_language)
50+
[raylib]: https://www.raylib.com/
51+
[c_std_lib]: https://en.wikipedia.org/wiki/C_standard_library
52+
[reddit_c_std_lib]: https://www.reddit.com/r/C_Programming/comments/iqtvde/why_are_data_structures_not_part_of_the_standard/
53+
[game_url]: https://maxclaus.itch.io/falling-world
54+
[repo_url]: https://github.com/maxclaus/raylib-game

0 commit comments

Comments
 (0)