Example #1
0
    private void PlayerShipStateCheck()
    {
        if (!Scr_PlayerData.dead)
        {
            if (currentPlanet != null)
            {
                playerShipPrediction.predictionTime = 0;

                RaycastHit2D beginLandingHit = Physics2D.Raycast(endOfShip.position, -endOfShip.up, landDistance, planetLayer);

                if (beginLandingHit && playerShipState == PlayerShipState.inSpace)
                {
                    mainCamera.GetComponent <Scr_MainCamera>().smoothRotation = true;
                    mainCamera.GetComponent <Scr_MainCamera>().CameraShake(0.25f, 5, 12);

                    maxSpeedSaved = maxSpeed;

                    Landing();
                }
            }

            else
            {
                playerShipState  = PlayerShipState.inSpace;
                checkingDistance = 100;
                landedOnce       = true;

                if (playerShipActions.currentAsteroid == null)
                {
                    playerShipPrediction.predictionTime = 6;
                }
            }

            if (Input.GetKeyDown(KeyCode.LeftShift) && playerShipState == PlayerShipState.landed && canControlShip && !damaged && playerShipStats.currentFuel > (playerShipStats.maxFuel * 0.15f))
            {
                if (playerShipStats.currentFuel == playerShipStats.maxFuel || firstTakeOff)
                {
                    savedTimeToTakeOff = timeToTakeOff;
                }
            }

            if (Input.GetKey(KeyCode.LeftShift) && playerShipState == PlayerShipState.landed && canControlShip && !damaged && playerShipStats.currentFuel > (playerShipStats.maxFuel * 0.15f))
            {
                if (playerShipStats.currentFuel == playerShipStats.maxFuel || firstTakeOff)
                {
                    firstTakeOff = true;

                    playerShipEffects.WarmingEffects(true);

                    savedTimeToTakeOff -= Time.deltaTime;

                    if (savedTimeToTakeOff <= 0 && Input.GetMouseButtonDown(0))
                    {
                        playerShipEffects.WarmingEffects(false);
                        playerShipEffects.warming = false;
                        playerShipEffects.PlayParticleSystem(playerShipEffects.takingOffSlam);

                        mainCamera.GetComponent <Scr_MainCamera>().smoothRotation = false;
                        mainCamera.GetComponent <Scr_MainCamera>().CameraShake(0.25f, 5, 12);

                        TakingOff();
                    }
                }
            }

            if (Input.GetKeyUp(KeyCode.LeftShift) && playerShipState == PlayerShipState.landed)
            {
                playerShipEffects.WarmingEffects(false);
            }

            if (onGround)
            {
                playerShipState = PlayerShipState.landed;

                Landed();
            }

            if (takingOff)
            {
                playerShipState = PlayerShipState.takingOff;
                canRotateShip   = false;
                canControlShip  = false;

                rb.velocity = Vector2.Lerp(rb.velocity, targetVelocity * transform.up, Time.deltaTime * takingOffTime);

                if (currentPlanet == null)
                {
                    transform.SetParent(null);
                    snapped = false;

                    canRotateShip  = true;
                    canControlShip = true;

                    takingOff = false;
                }
            }

            if (landing)
            {
                Vector3 planetDirection = new Vector3(transform.position.x - currentPlanet.transform.position.x, transform.position.y - currentPlanet.transform.position.y, transform.position.z - currentPlanet.transform.position.z);

                playerShipState = PlayerShipState.landing;
                canRotateShip   = true;

                RaycastHit2D checkingDistanceHit = Physics2D.Raycast(endOfShip.position, -endOfShip.up, Mathf.Infinity, planetLayer);

                if (checkingDistanceHit)
                {
                    if (checkingDistanceHit.distance < checkingDistance)
                    {
                        checkingDistance = checkingDistanceHit.distance;
                    }
                }

                Debug.DrawRay(endOfShip.position, -endOfShip.up * checkingDistance, Color.yellow);

                RaycastHit2D landingProperlyHit = Physics2D.Raycast(endOfShip.position, -endOfShip.up, checkingDistance + 0.1f, planetLayer);

                if (landingProperlyHit)
                {
                    if (manualLanding && Input.GetMouseButton(0))
                    {
                        rb.velocity = Vector3.Lerp(rb.velocity, Vector3.zero, Time.deltaTime * landingTime);

                        playerShipDeathCheck.CheckLandingTime(false);
                    }

                    else
                    {
                        rb.velocity = Vector3.Lerp(rb.velocity, Vector3.zero, Time.deltaTime * landingTime / (currentPlanet.transform.GetComponentInChildren <Renderer>().bounds.size.y / gameManager.initialPlanet.GetComponentInChildren <Renderer>().bounds.size.y));

                        playerShipDeathCheck.CheckLandingTime(false);
                    }
                }

                if (onGround)
                {
                    playerShipEffects.StopParticleSystem(playerShipEffects.mainThruster);
                    playerShipEffects.PlayParticleSystem(playerShipEffects.landingSlam);
                    landing = false;
                }
            }

            if (astronautOnBoard)
            {
                visuals.transform.position = new Vector3(visuals.transform.position.x, transform.position.y, initialZ + 50);
            }

            else
            {
                visuals.transform.position = new Vector3(visuals.transform.position.x, transform.position.y, initialZ);
            }
        }
    }
