Raspberry PI Game (2022)

Using Template Custom Engine C++  -  Solo Development  -  8 weeks development time  -  Generalist Programmer - Raspberry PI

In this project, I was tasked with creating a game that could run on a Raspberry PI using a very bare-bones custom engine. This allowed me to develop skills in most areas of game programming:


The thing I am most proud of in this project is the procedural map generation that I maded based on a cellular automata algorithm. Here is some of that code:


int** MapGenerator::CreateMap(int width, int height)

{

    int** tempMap = new int*[width];

    for (int x = 0; x < width; x++)

    {

        tempMap[x] = new int[height];

        for (int y = 0; y < height; y++)

        {

            if ((float(rand() % 100 + 1) / 100.f) < chanceToStartAlive)

            {

                tempMap[x][y] = WALL;

            }

        }

    }

    for (int i = 0; i < numberOfSimulations; i++)

    {

        tempMap = SimulationStep(tempMap, width, height);

    }

    LastStep(tempMap, width, height);

    return tempMap;

}


int MapGenerator::CountAliveNeighbours(int** map, int x, int y, int width, int height)

{

    int count = 0;

    for (int i = -1; i < 2; i++)

    {

        for (int j = -1; j < 2; j++)

        {

            int neighbour_x = x + i;

            int neighbour_y = y + j;

            //If we're looking at the middle point

            if (!(i == 0 && j == 0))

            {

                //In case the index we're looking at is off the edge of the map

                if (neighbour_x < 0 || neighbour_y < 0 || neighbour_x >= width || neighbour_y >= height)

                {

                    count++;

                }

                //Otherwise, a normal check of the neighbour

                else if (map[neighbour_x][neighbour_y] == 1)

                {

                    count++;

                }

            }

        }

    }

    return count;

}


int** MapGenerator::SimulationStep(int** oldMap, int width, int height)

{

    int** newMap = new int*[width];

    //Loop over each row and column of the map

    for (int x = 0; x < width; x++)

    {

        newMap[x] = new int[height];

        for (int y = 0; y < height; y++)

        {

            int nbs = CountAliveNeighbours(oldMap, x, y, width, height);

            //The new value is based on our simulation rules

            if (oldMap[x][y] == 1)//First, if a cell is alive but has too few neighbours, kill it.

            {

                if (nbs < deathLimit)

                {

                    newMap[x][y] = FLOOR;

                }

                else

                {

                    newMap[x][y] = WALL;

                }

            } //Otherwise, if the cell is dead now, check if it has the right number of neighbours to be 'born'

            else

            {

                if (nbs > birthLimit)

                {

                    newMap[x][y] = WALL;

                }

                else

                {

                    newMap[x][y] = FLOOR;

                }

            }

        }

    }

    return newMap;

}


This code is based on Michael Cook's "Generate Random Cave Levels Using Cellular Automata" project. I adapted the code to fit this project and its requirements such as in the LastStep function adding some space in front of the exit doors of the map to make sure the door is always accessible to the player. 


Another feature I am quite proud of is MD2 model loading and animation. I managed to create an MD2 model loader and implemented vertex-based animation using the data from the MD2 models.