Exemplo n.º 1
0
    void EnemyDoDamage(Turns input)
    {
        EnemyShipState  test  = input.attackerObject.GetComponent <EnemyShipState>();
        PlayerShipState test2 = input.targetObject.GetComponent <PlayerShipState>();

        test2.player.shipHealth = test2.player.shipHealth - test.cannon.weaponAttack;
        UI.printToCombatLog("The " + test.enemy.shipName + " dealt " + test.cannon.weaponAttack.ToString() + " damage to the " + test2.player.shipName + "!");
        if (test2.player.shipHealth <= 0)
        {
            Destroy(input.targetObject);
            player.Remove(input.targetObject);
            PlayerStatus.ShipHealthCurrent = 0;
            UI.printToCombatLog("The " + test.enemy.shipName + " has sunk the " + test2.player.shipName + "!");
            playerWon  = false;
            combatOver = true;
        }
    }
Exemplo n.º 2
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);
            }
        }
    }
 public void ChangeState(PlayerShipState state)
 {
     this.state = state;
     this.state.Create(player, this);
 }
Exemplo n.º 4
0
 // Use this for initialization
 void Start()
 {
     combatState     = (CombatState)combatManager.GetComponent("CombatState"); // to get a non-static reference to the ViewScript Object
     playerShipState = (PlayerShipState)combatState.player[0].GetComponent("PlayerShipState");
     enemyShipState  = (EnemyShipState)combatState.player[0].GetComponent("EnemyShipState");
 }