Space Scavenger

This is a endless runner. You steer a space ship while dodging meteorites. You need to get as far as possible. There is also an enemy spaceship that shoots bullets at you which you also have to dodge. If you get hit, you lose.

You can also collect blue scrap. With collected scrap you can buy upgrades at the shops in space for your ship.

Next to acting as team lead for this project, I coded the scrap grappling hook, meteorites generation, the enemy spaceship and object spawn handler. Also I designed the environment lighting, shadows and background movement.

Object pool

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

/// <summary>
/// A simple class that can create multiple objectpools
/// </summary>
public class ObjectPool : Singleton<ObjectPool>
{
    // Class that holds a objectPool
    [Serializable]
    public class ActiveAndInActive
    {
        public List<GameObject> Active = new List<GameObject>();
        public Queue<GameObject> InActive = new Queue<GameObject>();
        public GameObject Holder;
    }

    // Holds all the objectpools. every object pool has a tag 
    public Dictionary<string, ActiveAndInActive> ObjectPoolDic = new Dictionary<string, ActiveAndInActive>();

    // The main function that Spawns A Prefab with a string as tag to 
    public GameObject SpawnPrefab(string poolTag, GameObject prefab, Vector3 spawnLocation)
    {
        // Creates a new objectpool if it doesn't exists
        if (!ObjectPoolDic.ContainsKey(poolTag))
        {
            ObjectPoolDic[poolTag] = new ActiveAndInActive();
            ObjectPoolDic[poolTag].Holder = new GameObject($"{poolTag}s");
        }

        // If we don't have any InActive objects we spawn a new one
        if (ObjectPoolDic[poolTag].InActive.Count == 0)
        {
            var newPrefab = Instantiate(prefab, spawnLocation, Quaternion.identity);
            newPrefab.transform.parent = ObjectPoolDic[poolTag].Holder.transform;
            ObjectPoolDic[poolTag].Active.Add(newPrefab);
            return newPrefab;
        }
        // If we do have a InActive object we spawn it in
        else
        {
            var OldPrefab = ObjectPoolDic[poolTag].InActive.Dequeue();
            ObjectPoolDic[poolTag].Active.Add(OldPrefab);
            OldPrefab.SetActive(true);
            OldPrefab.transform.position = spawnLocation;
            return OldPrefab;
        }
    }

    public GameObject deActivedPrefab(string poolTag, GameObject sceneobject)
    {
        // Check if there was a ObjectPool with this tag
        if (!ObjectPoolDic.ContainsKey(poolTag))
        {
            Debug.LogError("prefab was never spawned");
            return null;
        }

        // Checks if the object exists in the pool
        if(!ObjectPoolDic[poolTag].Active.Contains(sceneobject)) return null;
        
        // Put it back in the queue and deActive it
        ObjectPoolDic[poolTag].Active.Remove(sceneobject);
        ObjectPoolDic[poolTag].InActive.Enqueue(sceneobject);
        sceneobject.SetActive(false);
        
        return sceneobject;
    }
}

I wrote this really simple object pool. It recycles already spawned objects out of sight. I use this object pool for the meteorites. I am proud of this implementation because it has few lines of code. Also the API is very simple: just two functions to create an object and to delete an object.

Team: 2 developers, 2 artists
Type: School project (graded 8,5 out of 10)

https://gitlab.glu.nl/200609/endless_runner

2021 Feb – 17 maart 2021