Beispiel #1
0
 private void Awake()
 {
     // Actually since Hero spwans eggs, this can be done in the Start() function, but,
     // just to show this can also be done here.
     Debug.Assert(mEggSystem != null);
     EggBehavior.InitializeEggSystem(mEggSystem);
 }
Beispiel #2
0
    // Update is called once per frame
    void Update()
    {
        #region user movement control
        transform.position += Input.GetAxis("Vertical") * transform.up * (kHeroSpeed * Time.smoothDeltaTime);

        float clampedX = Mathf.Clamp(this.transform.position.x, mGameManager.WorldMin.x, mGameManager.WorldMax.x);
        float clampedY = Mathf.Clamp(this.transform.position.y, mGameManager.WorldMin.y, mGameManager.WorldMax.y);
        mClampPosition     = new Vector3(clampedX, clampedY, 0.0f);
        transform.position = mClampPosition;

        transform.Rotate(Vector3.forward, -1f * Input.GetAxis("Horizontal") * (kHeroRotateSpeed * Time.smoothDeltaTime));
        #endregion

        #region fire egg
        if (Input.GetAxis("Fire1") > 0f)    // this is Left-Control
        {
            if (Time.realtimeSinceStartup - mlastEggFire > kEggSpawnInterval)
            {
                GameObject  e   = Instantiate(mProjectile) as GameObject;
                EggBehavior egg = e.GetComponent <EggBehavior>(); // Shows how to get the script from GameObject
                if (null != egg)
                {
                    mlastEggFire         = Time.realtimeSinceStartup;
                    e.transform.position = transform.position;
                    egg.SetForwardDirection(transform.up);
                }
            }
            var         source = GetComponents <AudioSource>();
            AudioSource reload = source[0];
            reload.Play();
        }
        #endregion
    }
Beispiel #3
0
    // Update is called once per frame
    void Update()
    {
        wait++;
        status = globalBehavior.ObjectCollideWorldBound(GetComponent <Renderer>().bounds);
        if (status != BossBackground.WorldBoundStatus.Inside)
        {
            transform.position -= 3 * Input.GetAxis("Vertical") * transform.up * (kHeroSpeed * Time.smoothDeltaTime);
        }

        transform.position += Input.GetAxis("Vertical") * transform.up * (kHeroSpeed * Time.smoothDeltaTime);
        transform.Rotate(Vector3.forward, -1f * Input.GetAxis("Horizontal") * (kHeroRotateSpeed * Time.smoothDeltaTime));

        if (Input.GetAxis("Fire1") > 0f && wait > 5)  // this is Left-Control
        {
            wait = 0;
            GameObject  e   = Instantiate(mProjectile) as GameObject;
            EggBehavior egg = e.GetComponent <EggBehavior>(); // Shows how to get the script from GameObject
            if (null != egg)
            {
                worldOffset          = transform.rotation * offset;
                e.transform.position = transform.position + worldOffset;
                egg.SetForwardDirection(transform.up);
            }
        }
    }
    void MakeEgg(float xSpeed, float ySpeed)
    {
        // Create the game object for an egg
        GameObject  egg      = (GameObject)Instantiate(eggPrefab, transform.position, Quaternion.identity);
        EggBehavior eggBehav = egg.GetComponent <EggBehavior>();

        egg.layer = gameObject.layer;
        Rigidbody2D eggrb = egg.GetComponent <Rigidbody2D>();

        eggBehav.attackPower *= powerups.attackChange;

        eggrb.gravityScale *= powerups.gravityChange;

        if (powerups.mExtraEggThrows <= 0 && Input.GetAxis("Vertical" + playerNumber) < 0)
        {
            // Set special anti-gravity egg
            eggrb.gravityScale  *= -0.1f;
            eggrb.velocity       = new Vector2(xSpeed * (facingRight ? 1 : -1) * 0.1f, ySpeed * 3.2f);
            eggBehav.bounceCount = 2;
        }
        else
        {
            // Set the velocity of the egg, add bonus velocity based on player velocity
            eggrb.velocity  = new Vector2(xSpeed * (facingRight ? 1 : -1) - rb.velocity.x * 0.4f, ySpeed - Mathf.Abs(rb.velocity.x) * 0.5f);
            eggrb.velocity *= powerups.speedChange;

            if (Mathf.Abs(rb.velocity.x) < 0.2f)
            {
                // if player has small or no x-velocity, add more bounce to egg
                eggBehav.bounceCount += 1;
                eggBehav.lifespan    += 1;
            }
        }
        eggrb.angularVelocity = (facingRight ? -1 : 1) * Random.value * 360.0f;
    }
