Exemple #1
0
        public void Attack(IFighter target)
        {
            if (target.Alive())
            {
                List <IEffect> dmg    = new List <IEffect>();
                IEquiped       weapon = this.GetItemFromSlot(EquipSlot.RightHand);
                if (weapon != null)
                {
                    weapon.EquipEffects.ForEach(x =>
                    {
                        dmg.Add(x);
                    });
                }
                else
                {
                    dmg.Add(new InstantEffect(EffectTarget.Character, StatType.Health, -20));
                }

                target.Hit(dmg);

                if (!target.Alive())
                {
                    KillEnemy?.Invoke(target);
                }
            }
            else
            {
                StateMachine.Switch2PreviousState();
            }
        }
    Vector3 respawn_pos;    //the position that the player gonna respawn



    // Use this for initialization

    void Start()
    {
        // Variable Setting

        life_count = 3; // player life

        originalJumpSpeed = jumpSpeed;

        originalSpeed = moveSpeed;

        beingCollected = false;

        coins = 0;

        CoinBoost = false;

        GameOver.SetActive(false); // hide game over



        // Get Components/Get Types

        myRigidbody = GetComponent <Rigidbody2D>();

        MyLevelManager = FindObjectOfType <LevelManager>();

        charaterKilling = FindObjectOfType <KillEnemy>();

        checkPointChecker = FindObjectOfType <CheckPointController>();
    }
Exemple #3
0
 public void LoadContent()
 {
     LargeTarget.LoadContent(MyGame.Manager.ImageManager.TargetLargeRectangle);
     SmallTarget.LoadContent(MyGame.Manager.ImageManager.TargetSmallRectangle);
     KillEnemy.LoadContent(MyGame.Manager.ImageManager.EnemyRectangles);
     targetFast = false;
 }
Exemple #4
0
    public void TryAttack(KillEnemy enemy, Transform playerTrans, Animator anim)
    {
        bool b = false;

        //Dash to the enemy if it is in combat area but out of your punch range
        if (enemy != null &&
            Vector3.Distance(enemy.transform.position, playerTrans.position) > _attackRangeDistance &&
            Vector3.Distance(enemy.transform.position, playerTrans.position) <= _maxDashDistance &&
            b)
        {
            Vector3 endPos = enemy.transform.position + ((playerTrans.position - enemy.transform.position).normalized * _attackRangeDistance);

            Debug.Log("Dash");
            _dash.CallbackFunctions += AttackAction;
            _dash.Dash(endPos, false);
            playerTrans.LookAt(new Vector3(enemy.transform.position.x, playerTrans.position.y, enemy.transform.position.z));
        }

        //Normal attack
        else
        {
            if (enemy != null &&
                Vector3.Distance(enemy.transform.position, playerTrans.position) <= _attackRangeDistance)
            {
                playerTrans.LookAt(new Vector3(enemy.transform.position.x, playerTrans.position.y, enemy.transform.position.z));
            }
            playerTrans.GetComponent <Rigidbody>().velocity = Vector3.zero;

            float impuls = _playerData.isGrounded? _impulseForce : _airImpulseForce;
            playerTrans.GetComponent <Rigidbody>().AddForce(playerTrans.forward * impuls, ForceMode.Impulse);

            AttackAction(anim);
        }
    }
    private void TargettingEnemies()
    {
        List <KillEnemy> selectionUnits = new List <KillEnemy>();
        KillEnemy        temp           = null;
        float            dist           = 0;

        _cameraData.CurrentAngle = _cameraData.TargetAngle;

        foreach (KillEnemy enemy in KillEnemy.EnemiesList)
        {
            Vector3 screenPos = _cameraData.CameraController.GetComponent <Camera>().WorldToScreenPoint(enemy.transform.position);
            Vector2 sP        = new Vector2(screenPos.x, screenPos.y);

            RaycastHit hit;

            if (Physics.Raycast(_playerData.ActionController.Transf.position, enemy.transform.position - _playerData.ActionController.Transf.position,
                                out hit, Vector3.Distance(_playerData.ActionController.Transf.position, enemy.transform.position) + 1f, _layerMask))
            {
                if (Vector2.Distance(sP, new Vector2(Screen.width * 0.5f, Screen.height * 0.5f)) < ((_cameraData.TargetRadius * 0.01f) * (Screen.height * 0.5f)) && hit.transform.gameObject == enemy.gameObject)
                {
                    selectionUnits.Add(enemy);
                }
            }
        }

        if (selectionUnits.Count == 0)
        {
            return;
        }

        foreach (KillEnemy enemy in selectionUnits)
        {
            if (temp == null || Vector3.Distance(_playerData.ActionController.Transf.position, enemy.transform.position) < dist)
            {
                temp = enemy;
                dist = Vector3.Distance(_playerData.ActionController.Transf.position, enemy.transform.position);
            }
        }

        _cameraData.EnemyTargeted = temp;

        if (_cameraData.EnemyTargeted != null)
        {
            _cameraData.CurrentCamType = DataContainer_Camera.CamType.Targetted;
        }
    }
    /*** double jump - powerup1
     *   triple coin - powerup2
     *   faster movement - powerup3
     *   extra life - powerup4
     ***/

    // Use this for initialization
    void Start()
    {
        scoresAdded = false;

        db       = FindObjectOfType <databaseController>();
        userName = "******";
        // Variable Setting
        life_count        = 3; // player life
        originalJumpSpeed = jumpSpeed;
        originalSpeed     = moveSpeed;
        beingCollected    = false;
        coins             = 0;
        CoinBoost         = false;
        GameOver.SetActive(false); // hide game over
        isSpeedBoost            = false;
        invincibleToSpikeDamage = false;


        // Get Components/Get Types
        myRigidbody       = GetComponent <Rigidbody2D>();
        MyLevelManager    = FindObjectOfType <LevelManager>();
        charaterKilling   = FindObjectOfType <KillEnemy>();
        checkPointChecker = FindObjectOfType <CheckPointController>();
        myAnim            = FindObjectOfType <Animator>();


        //Get history coins number
        totalCoins = PlayerPrefs.GetInt("totalcoins");

        if (PlayerPrefs.GetInt("hasPowerUp4") == 1)
        {
            life_count = 5;
        }

        //Get high score
        k         = FindObjectOfType <KillEnemy>();
        highScore = PlayerPrefs.GetInt("highscore");
    }
