Example #1
0
 public Tile this[TilePos tp]
 {
     get
         {
         return this._tiles[tp.X, tp.Y];
         }
 }
Example #2
0
        /// <summary>
        /// Returns a TilePos object corresponding to the specified co-ordinate
        /// </summary>
        /// <param name="position">The position within the world. For a GameObject, pass in the co-ordinates of the object's origin.</param>
        /// <returns>A TilePos that contains the specified co-ordinate</returns>
        public static TilePos TilePosFromPosition(Vector2 position)
            {
            var intx = (int)position.X / Tile.Width;
            var inty = (int)position.Y / Tile.Height;

            var result = new TilePos(intx, inty);
            return result;
            }
 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;
 }
 private static Direction DetermineFiringDirection(TilePos fromTilePos, TilePos towardsTilePos)
 {
     int xDiff = Math.Sign(fromTilePos.X - towardsTilePos.X);
     int yDiff = Math.Sign(fromTilePos.Y - towardsTilePos.Y);
     if (xDiff == 0)
         {
         switch (yDiff)
             {
             case 1: return Direction.Up;
             case -1: return Direction.Down;
             }
         }
     else if (yDiff == 0)
         {
         switch (xDiff)
             {
             case 1: return Direction.Left;
             case -1: return Direction.Right;
             }
         }
     return Direction.None;
 }
Example #5
0
        public static TilePos FromMortonCode(int mortonCode)
            {
            if (mortonCode < 0)
                throw new ArgumentOutOfRangeException("mortonCode");

            int x = Compact1By1(mortonCode >> 0);
            int y = Compact1By1(mortonCode >> 1);
            var result = new TilePos(x, y);
            return result;
            }
Example #6
0
 /// <summary>
 /// Draws the floor of the current view
 /// </summary>
 private void DrawFloorTiles(ISpriteBatch spriteBatch, Rectangle r)
 {
     // draw the floor
     for (int y = r.Top; y < r.Bottom; y++)
         {
         for (int x = r.Left; x < r.Right; x++)
             {
             var tp = new TilePos(x, y);
             Texture2D texture = this._wl[tp].Floor;
             if (texture != null)
                 {
                 Vector2 position = new Vector2(x, y) * Tile.Size;
                 spriteBatch.DrawEntireTexture(texture, position);
                 }
             }
         }
 }
Example #7
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;
 }
Example #8
0
 public void AddGrave(TilePos tp)
 {
     var g = new Grave(this, tp.ToPosition());
     this.GameObjects.Add(g);
 }
Example #9
0
 private static Crystal GetCrystal(World world, XmlElement cdef)
 {
     var id = int.Parse(cdef.GetAttribute("Id"));
     var tilePos = new TilePos(int.Parse(cdef.GetAttribute("Left")), int.Parse(cdef.GetAttribute("Top")));
     var position = tilePos.ToPosition();
     var score = int.Parse(cdef.GetAttribute("Score"));
     var energy = int.Parse(cdef.GetAttribute("Energy"));
     var result = new Crystal(world, position, id, score, energy);
     return result;
 }
Example #10
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;
        }
Example #11
0
 private static Boulder GetBoulder(World world, XmlElement bdef)
 {
     var tilePos = new TilePos(int.Parse(bdef.GetAttribute("Left")), int.Parse(bdef.GetAttribute("Top")));
     var position = tilePos.ToPosition();
     var result = new Boulder(world, position);
     return result;
 }
Example #12
0
 private static CrumblyWall GetCrumblyWall(World world, XmlElement wdef)
 {
     var tilePos = new TilePos(int.Parse(wdef.GetAttribute("Left")), int.Parse(wdef.GetAttribute("Top")));
     var position = tilePos.ToPosition();
     var energy = int.Parse(wdef.GetAttribute("Energy"));
     var textureName = wdef.GetAttribute("Texture");
     var result = new CrumblyWall(world, position, "Tiles/" + textureName, energy);
     return result;
 }
 public static bool ContainsTile(this Rectangle rect, TilePos tp)
 {
     var p = new Point(tp.X, tp.Y);
     var result = rect.Contains(p);
     return rect.Contains(p);
 }
Example #14
0
 public void AddMushroom(TilePos tp)
 {
     var m = new Mushroom(this, tp.ToPosition());
     this.GameObjects.Add(m);
 }
Example #15
0
        public void MoveUpALevel()
        {
            if (!this.Player.IsAlive())
                return;

            int currentWorldAreaId = this._wl.GetWorldAreaIdForTilePos(this.Player.TilePosition);
            int maxId = this._wl.GetMaximumWorldAreaId();
            var newState = Enumerable.Range(currentWorldAreaId + 1, maxId - currentWorldAreaId).Select(i => this._wl.GetStartStateForWorldAreaId(i)).FirstOrDefault(startState => startState != null);
            if (newState == null)
                return;

            var crystals = this.GameObjects.DistinctItemsOfType<Crystal>().Where(c => this._wl.GetWorldAreaIdForTilePos(c.TilePosition) == currentWorldAreaId);
            foreach (var c in crystals)
                {
                var i = new InteractionWithStaticItems(this, c, this.Player);
                i.Collide();
                }
            this.Player.Reset(newState.PlayerPosition.ToPosition(), newState.PlayerEnergy);
            this.GameObjects.UpdatePosition(this.Player);
            var boulder = this.GameObjects.DistinctItemsOfType<Boulder>().FirstOrDefault();
            if (boulder != null)
                {
                TilePos? tp = null;
                for (int i = 0; i < 16; i++)
                    {
                    int x = (i % 2 == 0) ? 7 - (i / 2) : 8 + ((i - 1) / 2);
                    var potentialPosition = new TilePos(x, newState.PlayerPosition.Y);
                    if (!IsStaticItemOnTile(potentialPosition))
                        {
                        tp = potentialPosition;
                        break;
                        }
                    }
                if (tp.HasValue)
                    {
                    boulder.Reset(tp.Value.ToPosition());
                    this.GameObjects.UpdatePosition(boulder);
                    }
                }
            Point roomStart = GetContainingRoom(this.Player.Position).Location;
            this.Game.SpriteBatch.WindowOffset = new Vector2(roomStart.X, roomStart.Y);
        }
Example #16
0
 /// <summary>
 /// Gets the collision mode of the tile at a particular location.
 /// This method handles tiles outside of the levels boundries by making it
 /// impossible to escape past the left or right edges, but allowing things
 /// to jump beyond the top of the World and fall off the bottom.
 /// </summary>
 public bool IsTileWithinWorld(TilePos tp)
 {
     var x = tp.X;
     var y = tp.Y;
     var result = !(x < 0 || x >= this._wl.Width || y < 0 || y >= this._wl.Height);
     return result;
 }
Example #17
0
 /// <summary>
 /// Tests whether any non-moving items are currently occupying the specified position
 /// </summary>
 /// <remarks>This is only to be used when looking to place non-moving items</remarks>
 /// <param name="tp">The tile position to test</param>
 /// <returns>True if there is already a static item occupying the specified position</returns>
 public bool IsStaticItemOnTile(TilePos tp)
 {
     var objectsAtPosition = this.GameObjects.GetItemsOnTile(tp);
     var result = objectsAtPosition.Any(gi => gi.Solidity != ObjectSolidity.Insubstantial);
     return result;
 }
Example #18
0
 public int GetWorldAreaIdForTilePos(TilePos tp)
 {
     var result = this._wl.GetWorldAreaIdForTilePos(tp);
     return result;
 }
Example #19
0
        /// <summary>
        /// Tests whether the specified position can be occupied.
        /// </summary>
        /// <remarks>This is only to be used to determine whether moving objects can (temporarily) occupy the tile</remarks>
        /// <param name="tp">The tile position to test</param>
        /// <param name="treatMoveableItemsAsImpassable">If true then an item such as the boulder will be treated as impassable</param>
        /// <returns>True if the specified tile can be occupied</returns>
        public bool CanTileBeOccupied(TilePos tp, bool treatMoveableItemsAsImpassable)
        {
            if (!IsTileWithinWorld(tp))
                return false;

            var objectsAtPosition = this.GameObjects.GetItemsOnTile(tp);
            var isTileAlreadyOccupied = treatMoveableItemsAsImpassable
                ? objectsAtPosition.Any(gi => gi.Solidity == ObjectSolidity.Impassable || gi.Solidity == ObjectSolidity.Moveable)
                : objectsAtPosition.Any(gi => gi.Solidity == ObjectSolidity.Impassable);
            var result = !isTileAlreadyOccupied;
            return result;
        }
Example #20
0
            public override bool Update(GameTime gameTime)
            {
                this.Mine._countdown += gameTime.ElapsedGameTime;
                if (this._spreadPosition == 0)
                    {
                    this.Mine.World.AddExplosion(this.Mine.TilePosition.ToPosition(), this._energyEffects[0]);
                    this._spreadPosition++;
                    return false;
                    }

                if (this.Mine._countdown < TimeInEachSpread)
                    return false;
                this.Mine._countdown -= TimeInEachSpread;
                TilePos tp = this.Mine.TilePosition;
                var positions = new TilePos[4];
                for (int i = 1; i <= this._spreadPosition; i++)
                    {
                    // Top right quadrant
                    positions[0] = new TilePos(tp.X + i, tp.Y + this._spreadPosition - i);

                    // Bottom right quadrant
                    positions[1] = new TilePos(tp.X + this._spreadPosition - i, tp.Y - i);

                    // Bottom left quadrant
                    positions[2] = new TilePos(tp.X - i, tp.Y - this._spreadPosition + i);

                    // Top left quadrant
                    positions[3] = new TilePos(tp.X - this._spreadPosition + i, tp.Y + i);

                    int energy = this._energyEffects[this._spreadPosition];
                    for (int j = 0; j < 4; j++)
                        this.Mine.World.AddExplosion(positions[j].ToPosition(), energy);
                    }
                this._spreadPosition++;
                return false;
            }
Example #21
0
 public int GetWorldAreaIdForTilePos(TilePos tp)
 {
     var areaContainingPoint =
         (from WorldArea wa in this._worldAreas
         where wa.HasId && wa.StartState != null && wa.Area.Contains(tp.X, tp.Y)
         select wa).Single();
     var result = areaContainingPoint.Id;
     return result;
 }