When Life Gives You Lemmings

audacity

When Life Gives You Lemmings is a small rhythm game inspired by simple navigation games like “Crossy Road” and “Froger”. Lead your lemmings as far as you can. And as they always say “When life gives you lemmings, make lemming-parade”…

When Life Gives You Lemmings was a collaborative effort I took part in along with two artists during the Summer Melon Jam 2024. The theme for the gamejam was “Flow” and the team decided to go for a rhythm game. I did all the programming for the game as well as some of the audio editing. Below I’ve highlighted a couple things from the gamejam that I was proud of.

Rhythm Management

The core challenge of making a rhythm game is trying to sync up the game with the beat of a song. While you would assume that just knowing the bpm and having a timer going would be enough, that isn’t the case. This is because small slow downs add up over time. To fix this you must manage the rhythm yourself and track where in the song you are. The code to the right is my implementation of that as well as code to speed up the song after a full loop is complete.

C#
				// Update is called once per frame
    void Update()
    {
        int trackTime = (int)(audioSource.timeSamples / (frequency));

        //checking for track reset
        if (trackTime == 0 && trackTime != lastTrackTime)
        {
            //changing speed
            speed += speedIncrement; //change recoreded speed (used in other scripts)
            mixerPitch -= speedIncrement/2; //change mixer pitch
            audioSource.pitch = speed; //set new source pitch
            audioMixer.SetFloat("MixerLevelPitch", mixerPitch); //set new mixer pitchs

            //update speeds
            CalcAnimTime();
            playerController.calcTimings(speed);

        }

        audioMixer.GetFloat("MixerLevelPitch", out mixerPitch);

        if (trackTime != lastTrackTime)
        {
            lastTrackTime = trackTime;
        }

        //send signals to rhythm based events
        foreach (RhythmEvent rhythmEvent in rhythmEvents)
        {
            float sampledTime = audioSource.timeSamples / (frequency * rhythmEvent.GetIntervalLength(tempo));
            rhythmEvent.CheckForNewInterval(sampledTime);
        }
    }
			

Unity Events

When Life Gives You Lemmings was my first time heavily using Unity’s event system. Though the implementation is a bit simplistic, it let me call events at different times while synchronized with rhythm calls from the game manager.

C#
				[System.Serializable]
public class RhythmEvent
{
    [SerializeField] private int every_X_beats;
    [SerializeField] private UnityEvent triggers;
    private int lastInterval;

    /// <summary>
    /// Accessor method that returns the length in seconds in between triggers of event
    /// </summary>
    /// <param name="bpm">the beats per minute of the song the interval is tied to</param>
    /// <returns>length in seconds in between triggers of event</returns>
    public float GetIntervalLength(int bpm)
    {
        return 60f / (bpm * (1f / every_X_beats));
    }

    public void CheckForNewInterval(float interval)
    {
        if (Mathf.FloorToInt(interval) != lastInterval)
        {
            lastInterval = Mathf.FloorToInt(interval);
            triggers.Invoke();
        }
    }
}
			
Scroll to Top