Exemple #1
0
 /// <summary>
 /// Updates path.
 /// </summary>
 protected void UpdatePath()
 {
     if ((tankLevel == 1) || (tankLevel == 11))
     {
         Vector2 newPoint = new Vector2();
         newPoint.y = GameManager.playerInstance.transform.position.y;
         newPoint.x = (GameManager.playerInstance.transform.position.x - 6.5f) * -1;
         path       = PathFinding.FindPath(this.transform.position, newPoint);
     }
     else if ((tankLevel == 2) || (tankLevel == 12))
     {
         path = PathFinding.FindPath(this.transform.position, GameManager.playerInstance.transform.position);
     }
     else if ((tankLevel == 3) || (tankLevel == 13))
     {
         path = PathFinding.FindPath(this.transform.position, (new Vector2(6.5f, 0.5f))); // base position
     }
     if (path != null)
     {
         followPathTimeStamp = Time.time;
         DebugVisualHelper.DrawPath(path);
         followingPath = true;
         pathPoints    = 0;
         GetDirectionFromVector();
     }
 }
Exemple #2
0
    /// <summary>
    /// Updates path (if not found, path is null).
    /// </summary>
    void UpdatePath()
    {
        lastPathCheck = Time.time;
        if ((tankLevel == 0) || (tankLevel == 10))
        {
            path = PathFinding.FindPath(this.transform.position, randomTravelDestinations[Random.Range(0, randomTravelDestinations.Length)]);
        }
        else if ((tankLevel == 1) || (tankLevel == 11))
        {
            if (GameManager.playerInstance.gameObject != null)
            {
                Vector2 target = new Vector2();
                if (GameManager.playerInstance.transform.position.x < 6.5f)
                {
                    target.x = GameManager.playerInstance.transform.position.x + 6.5f;
                    target.y = GameManager.playerInstance.transform.position.y;
                }
                else
                {
                    target.x = 6.5f - (GameManager.playerInstance.transform.position.x - 6.5f);
                    target.y = GameManager.playerInstance.transform.position.y;
                }
                path = PathFinding.FindPath(this.transform.position, target);
            }
            else
            {
                path = null;
            }
        }
        else if ((tankLevel == 2) || (tankLevel == 12))
        {
            path = PathFinding.FindPath(this.transform.position, GameManager.playerInstance.transform.position);
        }
        else if ((tankLevel == 3) || (tankLevel == 13))
        {
            path = PathFinding.FindPath(this.transform.position, new Vector2(6.5f, 0.5f));
        }

        if (path != null)
        {
            currentPathPoint     = 1;
            directionToPathPoint = GetDirectionFromVector(path[1]);
            currentMoveDirection = directionToPathPoint;
            DebugVisualHelper.DrawPath(path);
            checkPathAfter = 10f;
        }
        else
        {
            print("path is null.");
            checkPathAfter          = 3f;
            randomMovementTimeStamp = Time.time;
        }
    }
Exemple #3
0
 /// <summary>
 /// Sets path to specific point (depends on enemy 'level') or makes tank move randomly.
 /// </summary>
 protected void MovementRequest()
 {
     if (Time.time - lastPathCheck > checkPathAfter)
     {
         if (Random.Range(0, followPathChance) == 0)
         {
             UpdatePath();
         }
         else
         {
             path = null;
         }
     }
     DoMovement();
     DebugVisualHelper.DrawRayForMovement(currentMoveDirection, this.transform.position);
 }
Exemple #4
0
 // Update is called once per frame
 void FixedUpdate()
 {
     if (!GameManager.isGamePaused)
     {
         DebugVisualHelper.DrawRay(this.transform.position);
         //Vector3 lookAt = new Vector3(this.transform.position.x, this.transform.position.y);
         if (controllsEnabled)
         {
             if ((Input.GetKey(KeyCode.UpArrow)) || (Input.GetKey(KeyCode.W)))
             {
                 currentMoveDirection = "DIR_U"; shotDirection = currentMoveDirection;
             }
             else if ((Input.GetKey(KeyCode.DownArrow)) || (Input.GetKey(KeyCode.S)))
             {
                 currentMoveDirection = "DIR_D"; shotDirection = currentMoveDirection;
             }
             else if ((Input.GetKey(KeyCode.RightArrow)) || (Input.GetKey(KeyCode.D)))
             {
                 currentMoveDirection = "DIR_R"; shotDirection = currentMoveDirection;
             }
             else if ((Input.GetKey(KeyCode.LeftArrow)) || (Input.GetKey(KeyCode.A)))
             {
                 currentMoveDirection = "DIR_L"; shotDirection = currentMoveDirection;
             }
             else
             {
                 currentMoveDirection = null;
             }
         }
         else
         {
             currentMoveDirection = null;
         }
         PerformMovement(movementSpeed);
         if (currentMoveDirection == null)
         {
             tankAnimator.SetBool("Tank is moving", false);
             if (GameManager.mainSoundManager.SRCbackgroundNoise.clip != GameManager.mainSoundManager.SFXbackgroundNoise)
             {
                 if (GameManager.isGameOver != 1)
                 {
                     GameManager.mainSoundManager.SRCbackgroundNoise.Stop();
                     GameManager.mainSoundManager.SRCbackgroundNoise.clip = GameManager.mainSoundManager.SFXbackgroundNoise;
                     GameManager.mainSoundManager.SRCbackgroundNoise.Play();
                 }
                 else
                 {
                     GameManager.mainSoundManager.SRCbackgroundNoise.Stop();
                 }
             }
         }
         else
         {
             //this.transform.LookAt(lookAt);
             //this.transform.l
             if (GameManager.mainSoundManager.SRCbackgroundNoise.clip != GameManager.mainSoundManager.SFXplayerMoving)
             {
                 GameManager.mainSoundManager.SRCbackgroundNoise.Stop();
                 GameManager.mainSoundManager.SRCbackgroundNoise.clip = GameManager.mainSoundManager.SFXplayerMoving;
                 GameManager.mainSoundManager.SRCbackgroundNoise.Play();
             }
             tankAnimator.SetBool("Tank is moving", true);
         }
         // SHOT CONTROLS
         if (((Input.GetKeyDown(KeyCode.Space)) || (Input.GetKeyDown(KeyCode.Keypad0))) && (controllsEnabled))
         {
             if (areShotsBeingFired[0] == false)
             {
                 areShotsBeingFired[0] = true;
                 ShotingBullet(owner);
                 GameManager.mainSoundManager.SRCplayerShot.Play();
             }
             else if (areShotsBeingFired[1] == false)
             {
                 if (tankLevel > 1)
                 {
                     areShotsBeingFired[1] = true;
                     ShotingBullet(owner);
                     GameManager.mainSoundManager.SRCplayerShot.Play();
                 }
             }
         }
         //Check for players levelup
         if (GameManager.playersLevel != tankLevel)
         {
             tankLevel = GameManager.playersLevel;
             tankAnimator.SetInteger("Tank Level", tankLevel);
         }
         if (isShieldActtive)
         {
             if (Time.time - shieldToogleTime >= shieldDuration)
             {
                 ShieldToogle();
             }
         }
         playersShield.SetActive(isShieldActtive);
     }
 }