2D physics game programming in C, retro style | Gamedev the hard way #2

preview_player
Показать описание
Join me on a journey as I attempt to write a game for my Agon Light using nothing but raw C programming. In this second episode I figure out how to make a very basic 2D rigid body physics system work.

It doesn't matter if you don't have an Agon Light, I'm bringing you along for the ride. We'll be looking at how games deal with the objects they manipulate, and how to detect and resolve collisions in 2D.

The code for my game library that I'm building is available here

A longer writeup of the game and my ideas is available here

If you like this nonsense, consider supporting the channel

#linux #programming #gamedev #agon #z80 #cprogramming
Рекомендации по теме
Комментарии
Автор

Your videos are very well made, high quality stuff. Love the topic too! Nice to go with C. Easy to learn, hard to master but very satisfying indeed. Great shirt too! Keep at it and all the best from across the channel here in Belgium.

michaelsmith
Автор

Awesome! Looking forward to the next video!

charlesdorval
Автор

Your previous video inspired me to write a C++ compile time game screens data table that stores screen names, and assigns each one a numeric id based on an enum value. Thanks!

PaulMetalhero
Автор

I think I was one of the people who subscribed because of the last video but I could be wrong. I think I also left a comment but I already forgot what it was about. I'm looking forward to your next video. ❤

Nice_G
Автор

I also love the KDE editor, although my programming knowledge is strictly limited to the assembly language for the Z80, to be specific. Although I must also confess that assembler was the only language that I was able to assimilate until now at 60 years of age. Regarding your creation, the movement of the sprites in your game reminds me a lot of the game "Asteroids" and "Bosconian", among others. I sincerely congratulate all your videos and the love you profess for programming but, above all, for the generosity you show when sharing your knowledge. I send you cordial greetings from Chile, hoping that you can excuse me for my horrible English.

RobertoAlexFigueroa
Автор

Interesting idea, storing 1/mass instead of the mass, so that infinite masses of unmovable objects get represented as zero. Cool stuff.

HeatDeath
Автор

omg this is so exciting that this just came out but i'm not here yet..
i've been trying to see if i could get the emulator working or a virtual machine for the agon operating system. failing on all fronts.. i'm actually thinking about just getting one of those machines so i can learn this.. THIS is SO what i want to learn.. its killing me that i havent got to program anything since watching your video yesterday!!! i'm about to have to do some cpp just so i dont explode over here.

burntt
Автор

Thanks im learning c atm and this is so motivational

Hyintek
Автор

Great video, we both play the same games on Steam

mr_noodler
Автор

Great video! I just wish you were still using the Spectrum Next/N-Go.

stephenelliott
Автор

I didn't subscribe because of your last video. I subscribed because I looked through all of your videos. I studied CS because I enjoy the science of computing, not being a code monkey.

jamestaylor
Автор

One of the things I think is pretty cool about how you do your videos is that you use Kate as your IDE. It's amazing how many changes they've made to the program over the years and if I weren't so entrenched in using Vim, plus the myriad keybindings that allow me to navigate entirely with just the home row, I'd probably be using it too. I've got my Konsole setup to basically just be a black box, and use tabs with Vim. Do you have shortcut keys setup with KDE to push windows into tile positions? I've found that to be one of the best set of shortcut keys I could use, especially when manipulating multiple terminal windows.

anon_y_mousse
Автор

One of the things which will come up is when an object moves so fast that it will pass all the way through another object in a single frame, thus there being no overlap to find. So, it requires some kind of backward computation along the delta vector to see if indeed it would have collided.

RockTo
Автор

Another superlative video. I wish that you had been my CompSci teacher at school - I'd have got on a lot better than the people we did have who saw giving students access to coding tools as being dangerous..you might write executable code to the hard drive of the machine and cause things to happen!

The debug screen that you have - does that write the logged text to disk? I ask because if I wedge the machine doing something stupid and I can't then access any debug screen, I can't see what caused it. So a disk log is useful. Also, it might be interesting to compare and contast when you've finished the hard way to do this project in something like Godot 4 and show how much easier this would be given the tools that exist for doing exactly this kind of project...! :)

arronshutt
Автор

I see that you use a _lot_ of conditional code statements and branching. Have you check the instruction overhead in disassembly for things like the fixed point mul and div?

RockTo
Автор

Line 134 in physics.c will be true if overlapX is equal to overlapY, and therefore set your collision_normal vector's y value. Same issue at 148.

RockTo
Автор

I don’t know anything about the machine you’re emulating or will be running it on, I heard you say it was z80 based with some extra microcontroller goodness, does it have a UART so you can output debug that way?

osogrande
Автор

did you read the comment on gamedev blog #1 I've left a couple weeks ago (it's still on moderation stage). I wrote a Cyberoseum arena shooter concent for you.

DenisTrebushnikov
Автор

7:34 : Won't there be a lot of cache misses with those collision_mask values? It looks like they might be scattered around the heap. (Although I guess that isn't much of a concern on a Z80.)

RockTo
Автор

Why do you say nested for loops should not be done?

RockTo