Example #2
0
    public void Death()
    {
        if (!diedOnce)
        {
            diedOnce = true;

            if (playerShipMovement.astronautOnBoard)
            {
                playerShipMovement.canControlShip = false;
                playerShipMovement.canRotateShip  = false;
                playerShipMovement.landedOnce     = false;
                Scr_PlayerData.dead = true;
                rb.velocity         = Vector3.zero;
                rb.isKinematic      = true;
                shipVisuals.gameObject.SetActive(false);
                playerShipEffects.PlayParticleSystem(playerShipEffects.explosion);
                Scr_MusicManager.Instance.PlaySound(explosion.Sound, 0);
                playerShipEffects.StopAllThrusters();
                collider.enabled = false;
                playerShipProxCheck.ClearInterface(false);
                playerShipHalo.disableHalo          = true;
                savedPrediction                     = playerShipPrediction.predictionTime;
                playerShipPrediction.predictionTime = 0;

                GetComponentInChildren <Scr_PlayerShipDeathCheck>().enabled = false;

                Invoke("Fade", fadeTime);
            }

            else
            {
                astronautStats.visuals.transform.position = new Vector3(astronautStats.visuals.transform.position.x, astronautStats.visuals.transform.position.y, astronautStats.initialVisualPos.z + 50);
                astronautMovement.canMove = false;
                astronautAnim.SetTrigger("Death");

                switch (playerShipMovement.currentPlanet.GetComponent <Scr_Planet>().planetType)
                {
                case Scr_Planet.PlanetType.EarthLike:
                    astronautEffects.DeathParticles(Scr_AstronautEffects.DeathType.Normal);
                    break;

                case Scr_Planet.PlanetType.Frozen:
                    astronautEffects.DeathParticles(Scr_AstronautEffects.DeathType.Ice);
                    break;

                case Scr_Planet.PlanetType.Volcanic:
                    astronautEffects.DeathParticles(Scr_AstronautEffects.DeathType.Fire);
                    break;

                case Scr_Planet.PlanetType.Arid:
                    astronautEffects.DeathParticles(Scr_AstronautEffects.DeathType.Normal);
                    break;

                case Scr_Planet.PlanetType.Toxic:
                    astronautEffects.DeathParticles(Scr_AstronautEffects.DeathType.Posion);
                    break;
                }

                Invoke("Fade", fadeTime);
            }

            Invoke("Respawn", respawnTime);
        }
    }