Esempio n. 1
0
 override protected void ResolveCollisionWith(PE_Obj that)
 {
     if (that.coll == PE_Collider.friendlyBullet)
     {
         PhysEngine.objs.Remove(that.GetComponent <PE_Obj>());
         Destroy(that.gameObject);
         health--;
     }
 }
Esempio n. 2
0
    override protected void ResolveCollisionWith(PE_Obj that)
    {
        switch (this.coll)
        {
        case PE_Collider.enemy:

            switch (that.coll)
            {
            case PE_Collider.platform:             // collide with platform
                Vector3 thatP    = that.transform.position;
                Vector3 newPos   = transform.position;
                float   boxSizeY = this.GetComponent <BoxCollider> ().size.y;
                newPos.y           = thatP.y + (this.transform.lossyScale.y * .5f * boxSizeY) + (that.transform.lossyScale.y / 2);
                transform.position = newPos;
                vel.y = 0;

                break;

            case PE_Collider.guy:             // collide with guy
                PE_Guy guy = that.GetComponent <PE_Guy> ();
                if (!guy.isDead)
                {
                    guy.death(false, that.transform.position);
                }
                break;

            case PE_Collider.friendlyBullet:             // collide with friendlyBullet
                PhysEngine.objs.Remove(that.GetComponent <PE_Obj>());
                Destroy(that.gameObject);
                PhysEngine.objs.Remove(this.GetComponent <PE_Obj>());
                Destroy(this.gameObject);
                break;
            }
            break;
        }
    }
Esempio n. 3
0
    override protected void ResolveCollisionWith(PE_Obj that)
    {
        switch (that.coll)
        {
        case PE_Collider.friendlyBullet:                 // collide with friendlyBullet
            // Kill bullet
            PhysEngine.objs.Remove(that.GetComponent <PE_Obj>());
            Destroy(that.gameObject);

            // Instantiate Powerup
            GameObject powerupGO = (GameObject)Instantiate(powerupPrefab);
            powerupGO.transform.position = this.transform.position;
            powerupGO.GetComponent <PE_Powerup>().powerupType = this.powerupType;

            // Kill Self
            PhysEngine.objs.Remove(this.GetComponent <PE_Obj>());
            Destroy(this.gameObject);
            break;
        }
    }
Esempio n. 4
0
    override protected void ResolveCollisionWith(PE_Obj that)
    {
        switch (that.coll)
        {
        case PE_Collider.platform:
            // In Progress
            Vector3 thatP = that.transform.position;
            Vector3 delta = (pos1 - this.transform.lossyScale / 2) - (thatP - that.transform.lossyScale / 2);
            if (isInWater)
            {
                if (!isClimbing)
                {
                    climbTimer = Time.time;
                    isClimbing = true;
                }
                Vector3 newPos = transform.position;

                //Take a quarter of a second to climb up ledge
                if (Time.time > climbTimer + .15f)
                {
                    isInWater  = false;
                    isClimbing = false;
                    RepositionToTop(that);
                    break;
                }
                newPos = transform.position;
                if (transform.position.x > thatP.x)
                {
                    newPos.x = thatP.x + (that.transform.lossyScale.x / 2);
                }
                else if (transform.position.x < thatP.x)
                {
                    newPos.x = thatP.x - (that.transform.lossyScale.x / 2);
                }
                this.transform.position = newPos;
            }
            else if (delta.y >= 0)                                         // Top
            {
                if (vel.y <= 0)
                {
                    // Landed!
                    if (isInAir)
                    {
                        isInAir = false;
                        makeNotJump();
                    }
                    if (fD == FacingDir.down)
                    {
                        fD = lastDir;
                    }
                    RepositionToTop(that);
                }
            }
            break;


        //TODO Change this to handle sprites properly
        case PE_Collider.water:
            //If you are in the water then you can no longer jump
            isInWater = true;
            if (isInAir)
            {
                isInAir = false;
                makeNotJump();
            }

            RepositionToTop(that);
            break;

        case PE_Collider.enemyBullet:
            if (!isDead)
            {
                death(false, transform.position);
            }
            break;

        case PE_Collider.powerup:
            PowerupType pt = that.GetComponent <PE_Powerup>().powerupType;
            print("You got a powerup of type: " + pt);
            switch (pt)
            {
            case PowerupType.rapidFire:
                fireRate  *= .85f;
                burstRate *= .85f;
                break;

            case PowerupType.machineGun:
                gunType   = GunType.machineGun;
                fireRate  = .12f;
                burstRate = .15f;
                break;

            case PowerupType.spreadGun:
                gunType   = GunType.spreadGun;
                fireRate  = normFireRate;
                burstRate = normBurstRate;
                break;

            case PowerupType.laser:
                gunType   = GunType.laser;
                fireRate  = 1f;
                burstRate = 1f;
                break;

            case PowerupType.flame:
                gunType   = GunType.flame;
                fireRate  = .3f;
                burstRate = 1f;
                break;
            }
            // Remove powerup from game
            PhysEngine.objs.Remove(that.GetComponent <PE_Obj>());
            Destroy(that.gameObject);
            break;
        }
    }