Пример #1
1
        public Fruit(World world, Vector2 position, FruitType fruitType)
            : base(world, position)
        {
            this._fruitType = fruitType;
            switch (fruitType)
                {
                case FruitType.Apple:
                    this.Energy = 6;
                    break;
                case FruitType.Watermelon:
                    this.Energy = 8;
                    break;
                case FruitType.Pineapple:
                    this.Energy = 10;
                    break;
                case FruitType.Strawberry:
                    this.Energy = 12;
                    break;
                case FruitType.Cherries:
                    this.Energy = 14;
                    break;
                case FruitType.Acorn:
                    this.Energy = 16;
                    break;
                default:
                    throw new InvalidOperationException();
                }

            string textureName = string.Format("Sprites/Fruit/{0:G}", _fruitType);
            var a = Animation.StaticAnimation(World, textureName);
            this.Ap.PlayAnimation(a);
        }
Пример #2
0
 public Mushroom(World world, Vector2 position)
     : base(world, position)
 {
     var a = Animation.StaticAnimation(World, "Sprites/Props/Mushroom");
     this.Ap.PlayAnimation(a);
     this.Energy = 40;
 }
Пример #3
0
 /// <summary>
 /// Constructs a new boulder.
 /// </summary>
 public Boulder(World world, Vector2 position)
     : base(world, position)
 {
     LoadContent();
     Direction = Direction.None;
     Ap.PlayAnimation(_staticImage);
 }
Пример #4
0
 public CrumblyWall(World world, Vector2 position, string textureName, int energy)
     : base(world, position)
 {
     var a = Animation.StaticAnimation(World, textureName);
     this.Ap.PlayAnimation(a);
     this.Energy = energy;
     this._initialEnergy = energy;
 }
Пример #5
0
        public Grave(World world, Vector2 position)
            : base(world, position)
        {
            this.Energy = 255;

            var a = Animation.StaticAnimation(World, "Sprites/Props/Grave");
            this.Ap.PlayAnimation(a);
        }
Пример #6
0
        public ForceField(World world, Vector2 position, int crystalRequired)
            : base(world, position)
        {
            this._crystalRequired = crystalRequired;

            var a = Animation.LoopingAnimation(World, "Sprites/Props/ForceField", 3);
            this.Ap.PlayAnimation(a);
        }
Пример #7
0
 public Mine(World world, Vector2 position)
     : base(world, position)
 {
     this.Energy = 240;
     this._staticUnarmedAnimation = Animation.StaticAnimation(world, "Sprites/Shot/MineUnarmed");
     this._movingUnarmedAnimation = Animation.SingleRunAnimation(world, "Sprites/Shot/MineUnarmed", 4);
     this._armedAnimation = Animation.LoopingAnimation(world, "Sprites/Shot/MineArmed", 4);
     this.Ap.PlayAnimation(this._staticUnarmedAnimation);
     this._mineState = new InactiveState(this);
 }
Пример #8
0
        /// <summary>
        /// Constructs a new static item object
        /// </summary>
        /// <param name="world">A reference to the current world</param>
        /// <param name="position">The initial position of the object</param>
        protected StaticItem(World world, Vector2 position)
        {
            if (world == null)
                throw new ArgumentNullException("world");
            if (position == null)
                throw new ArgumentNullException("position");

            this._world = world;
            this.Position = position;
        }
Пример #9
0
        public Crystal(World world, Vector2 position, int id, int score, int energy)
            : base(world, position)
        {
            this.CrystalId = id;
            this.Score = score;
            this.Energy = energy;

            var a = Animation.LoopingAnimation(World, "Sprites/Crystal/Crystal", 4);
            this.Ap.PlayAnimation(a);
        }
Пример #10
0
        public Explosion(World world, Vector2 position, int energy)
            : base(world, position)
        {
            this.Energy = energy;
            var a = Animation.SingleRunAnimation(World, "Sprites/Props/LongBang", 2);
            Ap.PlayAnimation(a);
            Ap.AnimationFinished += AnimationFinished;

            this._isExtant = true;
        }
