Thursday 15 June 2017

How I implemented the Stop the Pop Thermometer Health Bar

This page shows how I implemented the thermometer health bar in Stop the Pop!

This is what the health bar looks like in isolation in the editor.



The thermometer is split into 4 images. 
  • Thermometer Overlay
  • White Body
  • Red Body
  • Glow




They are arranged in the inspector like below. The Thermometer was added as a UI Image but the Image component was then removed from the Thermometer. The Glow, WhiteBody, RedBody and ThermometerOverlay are all UI Images. Note that the order of these images in the editor is important otherwise the thermometer will not appear to function correctly.



In the Scene view, it looks like this:


The Thermometer has a ThermometerBehaviour script attached to it and an Animator component. You can find the content of the ThermometerBehaviour script below.

The animator is updated every frame from the script with the current temperature. The animator is set up so if the temperature reaches 0.8, it enables an animation which just scales the thermometer from the original size to a larger size and and back to the original size.




When using the script, the RedBody needs to be attached to the redFill Image reference from the editor.
The Glow Image also needs to be attached to alertGlow reference from the editor.

The percentage of the redFill Image that is shown on screen is controlled by setting redFill.fillAmount. This value needs to be between 0 and 1.

The way script works is that it has a currentFill float. The purpose of using this float to add in a bit of animation when jumping between one temperature value to another. Every frame it lerps between currentFill and currentTemperature.
The script also checks if a temperature threshold has been reached. If the threshold of 0.8f has been reached, the glow is enabled.

External scripts can modify the thermometer by changing the value of currentTemperature of the ThermometerBehaviour script.

using UnityEngine;
using UnityEngine.UI;
using System.Collections;

public class ThermometerBehaviour : MonoBehaviour {

    [Range(0.0f, 1.0f)]
    public float currentTemperature = 0;

    public Image redFill;
    public Image alertGlow;

    float currentFill = 0f;
    float animationSpeed = 5f;    //the speed of the lerp 
    Animator animator;

    void Start() {
        alertGlow.gameObject.SetActive (false);
        animator = GetComponent<Animator> ();
    }

    void Update () {
        //this is purely cosmetic so the fill is always gradually moving and there is no sudden jumps
        currentFill = Mathf.Lerp(currentFill, currentTemperature, Time.deltaTime * animationSpeed);
        if (currentTemperature > 0.8f) {
            alertGlow.gameObject.SetActive (true);
        } else {
            alertGlow.gameObject.SetActive (false);
        }
        animator.SetFloat ("temperature", currentTemperature);
        redFill.fillAmount = currentFill;
    }

    public void Reset() {
        currentTemperature = 0;
        currentFill = 0;
    }
}
  





Wednesday 14 June 2017

Stop the Pop! Popcorn Game Now Released on iOS and Android!

I am proud to announce that Stop the Pop is now available on iOS and Android!





Stop the Pop is a 2D platformer game where you play as a popcorn kernel. You have to help our hero on his adventure through hazardous environments and face strange foes. The aim of the game is to keep your temperature down and stop our hero from popping into popcorn. 

Game Origin

I have been working on Stop the Pop for almost three years! It has been a great journey and I have learned a lot throughout that time. 
I came up with the game by thinking if a popcorn kernel was alive, how would he feel when he turned into popcorn. Since the kernel turns inside out, I thought that the process of popping would be a very traumatic experience. He would got extremely hot and would start to go through a painful transformation of popping. I am a big fan of platform games so I decided to make Stop the Pop a 2D platformer. 

Development

I originally started developing Stop the Pop in libgdx but then I decided to switch to Unity. Libgdx is a great library but I preferred the visual aspect of the Unity inspector. I thought it would be easier to lay out levels in the inspector instead of building a bespoke level editor for libgdx. 
In October 2014, I switched to Unity and within a month I had a prototype up and running. 

Before this project I never created any digital artwork. I seen some amazing demos of drawing tablets so I purchased one. I found the results were not as I would have hoped, mainly due to my inexperience. I started looking into other options and I came across a vector graphics  program. I updated the graphics with this program and I think they look a lot cleaner.

The next big thing I changed was animations. You can see from the sprite sheet below that each pose was drawn. The problem with this was I found that the animations were not very smooth and it would take a lot of images to make the animation smoother. Since I was targeting mobile devices, I needed to keep file sizes small.

I came across an interesting video showing a different way of animating where the limbs and face are different sprites and you use Unity to animate the position and rotation of them. I found this gave a much better result. 

Release

Stop the Pop was released on iPhone and iPad on February 23rd 2017 and Android on March 5th 2017.
If you want to stay up to date with Stop the Pop, you can follow it on Twitter and Facebook.
https://www.facebook.com/stopthepopgame
https://twitter.com/stopthepopgame
http://stopthepopgame.com

How I implemented the Stop the Pop Thermometer Health Bar

This page shows how I implemented the thermometer health bar in Stop the Pop! This is what the health bar looks like in isolation in the e...