Exemple #1
0
        public EnemySpawner(int numEnemies)
        {
            _dungeon = ServiceLocator <IDungeonMap> .GetService();

            _badDudes      = new List <Enemy>(numEnemies);
            InitialEnemies = numEnemies;
        }
Exemple #2
0
        public Enemy(Texture2D texture, Vector2 location)
        {
            _dungeon = ServiceLocator <IDungeonMap> .GetService();

            SpriteTexture = texture;
            Location      = location;
            IsActive      = true;
        }
Exemple #3
0
        public Projectile(Weapon weapon)
        {
            BaseWeapon    = weapon;
            SpriteTexture = weapon.SpriteTexture;
            // Hold bullet speed internally so we can decrement it over time
            _bulletSpeed = weapon.BulletSpeed;
            _dungeon     = ServiceLocator <IDungeonMap> .GetService();

            _spawner = ServiceLocator <IEnemySpawner> .GetService();
        }
Exemple #4
0
        /// <summary>
        /// Ensure the camera is always within game world, clamps position on movement based on
        /// generated map.
        /// </summary>
        /// <param name="position"></param>
        /// <returns></returns>
        private Vector2 MapToClampedPosition(Vector2 position)
        {
            IDungeonMap dungeon = ServiceLocator <IDungeonMap> .GetService();

            var map = dungeon.CurrentMap;
            var min = new Vector2(Origin.X, Origin.Y);
            var max = new Vector2(
                (-1 * map.Width * dungeon.TileSize) + Bounds.Width,
                (-1 * map.Height * dungeon.TileSize) + Bounds.Height
                );

            return(Vector2.Clamp(position, max, min));
        }
Exemple #5
0
        public bool WithinViewportBounds(Sprite sprite, Vector2 direction)
        {
            IDungeonMap dungeon = ServiceLocator <IDungeonMap> .GetService();

            var map = dungeon.CurrentMap;

            // Upper-left
            var minXCheck = sprite.Location.X > (Bounds.Width * 0.5f) - (sprite.SpriteTexture.Width * 0.5f);
            var minYCheck = sprite.Location.Y > (Bounds.Height * 0.5f) - (sprite.SpriteTexture.Height * 0.5f);

            // Lower-right
            var maxXCheck = sprite.Location.X < ((map.Width * dungeon.TileSize) - (Bounds.Width * 0.5f) - (sprite.SpriteTexture.Width * 0.5f));
            var maxYCheck = sprite.Location.Y < ((map.Height * dungeon.TileSize) - (Bounds.Height * 0.5f) - (sprite.SpriteTexture.Height * 0.5f));

            return(((minXCheck && maxXCheck) || direction.Y != 0.0f) && ((minYCheck && maxYCheck) || direction.X != 0.0f));
        }
        public static Vector2 GetInitialPlayerPosition(this IDungeonMap dungeon)
        {
            ICamera camera = ServiceLocator <ICamera> .GetService();

            foreach (var cell in dungeon.CurrentMap.GetAllCells())
            {
                if (cell.IsWalkable)
                {
                    Vector2 firstAvailableCell = new Vector2(cell.X * dungeon.TileSize, cell.Y * dungeon.TileSize);
                    camera.SetLocation(firstAvailableCell);
                    return(firstAvailableCell);
                }
            }

            throw new InvalidOperationException();
        }
Exemple #7
0
        public Player()
        {
            _dungeon = ServiceLocator <IDungeonMap> .GetService();

            EquippedWeapon = WeaponTypes.Pistol;
        }
 public RunningState()
 {
     _dungeon = ServiceLocator <IDungeonMap> .GetService();
 }