Пример #11
0
 private static bool DoesMonsterHaveClearShotAtPlayer(World world, TilePos monsterTilePos, Direction firingDirection)
 {
     int i = 0;
     var testPos = monsterTilePos;
     var playerTilePos = world.Player.TilePosition;
     for ( ; testPos != playerTilePos && i < 20; testPos = testPos.GetPositionAfterOneMove(firingDirection), i++)
         {
         bool isClear = world.CanTileBeOccupied(testPos, false);
         if (!isClear)
             return false;
         }
     return true;
 }
        public InteractionWithMovingItems(World world, MovingItem movingItem1, MovingItem movingItem2)
        {
            if (world == null)
                throw new ArgumentNullException("world");
            if (movingItem1 == null)
                throw new ArgumentNullException("movingItem1");
            if (movingItem2 == null)
                throw new ArgumentNullException("movingItem2");

            this._world = world;
            this._movingItem1 = movingItem1;
            this._movingItem2 = movingItem2;
        }
        public ShotAndMovingItemInteraction(World world, Shot shot, MovingItem movingItem)
        {
            if (world == null)
                throw new ArgumentNullException("world");
            if (shot == null)
                throw new ArgumentNullException("shot");
            if (movingItem == null)
                throw new ArgumentNullException("movingItem");

            this._world = world;
            this._shot = shot;
            this._movingItem = movingItem;
        }
Пример #14
0
        public void FireIfYouLike(StaticItem source, World world)
        {
            Direction firingDirection = DetermineFiringDirection(source.TilePosition, world.Player.TilePosition);
            if (firingDirection == Direction.None)
                return;
            if (!DoesMonsterHaveClearShotAtPlayer(world, source.TilePosition, firingDirection))
                return;

            var startPos = source.TilePosition.ToPosition() + firingDirection.ToVector() * new Vector2(Tile.Width, Tile.Height) / 2;
            var shot = new StandardShot(world, startPos, firingDirection, source.Energy >> 2, ShotType.Monster);
            world.AddShot(shot);
            world.Game.SoundPlayer.Play(GameSound.MonsterShoots);
        }
        public ShotAndStaticItemInteraction(World world, Shot shot, StaticItem staticItem)
        {
            if (world == null)
                throw new ArgumentNullException("world");
            if (shot == null)
                throw new ArgumentNullException("shot");
            if (staticItem == null)
                throw new ArgumentNullException("staticItem");
            if (staticItem is MovingItem)
                throw new ArgumentOutOfRangeException("staticItem");

            this._world = world;
            this._shot = shot;
            this._staticItem = staticItem;
        }
        public StaticItemAndStaticItemInteraction(World world, StaticItem staticItem1, StaticItem staticItem2)
        {
            if (world == null)
                throw new ArgumentNullException("world");
            if (staticItem1 == null)
                throw new ArgumentNullException("staticItem1");
            if (staticItem2 == null)
                throw new ArgumentNullException("staticItem2");
            if (staticItem1 is MovingItem)
                throw new ArgumentOutOfRangeException("staticItem1");
            if (staticItem2 is MovingItem)
                throw new ArgumentOutOfRangeException("staticItem2");

            this._world = world;
            this._staticItem1 = staticItem1;
            this._staticItem2 = staticItem2;
        }
        public MovingItemAndStaticItemInteraction(World world, MovingItem movingItem, StaticItem staticItem)
        {
            if (world == null)
                throw new ArgumentNullException("world");
            if (movingItem == null)
                throw new ArgumentNullException("movingItem");
            if (staticItem == null)
                throw new ArgumentNullException("staticItem");

            if (movingItem is Shot)
                throw new ArgumentOutOfRangeException("movingItem");
            if (staticItem is MovingItem)
                throw new ArgumentOutOfRangeException("staticItem");

            this._world = world;
            this._movingItem = movingItem;
            this._staticItem = staticItem;
        }
