Having to time holding down left and then double taping it is an exercise in frustration.
Other than that it looks interesting, I enjoyed the moving platforms.
I enjoyed trying to reach the very top of the test level. Spotted your greeting :)
How does your game draw to the screen?
Not sure what dead weight comes with that as I'm not a C standards pedant, but there's clearly some welcome niceties that don't seem to ruin the language in my experience.
Variable modified types are cool - you can use them to cast a raw pointer to a N times N matrix and the math works out - you can just do m[i][j] instead of m[i*N+j].
But the evil part is when you declare variable length arrays on the stack. There are exactly two possible scenarios - either you have an upper bound on the allocated size or you don't.
If you have an upper bound and it is reasonably small, use a fixed length array on the stack - there is no point in saving a few bytes on the stack.
If you don't have an upper bound, VLAs will blow your stack, given the right inputs.
If you need a way to allocate unbounded arrays in a LIFO pattern, which 99% of the time are tiny, use a dedicated index-incrementing allocator, falling back on malloc when necessary. You can even cast the resulting pointer to a variably modified type, so that sizeof math works out
I'll allow of course that they don't "ruin the language" they just increase the cognitive burden of reading code.
vv = 3f_add(&v, &(3f_t){.x = .1, .y = .2, .z = .3 });
vs. having to declare and name the literal 3f_t beforehand, wasting my time and cluttering up the code with noise.But then, after looking back at my old code, I struggled and crafted my 1SLOC guiding principle. I never looked back.
Wasting time when writing code is actually an investment into future read speed.
I even wrote some time ago about my rationale for 1SLOC https://blog.pwkf.org/2022/09/18/always-optimize-for-dummies...
That said, I absolutely love the pixel art, characters and animation. I think you should leave aside platforming for interactive pixel art rich environments. Kind of like an adventure game but extremely interactive? Say maybe you could pick up flasks and mix potions to do things, and the environment could be reactive as well. I think that would be much more interesting and unique (I'd love to play it anyways :) ).
....why? A significant chunk of commercial games released were done in C (maybe not 'straight", as they might plug into Lua or Python); and probably the majority of open source games were.
C is fairly straightforward to develop games in, and is one of the realms it excels in; so I have no idea why you'd feel this way.
Many, if not most, are C++ with scripting. If you’re working on something that doesn’t need scripting, pure C is totally fine.
When I started writing my first C game, I used C89 too. However, after some time I realized that C89's limitations don't make my code cleaner at all and just make it more annoying to write. Since most of those games are game jam projects written under extreme time pressure, it made absolutely no sense for the language to pester me with pointless things like variable declarations outside of for loops or lack of designated initializers, so my toolkit uses C99 now. Initially I also made some use of nested functions, but I disable GNU extensions these days too.
Now I have about 40 games written on top of that codebase, a few of them being bigger projects. I've ended up with an "engine" of sorts that I have never really written - I've been always writing games and only then abstracted things away that actually begged to be abstracted. It did grew some fancy features and abstractions over years of using it, but not every game benefits from using them, so they're completely optional. In its essence it's mostly just a toolbox with handy things I find useful when writing the sort of games I usually write. Writing a game is essentially just filling up functions that update its state based on input and passing time, and that render an image based on that state. For many simple games, that's exactly the abstraction level they need.
I've often seen people making big eyes after being told that I use C to write games in < 48h at game jams - and yet I never really felt disadvantaged when compared to other teams that used big and fancy ready-made engines. Sure, there are kinds of games where I'd use a big engine like Godot too, but... most of those games aren't that kind :) Keeping things simple actually helps, especially where what you need is being able to jump straight into implementation instead of having to think about how to fit your ideas into whatever abstractions you ended up with due to your framework of choice.
I feel like designated initialisers can be circumvented by simply assigning the fields individually. It’s a bit more verbose, but I feel like it works almost as well, the biggest downside being that the compiler won’t warn you if you miss some.
Regarding loops and variables, I opted for just declaring all variables at the top of each function definiton (only using an initialiser for ‘static’ variables), which I find almost reminds me of how Python handles variables, except with a chunk of declarations at the start of each function.
Of course, this is all subjective, but I find this style looks neat, and I don’t think it gets in my way at all, personally.
Note: I freaking love C and often defend/advocate it here and elsewhere. I just don't understand why anyone would choose a more limited version. Artistic expression? Something something limitations something creativity?
Another comment posted that you would have to be "a madman" to code a game in C, and I was genuinely baffled. Gamedev is one of the realms C truly excels in and is actually relatively easy. Once you're used to it, and know the boilerplate that needs to be hoisted, it's not particularly difficult or time consuming.
It's weird to me that (I assume, at least) professional developers still have this weird mysticism over C as if it's just arcane incantations compared to what they do.
I don't think anything needs to change with the controls, the people saying that aren't the audience and don't have the genre literacy to know what this type of control setup is doing(for those watching: Jump King, Getting Over It both have the same kind of ruthless difficulty).
Regarding the technology, it's healthy to simplify the architecture - I've played a lot with the same kinds of thought processes of adding a lot of abstraction and gradually moved towards simpler answers. You already have a lot of answers that work, but my own take is that games of this type and scale need, roughly, these pieces:
* A "god object" entity model(every entity is one struct containing all necessary state for all possible behaviors). Going beyond that adds memory savings that you don't need for modern machines, or modularity that will introduce more to debug.
* State machine formalisms to describe what screen to draw, how to transition between them, what animations to play, and other behaviors. All control flow logic encompasses the behavior of a state machine, so you have to decide which formalism is best to use for the context and will aid debugging. That's why people sometimes gravitate towards coroutines and other high-level abstractions. Simple "scripting languages" that just describe a sequence of opcodes are something that frequently appear in old games.
* A simple constraint solver for the platforming physics. The problem that all physics systems have to solve is "there are multiple possible solutions that will resolve this motion: which one is the best?" This tends to be obfuscated in platforming physics by a convention of throwing away information about potential solutions early(e.g. moving on the x axis and resolving collision there, then doing the same on the y axis). Instead I recommend breaking down the motion into multiple permutations of "x then y" vs "y then x", then sorting and ranking the outcomes relative to a heuristic of unimpeded free movement. It's a more expensive check that also gives a better-feeling result.
* A pipeline to load the graphics, collision and scene assets. Although you can hard-code a lot of these things in a simple game, it can be convenient to export them from a spreadsheet and make it data-driven. Things like describing what "chapter 1" is are basically asset problems. I noticed that you have dialogue boxes described with a tileset and code to draw the tiles. This is how I would have done things once, since it is "how they used to do it" - today I would be likely to turn everything at runtime into an image, and to build the text itself, compile pre-baked images of text in the build process using tools like imagemagick. That makes the runtime simpler and reduces the kinds of assets it tracks, while allowing total freedom with the content of dialogues.
Sometimes with these projects, the engine development is being used to avoid content work. I suggest a physical graph paper notebook to create a location for that content to be designed, and to engage in some blind contour sketching to warm up to doing anything visually-oriented. When you have a whole storyboard for the game it becomes easier to conceptualize what code is necessary to get the effect, and do exactly that instead of generalizing it.
Two commercial "back in the day" games I would also look at for more inspiration: Xargon, Little Big Adventure 1. Both written in C, original source code is available. Studying those will give you a sense of where you are relative to finished work.
Yes, that’s exactly the kind of thing I was going for! Though I will say: I feel like my controls, although difficult at first, are easier to get used to than either of those two, or at least they were to me. After a while playing with the game, you “get the hang of it” so to say, and it starts feeling more natural.
Also, thank you for your advice! I have some thoughts/questions about some of it:
> Things like describing what "chapter 1" is are basically asset problems.
Well, my current solution is to encode the different “assets” (chapters, characters, images) as source code, and link them with the rest of the game at compile time. The biggest benefit is that I end up with a single executable that is easy to run, and don’t need to bother loading assets at runtime. To me, it doesn’t seem to matter ultimately whether I store information about how a chapter should play out as plain data or as code, and making it code seems simpler insofar.
Though a lot of the assets the game uses (e.g. the dialogue boxes you mentioned) are generated during intialisation, and then just displayed as a set of images during gameplay. Effectively, it shifts some “during build” work to “when the game starts”. The benefits include a simpler build system and fewer required build dependencies, besides being more straight‐forward to work with.
> A simple constraint solver for the platforming physics.
I don’t think I fully understand what you mean by this. Are you saying you feel like it would be better to avoid performing collision checks in order of axis? I.e. that it would make more sense to perform the checks in conjunction somehow?
One of my friends encouraged me to post about it here, since he felt people might find interesting how I don’t use any libraries for it.
The game can be played on a browser by virtue of WebAssembly. There are native ports using either MiniFB or SDL2, but you have to build those yourself.
I decided to write the game in C because I feel like it is a simple language that a lot of people can understand well enough, and I didn’t think I needed anything more involved or complicated.
Over time, the game’s code became complicated, and I decided to use advanced features such as coroutines and higher order procedures, besides general overly engineered abstractions.
But then, over time I grew to feel like a lot of those abstractions didn’t really add anything to it, and just made it more complicated (and oftentimes more buggy) than it really needed to be, so a few weeks ago, I made a significant refactoring to it to remove all of those abstractions without removing almost any features from the game.
Milestones are released effectively whenever I get the game’s code to a decently presentable state. Sometimes, this means there are a lot of changes and big refactorings, but sometimes it means there are only a few small changes.
The game uses a simple 2D model system to generate images for the character’s animations dynamically during initialisation. (The source code can be browsed using a web browser on its page.)
The character can be controlled using the arrow keys or “WASD” (“A” and “D”) (double-tap a direction to jump).