This is my first developer journal here and I am excited to get started! School just got out for me and after spending the year researching design patterns and frameworks for making games, I've decided my summer goal is to make a very basic geometric platformer. First things first however, I need to make the framework my games will be using. I've decided to use C++ with SFML as my A/V library and Box2D for physics. (I chose these because all three are super intuitive to code with/in, IMO) After finishing my framework, I'll test it out with a quick demo of Pong with a menu and multiple levels. The rest of this post is going to be dedicated to how I'm designing my framework, and the details and issues associated with my design.
The Game Class
There will be a main "Game" class that I initialize in the main function that takes the first "Scene" as an arguement, it automatically updates your "Scenes" (more on these later) and renders them, according to the methods contained within those scenes, with a reference to the Game class itself as the argument for all these methods. The Game class will manage the Scenes, and contains the main loop, for updating and rendering and all that stuff. The Game class will have a list of scenes, loaded and unloaded. The reason for this being that I don't want to load all my scenes at once, especially considering the way I'm going to be doing the loading. The reason for them all being in a list is because I'm lazy and don't want to have to keep track of whether my Scenes are in scope or not at the moment, and as long as the Game class exists so will the lists, so once I add my scene to the list I can let it go out of scope. (In the initialize method is where I'll want to define all of my scenes and stuff, but since they won't be loaded it hopefully won't take that much time) Each "Scene" contains a list of "GameObject" classes which is just an extension of sf::Sprite with some added functionality. (Like having its own update and render function, to be called by the Scene it is in by that Scene's update and render function, it is meant to be extended to create your own objects) For a LevelScene, there will also be an associated two images, which when the scene is loaded in game, the images' pixels will be read, and depending on the RGBA values of each pixel, an object will be placed in the "tile" where that pixel is located in game. This is my rudimentary system for level design, the reason for two images is that one image will contain on the objects in the foreground that interact with one another, while the other contains all the background objects that generally don't interact with the player. Some problems with this, the game and the scene classes own a list of objects, I have no way of knowing which object is which, so each object in the list will have an associated string name with it, so you can delete and switch to scenes based on the string name. This also applies to the Texture Atlas below, by me extending sf::Texture and simply adding a string name to the new Texture class. I'm pretty sure this isn't the best way to do things and if anyone has any advice on a better way to sort my objects, feel free to comment!
The Texture Atlas
SFML Sprites require a reference to a Texture object. So you have to manage the memory of all your textures. The Texture Atlas will do this for me by simply adding a texture to its list, and being initialized by the Game class so that the Texture Atlas class stays in scope, and thus so does the Textures. The Game class will have a function to retrieve the Texture Atlas, (since I have to initialize it in the game class). And then you can use the Texture Atlas to assign textures to sprite, consistently re-using preloaded ones since you'll only have to load any image you use once!
That's all that I can think of for now, if you have any advice/suggestions/feedback, feel free to tell me! I'm always open-minded to new ways of doing things and I appreciate that I am largely new in the area of serious game making and would love for a more experienced person to tell me what I'm doing wrong! (I've definitely coded games in the past, but from a code perspective they absolutely sucked, this will be my first attempt at "serious" coding) I'll be adding more to this journal as I find and solve problems within my framework and add stuff to it. (I am definitely adding things to it, I understand that it is very basic and simple right now.) I'm keeping this journal as a sort of design document to write down my ideas and force myself to work on the framework. I apologize for the rambly nature of this journal and I hope you will all bear with me as I get better! Thanks for reading and I hope this wasn't a complete waste of time!