Пример #18
0
        /// <summary>
        /// Constructs a new player.
        /// </summary>
        public Player(World world, Vector2 position, int energy)
            : base(world, position)
        {
            // Load animated textures.
            this._leftRightMovingAnimation = Animation.LoopingAnimation(World, "Sprites/Player/PlayerLeftFacing", 1);
            this._upMovingAnimation = Animation.LoopingAnimation(World, "Sprites/Player/PlayerUpFacing", 1);
            this._downMovingAnimation = Animation.LoopingAnimation(World, "Sprites/Player/PlayerDownFacing", 1);
            this._leftRightStaticAnimation = Animation.StaticAnimation(World, "Sprites/Player/PlayerLeftFacing");
            this._upStaticAnimation = Animation.StaticAnimation(World, "Sprites/Player/PlayerUpFacing");
            this._downStaticAnimation = Animation.StaticAnimation(World, "Sprites/Player/PlayerDownFacing");

            Ap.NewFrame += PlayerSpriteNewFrame;

            this._weapon1 = new StandardPlayerWeapon();
            this._weapon2 = new MineLayer();
            Reset(position, energy);

            this._playerMovesFootOne = world.Game.SoundPlayer.GetSoundEffectInstance(GameSound.PlayerMoves);
            this._playerMovesFootTwo = world.Game.SoundPlayer.GetSoundEffectInstance(GameSound.PlayerMoves);
            this._playerMovesFootTwo.Pitch = -0.15f;
        }
Пример #19
0
        public Bang(World world, Vector2 position, BangType bangType)
            : base(world, position)
        {
            Animation a;
            switch (bangType)
                {
                case BangType.Short:
                    a = Animation.SingleRunAnimation(World, "Sprites/Props/ShortBang", 3);
                    break;
                case BangType.Long:
                    a = Animation.SingleRunAnimation(World, "Sprites/Props/LongBang", 3);
                    break;
                default:
                    throw new ArgumentOutOfRangeException("bangType");
                }

            Ap.PlayAnimation(a);
            Ap.AnimationFinished += AnimationFinished;

            this._isExtant = true;
        }
        private static bool InteractionInvolvingShot(World world, Shot shot, MovingItem movingItem)
        {
            if (movingItem is Player)
                {
                movingItem.ReduceEnergy(shot.Energy);
                if (movingItem.IsAlive())
                    world.Game.SoundPlayer.Play(GameSound.PlayerInjured);
                world.ConvertShotToBang(shot);
                return true;
                }

            var monster = movingItem as Monster.Monster;
            if (monster != null)
                {
                var result = ShotHitsMonster(world, shot, monster);
                return result;
                }

            var items = new[] { shot, movingItem };
            var explosion = items.OfType<Explosion>().FirstOrDefault();
            if (explosion != null)
                {
                var otherItem = items.Single(item => item != explosion);
                if (otherItem is Shot)
                    {
                    shot.ReduceEnergy(explosion.Energy);
                    return true;
                    }
                }

            var standardShot1 = shot as StandardShot;
            var standardShot2 = movingItem as StandardShot;
            if (standardShot1 != null && standardShot2 != null)
                {
                var result = ShotHitsShot(world, standardShot1, standardShot2);
                return result;
                }

            return false;
        }
