Saturday, May 14, 2016

Unity 2D game
Crypt Raider

Introduction:

To complete the journey in the vast Egyptian deserts crypt raider has to complete all the five levels of the puzzle in the pyramids. To finish the level, he has to put the ball in the portal and then he will go to the next level. It’s not that easy as there will be some obstacles like flies, bombs and getting the key to open the path way for the portal. If he dies or gets stuck in the obstacles he will have to start the journey from the beginning.

Preview:



Main menu:

To add buttons and text in the main menu and instruction page, we used the graphical user interface (GUI) technique. To edit the buttons, we used GUI Skin which is a feature of unity platform.

Features:

We used following feature of unity 2D in our game:
1.     Box collider.
2.     Rigid body.
3.     Particle system.
4.     GUI Skin.
5.     Animator.

C# Scripting:

We use following functions in our scripts:

  • Void start() { It is called when scene is start }
  • Void update() { It is used to implement any kind of game behavior in every frame}
  • Void OnCollisionEnter2D(Collision2D abc) { It is called when object collides with another }
  • Void Awake() { It is called when the script instance is loaded }
  • Void OnDestroy() { It is called when scripted object is destroyed }
  • Application.LoadLevel(“levelname”) { To call specific scene }
  • Invoke() { To add delay }
  • Destroy() { To destroy specific object }
  • Instantiation {For the sound and visual effects}
  • GameObject.FindWithTag(“tag”) { To find an object }
  • Abc.gameobject.tag==”tag” { To check the object which collides }


Character:
   

The name of our character is crypt raider. We applied physics 2D components on it such as box collider, rigid body etc.

We used the following command for the movement:
void Update()
    {

             if (move) {
                    if (Input.GetAxis ("Horizontal") > 0) {

                           transform.Translate (Vector2.right * speed);

                    } else if (Input.GetAxis ("Horizontal") < 0) {
                           transform.Translate (-Vector2.right * speed);

                    } else if (Input.GetAxis ("Vertical") > 0) {
                           transform.Translate (Vector2.up * speed);

                    } else if (Input.GetAxis ("Vertical") < 0) {                                                     
                           transform.Translate (-Vector2.up * speed);

                    } else if(Input.GetKey(KeyCode.Escape)){
                           Application.LoadLevel ("over");
             }
        }




Ball and portal:





We applied box collider on the ball and the portal. Where a small gravity effect is also applied on the ball so that it can fall downwards.

We used the following script for portal to destroy ball and the character and to add sound effects.

void OnCollisionEnter2D(Collision2D other)
       {
             if(BALL.gameObject==null)
             {
                    if (other.gameObject.tag == "asd") {
                          
                           Destroy (other.gameObject);
                           soundhelper.instance.MakePlayerEnterSound ();
                           Invoke ("Level", 2.0f);
                    }
             }
       }
       void Level()
       {
             Application.LoadLevel ("level2");
       }


The following Script is applied on ball for self-destroy on collision with portal. It also add sound and visual effects.

void OnCollisionEnter2D(Collision2D other)
       {
             if (other.gameObject.tag == "portal") {
                    Destroy (this.gameObject);
                    effect.instance.Enter (transform.position);
                    soundhelper.instance.MakeBallEnterSound ();
             }
       }




Obstacles:

We used following obstacles:

  • Flies:

We used RayCast controller technique to move it up and down.


  • Bomb:

We applied Destroy() function on bomb to destroy the fly.

  • Key and door:





We applied this script on key.

public GameObject DOOR;
       void Start () {
             DOOR=GameObject.FindWithTag("door");    
       }
       void OnCollisionEnter2D (Collision2D other)
       {
             if (other.gameObject.tag == "asd") {
                    Destroy (this.gameObject);
                    soundhelper.instance.MakeKeySound ();
             }     
       }
       void OnDestroy()
       {
             Destroy (DOOR.gameObject);
       }






Thank you for reading our blog. For any queries you can further contact,

Abdul Wahid - awahid.bee15seecs@seecs.edu.pk
Rahim Zahid - rzahid.bee15seecs@seecs.edu.pk






No comments:

Post a Comment