예제 #1
0
    void Start()
    {
        currentCore    = "Empty";
        spriteRenderer = gameObject.GetComponent <SpriteRenderer>();
        if (transform.childCount > 0f)
        {
            currentCore            = transform.GetChild(0).gameObject.name;
            attachedPowerCell      = transform.GetChild(0).gameObject;
            attachedRb             = attachedPowerCell.GetComponent <Rigidbody2D>();
            attachedRb.isKinematic = true;
            powerCell  = attachedPowerCell.GetComponent <powerCell>();
            activated  = powerCell.activated;
            overcharge = powerCell.overcharge;
        }

        if (activated)
        {
            if (overcharge)
            {
                spriteRenderer.color = new Color32(166, 254, 0, 255);
            }
            else
            {
                spriteRenderer.color = new Color32(255, 255, 150, 255);
            }
        }
        else
        {
            spriteRenderer.color = Color.white;
        }
    }
예제 #2
0
    void DetachPowercell()
    {
        bool wasActivated = activated;

        Debug.Log("Exited");
        attachedPowerCell   = null;
        holdingPowerCell    = false;
        powerCellIdentifier = 0;
        powerCell           = null;
        if (!canStoreCharge)
        {
            activated            = false;
            overcharge           = false;
            spriteRenderer.color = Color.white;
            if (wasActivated != activated)
            {
                StateChange(activated);
            }
        }
    }