Exemple #7
0
    //this method check if there are enemies in an area around the player
    private void CombatArea()
    {
        List <KillEnemy> selectionUnits = new List <KillEnemy>();
        KillEnemy        temp           = null;
        Vector3          playerPos      = _playerData.ActionController.Transf.position;
        float            dist           = 0;

        //check all the enemies in the area
        foreach (KillEnemy enemy in KillEnemy.EnemiesList)
        {
            if ((enemy.transform.position.y > playerPos.y - 1f && enemy.transform.position.y < playerPos.y + 1f) && Vector3.Distance(playerPos, enemy.transform.position) <= _cameraData.CombatRange)
            {
                RaycastHit hit;

                if (Physics.Raycast(playerPos, (enemy.transform.position - playerPos).normalized, out hit, Mathf.Infinity) && hit.transform.gameObject == enemy.gameObject)
                {
                    selectionUnits.Add(enemy);
                }
            }
        }

        if (selectionUnits.Count == 0)
        {
            _cameraData.EnemyTargeted = null;
            return;
        }

        //select the closest enemy in the area
        if (_playerData.DirectionVector.magnitude == 0)
        {
            foreach (KillEnemy enemy in selectionUnits)
            {
                float newDist = Vector3.Distance(_playerData.ActionController.Transf.position, enemy.transform.position);

                if (temp == null || newDist < dist)
                {
                    temp = enemy;
                    dist = newDist;
                }
            }
        }

        else
        {
            foreach (KillEnemy enemy in selectionUnits)
            {
                float enemyDot   = -Vector3.Dot(_playerData.DirectionVector.normalized, (_playerData.ActionController.Transf.position - enemy.transform.position).normalized);
                float enemyAngle = Vector3.Angle(_playerData.DirectionVector, enemy.transform.position - _playerData.ActionController.Transf.position);

                if (temp == null)
                {
                    temp = enemy;
                    continue;
                }

                float tempDot = Vector3.Dot(_playerData.DirectionVector, _playerData.ActionController.Transf.position - temp.transform.position);

                if (enemyDot > tempDot && enemyAngle < 90f)
                {
                    temp = enemy;
                }
            }
        }


        _cameraData.EnemyTargeted = temp;
    }
 // Use this for initialization
 void Start()
 {
     k = FindObjectOfType <KillEnemy>();
 }