Source Code Ludum Dare 40


using System.Collections;

using System.Collections.Generic;

using UnityEngine;

using UnityEngine.Audio;

using UnityEngine.UI;

using UnityEngine.SceneManagement;

public class Char_mov1 : MonoBehaviour {

    Animator anim;

    public long rocks = 0;

    public bool rockcheck = false;

    public GameObject ScoreText;

    private SpriteRenderer mySpriteRenderer;

    // Use this for initialization

    public Transform ChildTransform;

    void Start () {

        mySpriteRenderer = GetComponent<SpriteRenderer>();

        anim = GetComponent<Animator>();

    }

    public GameObject RockSpawn;

    private float Timer = 0.5f;

    private bool started = false;

    public RuntimeAnimatorController Animation;

    public Sprite Idle;

    public float speed = 10.0f;

    public AudioClip Pickup;

    public AudioClip Dropoff;

    private AudioSource source;

    // Update is called once per frame

    void Update () {

        Timer -= Time.deltaTime;

        if (started == true && Timer <= 0.0f) 

        {

            Timer = 0.5f;

            Instantiate (RockSpawn, new Vector3 (Random.Range (-14.0f, 146.0f), Random.Range (50.0f, 100.0f), 0), Quaternion.identity);

            //RockSpawn.name = "GreyRock";

        }

        source = GetComponent<AudioSource> ();

        if (Input.GetKey (KeyCode.D)) {

            transform.position += Vector3.right * speed * Time.deltaTime;

            this.gameObject.GetComponent<Animator> ().runtimeAnimatorController = Animation;

            if (mySpriteRenderer != null) {

                mySpriteRenderer.flipX = false;

            }

        } else if (Input.GetKeyUp (KeyCode.D)){

            this.gameObject.GetComponent<Animator> ().runtimeAnimatorController = null;

            this.gameObject.GetComponent<SpriteRenderer> ().sprite = Idle;

        }

            

            if (Input.GetKey (KeyCode.A)) {

                transform.position += Vector3.left * speed * Time.deltaTime;

                if (mySpriteRenderer != null) {

                    mySpriteRenderer.flipX = true;

                this.gameObject.GetComponent<Animator> ().runtimeAnimatorController = Animation;

                }

        } else if (Input.GetKeyUp (KeyCode.A)){

            this.gameObject.GetComponent<Animator> ().runtimeAnimatorController = null;

            this.gameObject.GetComponent<SpriteRenderer> ().sprite = Idle;

        }

        if (Input.GetKeyDown (KeyCode.D) || Input.GetKeyDown (KeyCode.A)) {

            this.gameObject.GetComponent<Animator> ().runtimeAnimatorController = Animation;

        } /*else {

            if (this.gameObject.GetComponent<SpriteRenderer> ().sprite == Idle || Input.GetKey (KeyCode.H)) 

                {

                //Debug.Log ("Hit!", this.gameObject.GetComponent<SpriteRenderer>().sprite);

                this.gameObject.GetComponent<SpriteRenderer> ().sprite = Idle;

                }

            }*/

        if (Input.GetKeyDown (KeyCode.D) && Input.GetKeyDown (KeyCode.A)) 

        {

            this.gameObject.GetComponent<Animator> ().runtimeAnimatorController = null;

            this.gameObject.GetComponent<SpriteRenderer> ().sprite = Idle;

        }

        

            if (Input.GetKeyDown (KeyCode.R))

            {

                SceneManager.LoadScene (SceneManager.GetActiveScene().name);

            }

            

            //transform.Translate(Vector3.down * Time.deltaTime * 1.4f, Space.Self);

    }

    void OnCollisionEnter2D(Collision2D coll)

    {

        ChildTransform = this.gameObject.transform.GetChild(0);

        //Transform PackEmbiggen = transform.Find ("backpack");

        if (coll.gameObject.name == "GreyRock" || coll.gameObject.name == "GreyRock(Clone)") {

            rocks++;

            rockcheck = true;

            if (speed >= 0.1f) {

                speed = speed - 0.04f;

            }

                source.PlayOneShot (Pickup, 0.5f);

            //Debug.Log ("Hit!");

            ChildTransform.localScale += new Vector3(0.1f, 0.1f, 0);

            ChildTransform.position += new Vector3(0, 0.09f, 0);

            /*GetComponentInChildren<Transform>().localScale.y += 1;

            GetComponentInChildren<Transform>().position.y += 1

            */

        }

        if (coll.gameObject.name == "TempleDropoff") {

            //Debug.Log ("Hit!");

            if (rockcheck == true) 

            {

                source.PlayOneShot (Dropoff, 0.5f);

                rockcheck = false;

            }

            speed = 10;

            started = true;

            ScoreText.GetComponent<Text> ().text = "Rocks Collected: " + rocks;

            ChildTransform.localPosition = new Vector3(-0.01f, 0.046f, 0.01f);

            ChildTransform.localScale = new Vector3(1.0f, 1.0f, 1.0f);

        }

    }

}

//RockScript

using System.Collections;

using System.Collections.Generic;

using UnityEngine;

public class GreyScript : MonoBehaviour {

    // Use this for initialization

    void Start () {

        

    }

    

    // Update is called once per frame

    void Update () {

        

    }

    void OnCollisionEnter2D(Collision2D coll)

    {

        //Transform PackEmbiggen = transform.Find ("backpack");

        if (coll.gameObject.name == "SisyphusChar") {

            Destroy(gameObject);

                

        }

    }

}

Files

Sophos_Data.zip 16 MB
Dec 04, 2017

Get Sophos