GetTile() public method

public GetTile ( Vector2 playerPosition ) : Tile
playerPosition Vector2
return Tile
Example #1
0
        /// <summary>
        /// This is used when sprite is grapped on the platform edge
        /// and want to climbup the platform over he.
        /// </summary>
        /// <returns>
        /// the state ClimbUp or ClimbFail (if there isn't space like a gate closed)
        /// </returns>
        private Enumeration.State isHoldOn()
        {
            Rectangle playerBounds = _position.Bounding;
            Vector2   v2           = m_spriteRoom.getCenterTilePosition(playerBounds);

            int x = (int)v2.X;
            int y = (int)v2.Y;

            if (face == SpriteEffects.FlipHorizontally)
            {
                x = x + 1;
            }
            else
            {
                x = x - 1;
            }

            Tile t = m_spriteRoom.GetTile(new Vector2(x, y));

            if (t.Type == Enumeration.TileType.gate & t.tileState.Value().state == Enumeration.StateTile.closed)
            {
                return(Enumeration.State.climbfail);
            }
            else
            {
                return(Enumeration.State.climbup);
            }
        }
Example #2
0
        public void HandleCollision()
        {
            if (this.Type == Enumeration.TileType.loose)
            {
                if (this.tileState.Value().state != Enumeration.StateTile.loosefall)
                {
                    return;
                }

                Rectangle r          = new Rectangle(Convert.ToInt32(Math.Truncate(Position.X)), Convert.ToInt32(Math.Truncate(Position.Y)), Tile.WIDTH, Tile.HEIGHT);
                Vector4   v          = room.getBoundTiles(r);
                Rectangle tileBounds = room.GetBounds(Convert.ToInt32(Math.Truncate(v.X)), Convert.ToInt32(Math.Truncate(v.W)));

                Vector2 depth = RectangleExtensions.GetIntersectionDepth(tileBounds, r);
                Enumeration.TileType      tileType      = room.GetType(Convert.ToInt32(Math.Truncate(v.X)), Convert.ToInt32(Math.Truncate(v.W)));
                Enumeration.TileCollision tileCollision = room.GetCollision(Convert.ToInt32(Math.Truncate(v.X)), Convert.ToInt32(Math.Truncate(v.W)));
                //Tile tile = room.GetTile(new Vector2((int)v.X, (int)v.W));
                if (tileCollision == Enumeration.TileCollision.Platform)
                {
                    //if (tileType == Enumeration.TileType.floor)
                    if (depth.Y >= Tile.HEIGHT - Tile.PERSPECTIVE)
                    {
                        lock (room.tilesTemporaney)
                        {
                            room.tilesTemporaney.Remove(this);
                        }
                        //Vector2 vs = new Vector2(this.Position.X, this.Position.Y);
                        if (tileType == Enumeration.TileType.loose)
                        {
                            Loose l = (Loose)room.GetTile(Convert.ToInt32(Math.Truncate(v.X)), Convert.ToInt32(Math.Truncate(v.W)));
                            l.Fall(true);
                        }
                        else
                        {
                            ((SoundEffect)Maze.dContentRes[PrinceOfPersiaGame.CONFIG_SOUNDS + "tile crashing into the floor".ToUpper()]).Play();
                            room.SubsTile(Coordinates, Enumeration.TileType.rubble);
                        }
                    }
                }


                //if (_position.Y >= RoomNew.BOTTOM_LIMIT - Tile.HEIGHT - Tile.PERSPECTIVE)
                if (_position.Y >= RoomNew.BOTTOM_LIMIT - Tile.PERSPECTIVE)
                {
                    //remove tiles from tilesTemporaney
                    lock (room.tilesTemporaney)
                    {
                        room.tilesTemporaney.Remove(this);
                    }
                    //exit from DOWN room
                    RoomNew roomDown = room.maze.DownRoom(room);
                    room        = roomDown;
                    _position.Y = RoomNew.TOP_LIMIT - 10;

                    lock (room.tilesTemporaney)
                    {
                        room.tilesTemporaney.Add(this);
                    }
                }
            }
        }