예제 #1
0
    private void Start()
    {
        base.Initial();
        Animator animator;

        animator = GetComponent <Animator>();

        #region 设置角色控制器的大小
        control        = GetComponent <CharacterController>();
        control.center = new Vector3(0, 1, 0);
        control.height = 2;
        control.radius = 0.23f;
        #endregion

        #region 添加动画
        PlayerIdel playerIdel = new PlayerIdel(animator);
        fsmManager.AddState(playerIdel);
        PlayerWalk playerWalk = new PlayerWalk(animator);
        fsmManager.AddState(playerWalk);
        PlayerRun playerRun = new PlayerRun(animator);
        fsmManager.AddState(playerRun);
        PlayerAttack playerAttack = new PlayerAttack(animator);
        fsmManager.AddState(playerAttack);
        PlayerAttacked playerAttacked = new PlayerAttacked(animator, this);
        fsmManager.AddState(playerAttacked);
        PlayerDie playerDie = new PlayerDie(animator);
        fsmManager.AddState(playerDie);
        #endregion
    }
예제 #2
0
 void Awake()
 {
     anim = GetComponent <Animator>();
     playerAudio = GetComponent <AudioSource>();
     playerMovement = GetComponent <PlayerMovement>();
     playerAttacked = GetComponent <PlayerAttacked>();
     currentHealth = startingHealth;
 }
 void Awake()
 {
     anim           = GetComponent <Animator>();
     playerAudio    = GetComponent <AudioSource>();
     playerMovement = GetComponent <PlayerMovement>();
     playerAttacked = GetComponent <PlayerAttacked>();
     currentHealth  = startingHealth;
 }
예제 #4
0
    private bool PlayerAttack()
    {
        Ray        ray = Camera.main.ScreenPointToRay(mouse.position.ReadValue());
        RaycastHit hit;

        if (Physics.Raycast(ray, out hit, Mathf.Infinity, enemyLayer))
        {
            PlayerAttacked?.Invoke(hit.transform.GetComponent <Enemy>());
            return(true);
        }

        return(false);
    }
예제 #5
0
        public void Attack(int x, int y)
        {
            int yPos = Game.PlayerRef.Position.Y + y;
            int xPos = Game.PlayerRef.Position.X + x;

            int      oldPlayerPosX = int.Parse(Game.PlayerRef.Position.X.ToString());
            int      oldPlayerPosY = int.Parse(Game.PlayerRef.Position.Y.ToString());
            Position previousPos   = new Position(oldPlayerPosX, oldPlayerPosY);


            if (Map.MapTiles[yPos][xPos] is EmptySpaceTile)
            {
                return;
            }
            else if (Map.MapTiles[yPos][xPos] is WallTile)
            {
                Map.MapTiles[yPos][xPos] = new EmptySpaceTile();
                Game.PlayerRef.Score    += 1;
            }
            else if (Map.MapTiles[yPos][xPos] is AbstractMonster)
            {
                AbstractMonster monster   = null;
                Position        attackPos = Game.PlayerRef.Position + new Position(x, y);
                monster = AbstractMonster.Monsters.Find(item => item.Position == attackPos);
                if (monster != null)
                {
                    Game.PlayerRef.Attack(attackPos);
                }
                MonsterAttackOnPlayerProximity(yPos, xPos);
            }
            else
            {
                return;
            }

            PlayerAttacked?.Invoke(new Position(xPos, yPos));
        }
예제 #6
0
 /// <summary>
 ///     Fires an event to all subscribers saying the player is dealing damage to that area.
 /// </summary>
 /// <param name="damageArea"></param>
 /// <param name="damage"></param>
 public void DealDamage(Rectangle damageArea, int damage)
 {
     PlayerAttacked?.Invoke(damageArea, damage);
 }