top of page
Top 2

Gotrek Engine (2D Game Engine) SDL2

github_git_hub_logo_icon_132878.png

Overview

I'm currently building a 2D Game Engine utilizing SDL2 as a tool for learning low level C++. This project aims to provide a Game Development Framework for personal use of creating 2D games. for learning purposes.

It's current state consists of being able to:

- Manage Rendering of "objects" through a RenderManager class

- Manage loading and unloading of Texture through a TextureManager class

- Create and render text objects

- Load Clickable buttons which get data from a Sprite Sheet

- Timer class which can be instantiated to measure time passed in frames

- Various other misc functionality e.g. output (logging) class, shape class (rendering primitive shapes on screen) game settings (handle preset game settings to be used e.g. screen size etc)

I'm really proud of the RenderManager.cpp and Rendering system so far, the RenderManager has static functionality allowing for rendering from anywhere, where it holds lists of all objects required for rendering that are derived from a RenderableObject.cpp class.

image.png

RenderManager.cpp

Each object that requires any form of rendering inherits from the RenderableObject.cpp class thus not requiring repeat definitions and functions inside of classes that require rendering when the RenderManager needs to get that render data.

image.png

RenderableObject.cpp

image.png

RenderableObject.cpp

The images below show the Button.cpp class, which is used for button functionality, it is derived from the RenderableObject class, and only has to pass the render on instantiation for the render data to be correctly stored in the RenderableObject base class.

image.png

Button.h

image.png

Button.cpp

The Button class sets some additional values in the RenderableObject.cpp, unlike other classes requiring rendering, Buttons use sprite sheets to cut a piece of the texture to render, therfore it reassigns the render data srcRect variables based upon the buttonStatus, defined as an Enum.

image.png

Button.cpp

image.png

As a bonus because this is exciting! The spriteSheetRects vector that it gets a new SDL_Rect value for the srcRect of what to render from the texture is from a SpriteSheet class which gets passed into the Button class on creation. (See below)

image.png
image.png

Game::Init (Where everything is currently initialized)

As a bonus because this is exciting! The spriteSheetRects vector that it gets a new SDL_Rect value for the srcRect of what to render from the texture is from a SpriteSheet class which gets passed into the Button class on creation. (See below)

(Left)The SpriteSheet class takes in x,y,w,h as based on what sprite sheet you pass in, it allows you to define the dimensions of each segment of the texture sheet!

 

It's setup for 4 image based sprite sheets (predominantly for testing) to be used with Buttons and eventually other objects, like gameobjects and art assets hence the vector<SDL_Rect> size of 4. Though this will be reworked later to work with sprite sheet columns and rows etc

SpriteSheet.cpp

Thanks for checking out the RenderManager, I'm also super proud of the TextureManager class too so check that out and have a snoop on the Github project at other stuff. More to come!

bottom of page