2. Game Information
This a 2D game where we must control a
bird and avoid all the obstacles, like col-
umns and spikes, also we earn some score
every time that we cross a column. Is im-
portant to notice that we will die immedi-
ately if we touch any object on the screen..
3. Characteristics
Design
The first step was to create the environment: I put the columns in the top
and Bottom of the screen, I added the floor and the spikes, these last
ones were an invention of my own in order to make the game harder.
The second step was create the sprites of the main character "hero" and program-
ming the animation using the Unity Animator feature for every sprite : Fly, stand by
and dead.
4. Characteristics
Programming
This section has the scripts that allow the game work properly, a lot of the "methods"
and variables have their names in "Spanish" Because this game is initially intended
for Spanish-Speakers users, but the functions, logic, and content of the script are in
English. Also its important to said that each scrip has a brief description about what it
does.
Main Character
This script controls the up- force applied to the rigid body in the bird script, also
check if our "hero" have touches any object in the screen, if this is the case, will stop
the game and will shows the "game over" massage .
public class Bird : MonoBehaviour {
private bool isdead;
private Rigidbody2D rd2;
private Animator anim;
public float upforce= 200f;
public birdrotate rotatebird;
void Awake ()
{
rd2 = GetComponent<Rigidbody2D>();
anim = GetComponent<Animator> ();
}
// Update is called once per frame
void Update ()
{
if (isdead) return;
{
if (Input.GetMouseButtonDown(0))
{
5. Characteristics
rd2.velocity = Vector2.zero;
rd2.AddForce(new Vector2 (0,upforce));
anim.SetTrigger ("flap");
soundsystem.referencia.playfly ();
}
}
}
void OnCollisionEnter2D(Collision2D collision)
{
isdead = true;
anim.SetTrigger ("dead");
controladorjuego.referencia.birdie ();
soundsystem.referencia.playdead ();
rotatebird.enabled = false;
}
}
Game controller
This scripts have the methods that determine what should happend if the bird
touches an object (Will die), if the bird crosses between two columns ( in this case
will add score to the game score) and also destroy the game objects that out the
main screen in order to clean the memory resources.
public class controladorjuego : MonoBehaviour {
public static controladorjuego referencia;
public GameObject gameovertext;
public bool gameover;
public float scrollspeed = -1.5f;
private int valuescore;
public Text scoretextvalue;
void Awake()
{
controladorjuego.referencia = this;
if (controladorjuego.referencia == null)
{
controladorjuego.referencia = this;
}
else if (controladorjuego.referencia != this)
6. Characteristics
{
Destroy (gameObject);
Debug.LogWarning("Este objeto ha sido instanciado por segunda vez ¡error!");
}
}
public void birdscore()
{
if (gameover)return;
{
valuescore=valuescore+10;
scoretextvalue.text = "Score: " + valuescore;
soundsystem.referencia.playpoint ();
}
}
public void birdie()
{
gameovertext.SetActive (true);
gameover=true;
}
private void OnDestroy()
{
if (controladorjuego.referencia == this)
{
controladorjuego.referencia = null;
}
}
}
}
7. Characteristics
Column Behavior
This script controls when and where the columns should be spawned, also has the
call to the methods in the "Gamecontroller Script" in order to determinate what
would happen if they touch the bird
public class columns : MonoBehaviour {
private void OnTriggerEnter2D(Collider2D collider)
{
if (collider.CompareTag ("Player"))
{
controladorjuego.referencia.birdscore ();
}
}
ublic int canticolumnas = 5;
public GameObject columprefab;
private GameObject [] columnas;
private float columnymax= 1.3f;
private float columnymin=1.4f;
private float columnx=9f;
private Vector2 posicioncolumnas = new Vector2 (-13, 0);
private float timelastcolumn;
public float columnspawnrate;
private int columnactual;
// Use this for initialization
void Start () {
columnas = new GameObject [canticolumnas];
for ( int i =0; i<canticolumnas; i++)
{
columnas [i] = Instantiate (columprefab, posicioncolumnas, Quaternion.identity);
}
spawncolumn ();
8. Characteristics
}
// Update is called once per frame
void Update ()
{
timelastcolumn += Time.deltaTime;
if (!controladorjuego.referencia.gameover && timelastcolumn >= columnspawnrate)
{
spawncolumn ();
}
}
void spawncolumn()
{
timelastcolumn = 0;
float spawnyposition = Random.Range (columnymin, columnymax);
columnas [columnactual].transform.position =new Vector2 (columnx, spawnyposi-
tion);
columnactual++;
if(columnactual>=canticolumnas)
{
columnactual = 0;
}
}
}}
Sound And Effects
The Sounds and Music of this game were taken from free sources web Music and
sounds and the effects and sprites were taken from:
Unity free Assets Store