Wednesday, 14 March 2018

Modules with procedures

Experiences so far from a procedural C++ game project have been somewhat interesting. It's divided into modules which at the moment are Datatype, File, Function (for generic functions), Gui and the main module. Most of the code is in the Gui as you would expect. What I have learned is that procedural code seems to be "shorter" than writing classes, but it looks strangely messy. Maybe it's just that I don't quite know how to write clean looking procedural code.

Another interesting part is the Datatype class where I made a decision to use inheritance which may sound weird in this context. I'm using as much inheritance as I can, for example Rectangle class inherits from both Point and Size classes. And I have a feeling this is how I should have done this in the first place in my other projects as well. Using inheritance in this kind of limited context is easy and doesn't seem to have any problems this far. I had to name generic "Set" functions for Point to "Locate" and for Size "Resize" which is I guess better way to describe them. Using inheritance avoids repeating type of data and code for datatypes.

The graphics engine which is less than 300 lines of code in Gui can already display everything it needs: background tiles and letters with different colors. The next step could be the division of screen to three areas: gameview, message window and stats window.

No comments: