SDL Project

This is a university project I worked on for the Games Engine Cretion module between February and May 2023. We were tasked with recreating the original Mario Bros using C++ and SDL2 whilst also creating a second level using what we had learnt from the first. I implemented the minimum requirements of rendering sprites, playing music and sound effects, using bounding box/circle collision and having a game screen manager while also adding dynamic level loading from a text file, scrolling screen functionality, high score tables stored in a text file and projectiles.

Game Screen Manager

One of the problems I encountered was swapping between screens in my game while properly handling memory. I handled this by making each screen in the game a child of the GameScreen class which has a virtual deconstructor so that the screens can be properly deleted. It took me a while to figure out the right approach to this partly because the game still functioned even if the screens were not being deleted properly, there were just some issues with music but the memory leak made it clear that a different approach had to be taken. I struggled at first to not get errors due to classes being deleted which others were dependent on. This was a good thing however; it forced me to cleanup the structure of my project and resulted in a better running final game with fewer bugs.

Dynamic Level Loading

The levels in my game are dynamically loaded from a text file, this includes the placement of tiles. Despite only making two levels, this set up means I can create many levels with relative ease and edit them quickly too without ever having to go and alter any code. I achieved this by having a text file be read into the program and placing tiles in the necessary places based off of this. If I had more time to spend on this project I would expand the level editor so as to not require the editing of text files directly but for the purpose of this project and the time restraints imposed I found this to work well.

This is an example of one of the level text files:

And this is how the levels are created:

      //load level map from file
      std::ifstream inFile;"Levels/Level2.txt", std::ios::in);
      int temp_num;
      int map[MAP_HEIGHT][MAP_WIDTH];
      if (inFile.is_open())
        for (int i = 0; i < MAP_HEIGHT; i++)
          for (int j = 0; j < MAP_WIDTH; j++)
            inFile >> temp_num;
            map[i][j] = temp_num;
      int rows = sizeof map / sizeof map[0];
      int cols = sizeof map[0] / sizeof(int);
      //populate level map
      for ( int i = 0; i < rows; i++)
        for (int j = 0; j < cols; j++)
          if (map[i][j] == 1)
            Vector2D* pos = new Vector2D((static_cast(j* TILE_WIDTH)),(static_cast(i * TILE_HEIGHT)));
      //clear old maps
      if (m_level_map != nullptr)
        delete m_level_map;
      m_level_map = new LevelMap(map);

Who Did What?

All Mario Sprites supplied by Staffordshire University

Pixel Art-Cat Doing Some Stuff by Spring Spring

Bat Sprite by bagzie

Background by jkjkke

Outdoor 32x32 tileset by Buch

When Was it Made?

The prototype was worked on from February 2023 to May 2023 for the Games Engine Creation module at Staffs Uni.

What Went Well?

I completed the goal set out for me to build a minimal game engine using SDL2 and create 2 levels inside of it, one of which being a Mario clone. On top of this, I added dynamic level loading, animated chararcters, a scrolling screen and new characters and design. The levels are both functional, fun to play and with goals to complete in them.

What Could Be Better?

With the knowledge I've gained and with more time I would improve the game's animation system as it is very simplistic and creates many visual and collision bugs which I have been able to somewhat work around for this version but it is completely rigid and would need to be completely redone if this were to be a general use engine. I would also add more enemies and platforming challenges to make the game more interesting, as well as tweaking the games physics so that they are more engaging.


Social Media


Rhys Elliott 2023.