예제 #1
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);
    }
예제 #2
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));
        }
예제 #3
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);
 }