How do you generally go about controlling characters?


I’ve been looking around and it seems there’s lots of ways to organize your controller code, and I got thinking: what way do you normally handle code organization and event calling with character controllers? So far I’ve been browsing and seen just piling accept commands into an init function, creating an entire class for making key relationships, etc.

Specifically, nobody tends to write where they’ve put these things in the code, they just include the functions and commands. So how do you organize your controller?


I think that I usually have a “GameObject” class, which handles general “this is a thing in the game” logic–possibly including the general case of movement–and a “Player” class that is a sub-class of that (possibly through one or more intermediate classes). In terms of connecting input to player-character, I think that I usually have my core “Game” class accept input (often through my “KeyMapper” class), and then pass it on to the “Player” class (sometimes via a “Level” class, or similar).

Put another way, the “Game” class accepts input (possibly handled by the “KeyMapper” class), and passes it on to the “Player” class, which is likely a descendant of a general “GameObject” class.

The “Player” object may be stored in a variable of the “Game” object, or in a variable of a “Level” object (if any) that it itself stored in a variable of the “Game” class. Put another way, the “Game” (possibly has a “Level”, which) has a “Player”.

The specifics to tend to vary somewhat from game to game, but that’s the general idea, I think.