Sign in to follow this  

Unity Please help. Programming in C with SDL.

This topic is 4249 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm trying to make a game in C using SDL. I have no clue how to implement an entity system and there seems to be no resources/tutorials that cover C. There are many SDL ones that cover Python, Java, C++, but not C. Can anyone please direct me to some tutorial, source code, or community that focuses on C and SDL? Thanks.

Share this post


Link to post
Share on other sites
Entities are almost by definition objects, so it will be quite ugly to write an entity system in C. However, you can substitute wherever you see a design pattern thus in an OO language (pseudo-code, some example stuff that might be in an entity):
class Entity {
Vector position, speed;

bool CollidesWith(Entity target);
void Render(Renderer target);
}


... with some C:
typedef struct {
// Fields go in here
Vector position, speed;
} entity_t;
typedef entity_t* entity_p;

// 'Methods', and property accessers, become
// C functions. Notice how the first parameter
// becomes the 'this' object, i.e.
// ent.Method(p1, p2) -> Entity_Method(ent, p1, p2)
bool Entity_CollidesWith(entity_p this, entity_p target){
...
}

// References to other 'objects' in your game probably
// become function pointers
typedef void()* render_func; // syntax may be wrong!
void Entity_Render(entity_p this, render_func f){ ... }


Check out the Quake II source code, which I believe is basically straight up C, for a proper game with entity code done this way. I still think it's shoehorning an OO problem into a non-OO language and you'd be better off switching, though.

Share this post


Link to post
Share on other sites

This topic is 4249 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this