Пример #21
0
        public void Fire(StaticItem source, World world, FiringState firingState, Direction direction)
        {
            if (direction == Direction.None)
                throw new ArgumentOutOfRangeException("direction");

            if (firingState != FiringState.Pulse || source.Energy < 4)
                return;
            var startPos = source.TilePosition.ToPosition();
            var shot = new StandardShot(world, startPos, direction, source.Energy >> 2, ShotType.Player);
            if (!shot.CanMoveInDirection(direction))
                return;
            startPos += direction.ToVector() * Tile.Size / 2;
            shot.SetPosition(startPos);

            world.AddShot(shot);
            world.Game.SoundPlayer.Play(GameSound.PlayerShoots);
            _countOfShotsBeforeCostingEnergy--;
            if (_countOfShotsBeforeCostingEnergy < 0)
                {
                _countOfShotsBeforeCostingEnergy = 3;
                source.ReduceEnergy(1);
                }
        }
        public MovingItemAndMovingItemInteraction(World world, MovingItem movingItem1, MovingItem movingItem2)
        {
            if (world == null)
                throw new ArgumentNullException("world");
            if (movingItem1 == null)
                throw new ArgumentNullException("movingItem1");
            if (movingItem2 == null)
                throw new ArgumentNullException("movingItem2");
            if (movingItem1 is Shot)
                throw new ArgumentOutOfRangeException("movingItem1");
            if (movingItem2 is Shot)
                throw new ArgumentOutOfRangeException("movingItem2");

            this._world = world;
            var items = new[] {movingItem1, movingItem2};
            this._player = items.OfType<Player>().SingleOrDefault();
            this._boulder = items.OfType<Boulder>().SingleOrDefault();
            this._mine = items.OfType<Mine>().SingleOrDefault();
            this._monster1 = items.OfType<Monster.Monster>().FirstOrDefault();
            this._monster2 = items.OfType<Monster.Monster>().Skip(1).FirstOrDefault();

            this._moveableObject = items.FirstOrDefault(item => item.Solidity == ObjectSolidity.Moveable);
            this._insubstantialObject = items.FirstOrDefault(item => item.Solidity == ObjectSolidity.Insubstantial);
        }
Пример #23
0
        public StandardShot(World world, Vector2 position, Direction d, int energy, ShotType shotType)
            : base(world, position)
        {
            this.Energy = energy;
            this.ShotType = shotType;
            this._directionOfTravel = d;
            TrySetDirectionAndDestination();

            string textureName;
            switch (this.ShotType)
                {
                case ShotType.Player:
                    textureName = "Sprites/Shot/RedShot";
                    break;
                case ShotType.Monster:
                    textureName = "Sprites/Shot/GreenShot";
                    break;
                default:
                    throw new InvalidOperationException();
                }
            var staticImage = Animation.StaticAnimation(World, textureName);
            Ap.PlayAnimation(staticImage);
            ResetTimeToTravel();
        }
Пример #24
0
 protected Shot(World world, Vector2 position)
     : base(world, position)
 {
 }
Пример #25
0
 public Wall(World world, Vector2 position, string textureName)
     : base(world, position)
 {
     var a = Animation.StaticAnimation(World, textureName);
     this.Ap.PlayAnimation(a);
 }
Пример #26
0
 protected MovingItem(World world, Vector2 position)
     : base(world, position)
 {
     this.MovingTowards = position;
 }
Пример #27
0
        private static Monster.Monster GetMonster(World world, XmlElement mdef)
        {
            string type = mdef.GetAttribute("Type");
            var tilePos = new TilePos(int.Parse(mdef.GetAttribute("Left")), int.Parse(mdef.GetAttribute("Top")));
            Vector2 position = tilePos.ToPosition();
            int e = int.Parse(mdef.GetAttribute("Energy"));
            Monster.Monster result = Monster.Monster.Create(type, world, position, e);
            string direction = mdef.GetAttribute("Direction");
            if (!string.IsNullOrEmpty(direction))
                result.Direction = (Direction)Enum.Parse(typeof(Direction), direction);
            string mobility = mdef.GetAttribute("Mobility");
            if (!String.IsNullOrEmpty(mobility))
                result.Mobility = (MonsterMobility)Enum.Parse(typeof(MonsterMobility), mobility);
            string changeRooms = mdef.GetAttribute("ChangeRooms");
            if (!string.IsNullOrEmpty(changeRooms))
                result.ChangeRooms = (ChangeRooms)Enum.Parse(typeof(ChangeRooms), changeRooms);
            string isEggAttribute = mdef.GetAttribute("IsEgg");
            string timeBeforeHatchingAttribute = mdef.GetAttribute("TimeBeforeHatching");
            if (!string.IsNullOrEmpty(isEggAttribute) && !string.IsNullOrEmpty(timeBeforeHatchingAttribute))
                {
                bool isEgg = Boolean.Parse(isEggAttribute);
                int timeBeforeHatching = int.Parse(timeBeforeHatchingAttribute);
                if (isEgg)
                    {
                    result.SetDelayBeforeHatching(timeBeforeHatching | 1);
                    }
                }
            string laysMushrooms = mdef.GetAttribute("LaysMushrooms");
            if (!string.IsNullOrEmpty(laysMushrooms))
                {
                result.LaysMushrooms = Boolean.Parse(laysMushrooms);
                }
            string laysEggs = mdef.GetAttribute("LaysEggs");
            if (!string.IsNullOrEmpty(laysEggs))
                {
                result.LaysEggs = Boolean.Parse(laysEggs);
                }
            string splitsOnHit = mdef.GetAttribute("SplitsOnHit");
            if (!string.IsNullOrEmpty(splitsOnHit))
                {
                result.SplitsOnHit = Boolean.Parse(splitsOnHit);
                }

            return result;
        }