Beispiel #5
0
    // Start is called before the first frame update
    void Start()
    {
        GameManager.sTheGlobalBehavior = this;  // Singleton pattern
        Debug.Assert(mEggCountEcho != null);    // Assume setting in the editor!
        Debug.Assert(mHero != null);

        // Connect up everyone who needs to know about each other
        EggBehavior.SetGreenArrow(mHero);
        // Notice the symantics: this is a call to class method (NOT instance method)
    }
 private void OnTriggerEnter2D(Collider2D collision)
 {
     if (collision.tag == "Egg")
     {
         Hit();
         wayPointCamera.GetComponent <WayPointCamera>().cameraOn(transform);
         // Delete the Egg
         EggBehavior egg = collision.GetComponent <EggBehavior>();
         egg.Destroy();
     }
 }
Beispiel #7
0
 private void cullEggs( )
 {
     EggBehavior[] eggs = FindObjectsOfType <EggBehavior>( );
     for (int i = 0; i < eggs.Length; i++)
     {
         EggBehavior egg = eggs[i];
         if (egg.CheckLife( ))
         {
             _eggCount--;
         }
     }
 }
Beispiel #8
0
    public void SpawnAnEgg(Vector3 p, Vector3 dir)
    {
        Debug.Assert(CanSpawn());
        GameObject  e   = GameObject.Instantiate(mEggSample) as GameObject;
        EggBehavior egg = e.GetComponent <EggBehavior>(); // Shows how to get the script from GameObject

        if (null != egg)
        {
            e.transform.position = p;
            e.transform.up       = dir;
        }
        IncEggCount();
        mSpawnEggAt = Time.realtimeSinceStartup;
        EchoEggCount();
    }
Beispiel #9
0
    // Update is called once per frame
    void Update()
    {
        #region user movement control
        transform.position += Input.GetAxis("Vertical") * transform.up * (kHeroSpeed * Time.smoothDeltaTime);
        transform.Rotate(Vector3.forward, -1f * Input.GetAxis("Horizontal") * (kHeroRotateSpeed * Time.smoothDeltaTime));
        #endregion

        if (Input.GetAxis("Fire1") > 0f)            // this is Left-Control
        {
            GameObject  e   = Instantiate(mProjectile) as GameObject;
            EggBehavior egg = e.GetComponent <EggBehavior>();            // Shows how to get the script from GameObject
            if (null != egg)
            {
                e.transform.position = transform.position;
                egg.SetForwardDirection(transform.up);
            }
        }
    }
    // Update is called once per frame
    void Update()
    {
        #region motion control
        transform.position += Input.GetAxis("Vertical") * transform.up *
                              (kHeroSpeed * Time.smoothDeltaTime);
        transform.Rotate(Vector3.forward, -1f * Input.GetAxis("Horizontal") *
                         (kHeroRotateSpeed * Time.smoothDeltaTime));
        #endregion

        GlobalBehavior.sTheGlobalBehavior.ObjectClampToWorldBound(this.transform);

        if (Input.GetKey("space"))                            // VS. GetKeyDown <<-- even, one per key press
        {                                                     // space bar hit
            GameObject  e   = Instantiate(mEgg) as GameObject;
            EggBehavior egg = e.GetComponent <EggBehavior>(); // Shows how to get the script from GameObject
            if (null != egg)
            {
                e.transform.position = transform.position;
            }
        }
    }
Beispiel #11
0
	public void E_Hatch(EggBehavior egg){
		if(hatchName.text.Trim() == "") return;
		egg.Hatch(hatchName.text);
		ClosePopup();
	}