예제 #3
0
    void OnTriggerEnter2D(Collider2D col)
    {
        if (col.tag == "powerCell" && !holdingPowerCell)
        {
            attachedPowerCell      = col.gameObject;
            attachedRb             = attachedPowerCell.GetComponent <Rigidbody2D>();
            attachedRb.velocity    = Vector2.zero;
            attachedRb.isKinematic = true;
            attachedPowerCell.transform.position = transform.position;
            attachedPowerCell.transform.parent   = gameObject.transform;
            powerCell           = attachedPowerCell.GetComponent <powerCell>();
            powerCellIdentifier = powerCell.identifier;

            UpdateCharge(powerCell.activated, powerCell.overcharge);

            if ((powerCell.activated && lockChargedPowerCell) || (powerCell.overcharge && powerCell.activated && lockOverchargedPowerCell))
            {
                attachedRb.bodyType = RigidbodyType2D.Static;
            }
        }
    }
    // Update is called once per frame
    void FixedUpdate()
    {
        if (Physics2D.OverlapCircle(gameObject.transform.position, range, playerLayer))
        {
            collisionEffect.SetActive(true);
            laserLine.enabled = true;

            targetPosition = target.transform.position;

            if (!isFiring && !isPaused) // aim
            {
                laserOrigin          = laserOriginPoint.transform.position;
                laserOriginDirection = new Vector2(targetPosition.x - laserOrigin.x, targetPosition.y - laserOrigin.y);
                laserAngle           = Mathf.Atan2(laserOriginDirection.y, laserOriginDirection.x);
                if (laserAngle < 0f)
                {
                    laserAngle = Mathf.PI * 2 + laserAngle;
                }
                gameObject.transform.up = Quaternion.Euler(0, 0, (laserAngle * Mathf.Rad2Deg) + 90f) * Vector2.right;
                laserOriginDirection.Normalize();
            }

            RaycastHit2D laser = Physics2D.Raycast(laserOrigin, laserOriginDirection, laserRange, laserLayer);
            if (laser.collider != null)
            {
                laserEndpoint = laser.point;
                collisionEffect.SetActive(true);

                laserLine.positionCount = 2;
                laserLine.SetPosition(0, laserOrigin);
                laserLine.SetPosition(1, laserEndpoint);

                Vector2 laserCollisionNormal = laser.normal;
                float   collisionNormalAngle = Mathf.Atan2(laserCollisionNormal.y, laserCollisionNormal.x);
                if (collisionNormalAngle < 0f)
                {
                    collisionNormalAngle = Mathf.PI * 2 + collisionNormalAngle;
                }

                if (playerScript.partConfiguration == 1 && laser.collider.tag == "Player")
                {
                    collisionEffect.transform.up = Quaternion.Euler(0, 0, (laserAngle * Mathf.Rad2Deg) + 180f) * Vector2.right;
                }
                else
                {
                    collisionEffect.transform.up = Quaternion.Euler(0, 0, (collisionNormalAngle * Mathf.Rad2Deg)) * Vector2.right;
                }

                if (laser.collider.tag == "Player") // if hitting the player and they do not have the deflector shield
                {
                    collisionEffect.transform.position = targetPosition;
                    if (laserTag != "Player") // if it wasn't previously hitting the player
                    {
                        playerScript.DeathRay(false);
                        playerScript.EndDeflect();
                    }
                    if (isFiring)
                    {
                        if (!killedPlayer)
                        {
                            playerScript.Die(0.4f);
                            killedPlayer = true;
                        }
                    }
                    else if (!isPaused)
                    {
                        isCharging = true;
                    }
                }
                else if (laser.collider.tag == "powerCell")
                {
                    if (laserTag != "powerCell" && isFiring || (isFiring && !wasFiring))
                    {
                        powerCell           = laser.transform.gameObject.GetComponent <powerCell>();
                        powerCell.activated = true;
                    }
                }
                else if (laser.collider.tag == "HeldBox")
                {
                    collisionEffect.transform.position = laser.point;
                    if (laserTag != "HeldBox" && isFiring || (isFiring && !wasFiring))
                    {
                        if (playerScript.heldBoxTag == "powerCell")
                        {
                            powerCell powerCell = target.transform.Find("PowerCell").GetComponent <powerCell>();
                            Debug.Log(powerCell);
                            powerCell.activated = true;
                        }
                    }
                }
                else if (laser.collider.tag == "Shield") // if it hits the player's force field shield
                {
                    collisionEffect.transform.position = laser.point;
                    if (laserTag != "Shield")
                    {
                        playerScript.InitiateDeflect();
                        laserChargeTimer = 0f;

                        if (isFiring == true)
                        {
                            playerScript.DeathRay(true);
                        }
                        else
                        {
                            playerScript.DeathRay(false);
                            if (!isPaused)
                            {
                                isCharging = true;
                            }
                        }
                    }
                }
                else if (laser.collider.tag == "LaserRouter") // if it hits a laser router
                {
                    if (laserTag != "laserRouter")
                    {
                        laserRouter = laser.transform.gameObject.GetComponent <laserRouter>();
                        laserRouter.Charged();
                        if (isFiring == true)
                        {
                            laserRouter.DeathRay(true);
                        }
                        else
                        {
                            laserRouter.DeathRay(false);
                        }
                    }
                }
                else
                {
                    if (laserRouter != null && laserTag == "laserRouter")
                    {
                        laserRouter.Drained();
                        laserRouter.DeathRay(false);
                    }

                    if (laserTag == "Shield")
                    {
                        playerScript.DeathRay(false);
                        playerScript.EndDeflect();
                    }

                    isCharging = false;

                    if (laser.collider.tag == "Box" || laser.collider.tag == "Enemy")
                    {
                        collisionEffect.transform.position = laser.collider.transform.position;
                    }
                    else
                    {
                        collisionEffect.transform.position = laser.point;
                    }
                }

                if (laserTag != laser.collider.tag)
                {
                    if (laserTag == "Shield")
                    {
                        playerScript.DeathRay(false);
                        playerScript.EndDeflect();
                    }
                }
                laserTag = laser.collider.tag;
                collisionEffect.transform.position = laser.point;
            }
            else
            {
                if (laserTag == "Shield")
                {
                    playerScript.DeathRay(false);
                    playerScript.EndDeflect();
                }
                laserTag = "null";
                collisionEffect.SetActive(false);
            }
        }
        else
        {
            if (laserTag == "Shield")
            {
                playerScript.DeathRay(false);
                playerScript.EndDeflect();
                laserTag = "null";
            }
            isCharging = false;
            collisionEffect.SetActive(false);
            laserLine.enabled = false;
            laserChargeTimer  = 0;
            // Unwind
            //if(laserChargeTimer > 0) laserChargeTimer -= 2f * Time.deltaTime;
            //if(laserChargeTimer <= 0) laserChargeTimer = 0f;
        }


        wasFiring = isFiring;


        if (isCharging)
        {
            if (!wasCharging)
            {
                AkSoundEngine.PostEvent("BansheeWindUp", gameObject);
            }
            laserLine.material = materialCharge;
            laserChargeTimer  += Time.deltaTime;

            burstColour.ColourChange("blue");
            collisionColour.ColourChange("blue");

            if (laserChargeTimer >= laserChargeTime)
            {
                laserTag           = "null";
                laserLine.material = materialPause;
                laserPauseTimer    = 0f;
                isPaused           = true;
                isCharging         = false;
                burstColour.ColourChange("purple");
                collisionColour.ColourChange("purple");
            }
        }
        else
        {
            laserChargeTimer = 0f;
        }

        wasCharging = isCharging;

        if (isPaused)
        {
            laserPauseTimer += Time.deltaTime;
            if (laserPauseTimer >= laserPauseTime)
            {
                laserTag           = "null";
                laserLine.material = materialFire;
                laserFireTimer     = 0f;
                isFiring           = true;
                isPaused           = false;
                AkSoundEngine.PostEvent("BansheeFire", gameObject);
            }
        }

        if (isFiring)
        {
            isPaused         = false;
            laserChargeTimer = 0f;
            laserFireTimer  += Time.deltaTime;

            if (laserFireTimer > laserFireTime)
            {
                laserTag           = "null";
                laserLine.material = materialCharge;
                isFiring           = false;
                laserFireTimer     = 0f;
                killedPlayer       = false;
                burstColour.ColourChange("blue");
                collisionColour.ColourChange("blue");
            }

            float laserAngle = Mathf.Atan2(laserOriginDirection.y, laserOriginDirection.x);  // apply the laser burst effect
            if (laserAngle < 0f)
            {
                laserAngle = Mathf.PI * 2 + laserAngle;
            }

            burstEffect.SetActive(true);
            burstColour.ColourChange("red");
            collisionColour.ColourChange("red");
            collisionEffect.transform.localScale = Vector3.one;
            burstEffect.transform.position       = laserOrigin;
            burstEffect.transform.up             = Quaternion.Euler(0, 0, (laserAngle * Mathf.Rad2Deg)) * Vector2.right;
        }
        else
        {
            burstEffect.SetActive(false);
            collisionEffect.transform.localScale = new Vector3(0.6f, 0.6f, 1f);
        }

        if (!isCharging && !isFiring && !isPaused)
        {
            unFocussed = true;
            if (!wasUnFocussed)
            {
                AkSoundEngine.PostEvent("BansheeStop", gameObject);
                burstColour.ColourChange("blue");
                collisionColour.ColourChange("blue");
            }
        }
        else
        {
            unFocussed = false;
        }

        wasUnFocussed = unFocussed;
    }