Пример #28
0
        private IEnumerable<Wall> GetLayout(World world, out Tile[,] tiles)
        {
            var worldDef = (XmlElement)this._xmlDoc.SelectSingleNode("World");
            if (worldDef == null)
                throw new InvalidOperationException("No World element found.");
            int width = int.Parse(worldDef.GetAttribute("Width"));
            int height = int.Parse(worldDef.GetAttribute("Height"));
            var layout = (XmlElement) this._xmlDoc.SelectSingleNode("World/Layout");
            if (layout == null)
                throw new InvalidOperationException("No Layout element found.");
            tiles = new Tile[width, height];

            var lines = layout.InnerText.Trim().Replace("\r\n", "\t").Split('\t');
            if (lines.GetLength(0) != height)
                throw new InvalidOperationException();

            for (int y = 0; y < height; y++)
                {
                lines[y] = lines[y].Trim();
                if (lines[y].Length != width)
                    throw new InvalidOperationException();
                }

            var result = new List<Wall>();
            foreach (WorldArea wa in this._worldAreas)
                {
                if (wa.TileDefinitions.Count == 0)
                    continue;

                string defaultFloorName = wa.TileDefinitions.Values.Single(td => td.TileTypeByMap == TileTypeByMap.Floor).TextureName;
                foreach (TilePos p in wa.Area.PointsInside())
                    {
                    char symbol = lines[p.Y][p.X];
                    TileDefinition td;
                    if (!wa.TileDefinitions.TryGetValue(symbol, out td))
                        {
                        string text = string.Format("Don't know what symbol {0} indicates in world area {1}", symbol, wa.Id);
                        throw new InvalidOperationException(text);
                        }
                    Texture2D floor;
                    switch (td.TileTypeByMap)
                        {
                        case TileTypeByMap.Wall:
                            floor = world.LoadTexture("Tiles/" + defaultFloorName);
                            tiles[p.X, p.Y] = new Tile(floor, TileTypeByMap.Wall);
                            var wall = new Wall(world, p.ToPosition(), "Tiles/" + td.TextureName);
                            result.Add(wall);
                            break;
                        case TileTypeByMap.Floor:
                            floor = world.LoadTexture("Tiles/" + td.TextureName);
                            tiles[p.X, p.Y] = new Tile(floor, TileTypeByMap.Floor);
                            break;
                        case TileTypeByMap.PotentiallyOccupied:
                            floor = world.LoadTexture("Tiles/" + defaultFloorName);
                            tiles[p.X, p.Y] = new Tile(floor, symbol);
                            break;
                        default:
                            throw new InvalidOperationException();
                        }
                    }
                }

            return result;
        }
