GetCollision() public method

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 level and fall off the bottom.
public GetCollision ( int x, int y ) : Enumeration.TileCollision
x int
y int
return Enumeration.TileCollision
Esempio n. 1
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);
                    }
                }
            }
        }
Esempio n. 2
0
        public void isGround()
        {
            if (IsAlive == false)
            {
                return;
            }

            m_isOnGround = false;

            RoomNew   room         = null;
            Rectangle playerBounds = _position.Bounding;
            Vector2   v2           = SpriteRoom.getCenterTile(playerBounds);
            Rectangle tileBounds   = SpriteRoom.GetBounds(Convert.ToInt32(Math.Truncate(v2.X)), Convert.ToInt32(Math.Truncate(v2.Y)));

            //Check if kid outside Room
            if (v2.X < 0)
            {
                room = Maze.LeftRoom(SpriteRoom);
            }
            else
            {
                room = SpriteRoom;
            }

            if (v2.Y > 2)
            {
                m_isOnGround = false;
            }
            else if (v2.Y < 0)
            {
                m_isOnGround = false;
            }
            else
            {
                if (room.GetCollision(Convert.ToInt32(Math.Truncate(v2.X)), Convert.ToInt32(Math.Truncate(v2.Y))) != Enumeration.TileCollision.Passable)
                {
                    if (playerBounds.Bottom >= tileBounds.Bottom)
                    {
                        m_isOnGround = true;
                    }
                }
            }


            if (m_isOnGround == false)
            {
                if (sprite.sequence.raised == false)
                {
                    if (spriteState.Value().state == Enumeration.State.runjump)
                    {
                        spriteState.Add(Enumeration.State.rjumpfall, Enumeration.PriorityState.Force);
                        sprite.PlayAnimation(spriteSequence, spriteState.Value());
                    }
                    else
                    {
                        if (spriteState.Previous().state == Enumeration.State.runjump)
                        {
                            spriteState.Add(Enumeration.State.stepfall, Enumeration.PriorityState.Force, new Vector2(20, 15));
                        }
                        else if (spriteState.Value().state != Enumeration.State.freefall)
                        {
                            spriteState.Add(Enumeration.State.stepfall, Enumeration.PriorityState.Force);
                        }
                    }
                    //SpriteRoom.LooseShake();
                    //and for upper room...
                    SpriteRoom.maze.UpRoom(SpriteRoom).LooseShake();
                }
                return;
            }


            //IS ON GROUND!
            if (spriteState.Value().state == Enumeration.State.freefall)
            {
                //Align to tile x
                _position.Y = tileBounds.Bottom - _position._spriteRealSize.Y;

                //CHECK IF LOOSE ENERGY...
                int Rem = 0;
                Rem = Convert.ToInt32(Math.Truncate(Math.Abs(Position.Y - PositionFall.Y))) / Tile.REALHEIGHT;

                if (Rem == 0)
                {
                    ((SoundEffect)Maze.dContentRes["Sounds/dos/falling echo".ToUpper()]).Play();
                }
                else if (Rem >= 1 & Rem < 3)
                {
                    ((SoundEffect)Maze.dContentRes["Sounds/dos/loosing a life falling".ToUpper()]).Play();
                }
                else
                {
                    ((SoundEffect)Maze.dContentRes["Sounds/dos/falling".ToUpper()]).Play();
                    //you should dead!!!
                    DeadFall();
                }
                Energy = Energy - Rem;
                spriteState.Add(Enumeration.State.crouch, Enumeration.PriorityState.Force, false);
                SpriteRoom.LooseShake();
            }
        }