예제 #5
0
    void SecondaryLaserCaster()
    {
        Vector2 laserOriginDirection = (aimSpriteSplit.transform.up + aimSpriteSplit.transform.right).normalized;
        Vector2 laserOrigin          = (Vector2)transform.position + (laserOriginDirection * colRadius);

        RaycastHit2D laser = Physics2D.Raycast(laserOrigin, laserOriginDirection, Mathf.Infinity, laserLayer);

        if (laser.collider != null)
        {
            laserEndpointSplit = laser.point;

            laserLineSplit.positionCount = 2;
            laserLineSplit.SetPosition(0, laserOrigin);
            laserLineSplit.SetPosition(1, laserEndpointSplit);

            Vector2 laserCollisionNormal = laser.normal;
            float   collisionNormalAngle = Mathf.Atan2(laserCollisionNormal.y, laserCollisionNormal.x);
            if (collisionNormalAngle < 0f)
            {
                collisionNormalAngle = Mathf.PI * 2 + collisionNormalAngle;
            }

            collisionEffectSplit.SetActive(true);
            collisionEffectSplit.transform.position = laser.point;
            collisionEffectSplit.transform.up       = Quaternion.Euler(0, 0, (collisionNormalAngle * Mathf.Rad2Deg)) * Vector2.right;

            if (laser.collider.tag == "LaserRouter")
            {
                if (laserTagSplit != "laserRouter")
                {
                    laserRouter laserRouter = laser.transform.gameObject.GetComponent <laserRouter>();
                    laserRouter.Charged();
                    if (deathRay)
                    {
                        laserRouter.DeathRay(true);
                    }
                    else
                    {
                        laserRouter.DeathRay(false);
                    }
                }
            }
            else if (laser.collider.tag == "HeldBox")
            {
                collisionEffect.transform.position = laser.point;
                if (playerScript.heldBoxTag == "powerCell" && ((laserTagSplit != "HeldBox" && charged) || (!wasCharged && charged)))
                {
                    powerCell powerCell = player.transform.Find("PowerCell").GetComponent <powerCell>();
                    powerCell.activated = true;
                    if (overcharge)
                    {
                        powerCell.overcharge = true;
                    }
                }
            }
            else if (laser.collider.tag == "Shield")
            {
                if (laserTagSplit != "Shield") // if the most recent collider hit was not the player
                {
                    playerScript playerScript = laser.transform.gameObject.GetComponent <playerScript>();
                    playerScript.InitiateDeflect();
                    if (deathRay)
                    {
                        playerScript.DeathRay(true);
                    }
                    else
                    {
                        playerScript.DeathRay(false);
                    }
                }
            }
            else if (laser.collider.tag == "Player")
            {
                if (laserTagSplit != "Player") // if the most recent collider hit was not the player
                {
                    if (charged)
                    {
                        playerScript.Die(0.5f);
                    }
                }
            }
            else
            {
                if (playerScript != null && laserTagSplit == "Shield")
                {
                    playerScript.DeathRay(false);
                    playerScript.EndDeflect();
                }
            }

            if (charged)
            {
                if (laser.collider.tag == "Enemy" || laser.collider.tag == "Groundbreakable")
                {
                    Destroy(laser.collider.gameObject);
                }
            }


            if (laser.collider.tag == "powerCell")
            {
                if ((laserTagSplit != "powerCell" && charged) || (!wasCharged && charged))
                {
                    powerCell           = laser.transform.gameObject.GetComponent <powerCell>();
                    powerCell.activated = true;
                }
            }
            else if (laser.collider.tag == "PowerStation")
            {
                if (laserTagSplit != "PowerStation")
                {
                    powerStation           = laser.transform.gameObject.GetComponent <powerStation>();
                    powerStation.activated = true;
                }
            }

            laserTagSplit = laser.collider.tag;
        }
        else
        {
            collisionEffect.SetActive(false);
            laserEndpointSplit = laserOrigin + (laserOriginDirection * 10000f);
        }
        laserLineSplit.positionCount = 2;
        laserLineSplit.SetPosition(0, laserOrigin);
        laserLineSplit.SetPosition(1, laserEndpointSplit);

        float laserAngle = Mathf.Atan2(laserOriginDirection.y, laserOriginDirection.x);  // apply the laser burst effect

        if (laserAngle < 0f)
        {
            laserAngle = Mathf.PI * 2 + laserAngle;
        }

        burstEffectSplit.SetActive(true);
        burstEffectSplit.transform.position = (Vector2)transform.position + (laserOriginDirection * (colRadius - 0.01f));
        burstEffectSplit.transform.up       = Quaternion.Euler(0, 0, (laserAngle * Mathf.Rad2Deg)) * Vector2.right;
    }