Пример #29
0
 private IEnumerable<Fruit> GetListOfFruit(World world, ref Tile[,] tiles)
 {
     var result = new List<Fruit>();
     foreach (WorldArea wa in this._worldAreas)
         {
         foreach (FruitDefinition fd in wa.FruitDefinitions.Values)
             {
             for (int i = 0; i < fd.FruitQuantity; )
                 {
                 var tilePos = new TilePos(wa.Area.X + Rnd.Next(wa.Area.Width), wa.Area.Y + Rnd.Next(wa.Area.Height));
                 Tile t = tiles[tilePos.X, tilePos.Y];
                 if (!t.IsFree)
                     continue;
                 tiles[tilePos.X, tilePos.Y].SetOccupationByFruit();
                 Vector2 position = tilePos.ToPosition();
                 var f = new Fruit(world, position, fd.FruitType);
                 result.Add(f);
                 i++;
                 }
             }
         }
     return result;
 }
Пример #30
0
        public IEnumerable<StaticItem> GetGameObjects(World world)
        {
            var exceptions = new List<TileException>();
            Tile[,] tiles;

            var result = new List<StaticItem>();
            var walls = GetLayout(world, out tiles);
            result.AddRange(walls);

            int initialWorldId = GetStartingWorldAreaId();
            StartState ss = GetStartStateForWorldAreaId(initialWorldId);

            var player = new Player(world, ss.PlayerPosition.ToPosition(), ss.PlayerEnergy);
            result.Add(player);
            var playerStartPositions = this._worldAreas.Where(wa => wa.StartState != null).Select(wa => new Grave(world, wa.StartState.PlayerPosition.ToPosition()));
            exceptions.AddRange(SetTileOccupation(ref tiles, playerStartPositions, false));

            var objects = this._xmlDoc.SelectNodes("World/Objects/*");
            if (objects == null)
                throw new InvalidOperationException("No Objects node in world definition.");
            foreach (XmlElement definition in objects)
                {
                StaticItem[] newItems;

                switch (definition.LocalName)
                    {
                    case "Boulder":
                        {
                        newItems = new StaticItem[] { GetBoulder(world, definition) };
                        break;
                        }

                    case "Monster":
                        {
                        newItems = new StaticItem[] { GetMonster(world, definition) };
                        break;
                        }

                    case "Crystal":
                        {
                        newItems = new StaticItem[] { GetCrystal(world, definition) };
                        break;
                        }

                    case "ForceField":
                        {
                        newItems = GetForceFields(world, definition).Cast<StaticItem>().ToArray();
                        break;
                        }

                    case "CrumblyWall":
                        {
                        newItems = new StaticItem[] { GetCrumblyWall(world, definition) };
                        break;
                        }

                    default:
                        throw new InvalidOperationException("Unknown object " + definition.LocalName);
                    }

                result.AddRange(newItems);
                exceptions.AddRange(SetTileOccupation(ref tiles, newItems.Where(item => !(item is Monster.Monster) || ((Monster.Monster) item).IsStill), false));
                }

            var fruit = GetListOfFruit(world, ref tiles);
            result.AddRange(fruit);

            exceptions.AddRange(SetTileOccupation(ref tiles, result.OfType<Monster.Monster>().Where(m => !m.IsStill), true));

            ReviewPotentiallyOccupiedTiles(ref tiles, exceptions);

            if (exceptions.Count != 0)
                {
                string message = string.Empty;
                var errors = exceptions.Where(te=>te.Type == TileExceptionType.Error).ToList();
                var warnings = exceptions.Where(te=>te.Type == TileExceptionType.Warning).ToList();
                foreach (TileException te in errors)
                    {
                    if (message.Length != 0)
                        message += "\r\n";
                    message += string.Format("{0} - {1}", te.Type, te.Message);
                    }
                if (warnings.Any())
                    {
                    if (message.Length != 0)
                        message += "\r\n";
                    foreach (TileException te in warnings)
                        {
                        if (message.Length != 0)
                            message += "\r\n";
                        message += string.Format("{0} - {1}", te.Type, te.Message);
                        }
                    }
                if (errors.Any())
                    throw new InvalidOperationException(message);
                Trace.WriteLine(message);
                var dr = MessageBox.Show(message, "Warnings", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
                if (dr == DialogResult.Cancel)
                    throw new InvalidOperationException(message);
                }

            this._tiles = tiles;
            return result;
        }