Exemplo n.º 1
0
        //COllision nur mit Untergrund
        // Achtung: hier ist eine Konstante als Puffer für die Gravitation eingebaut
        // dies muss bei eventuellen Änderungen angepasst werden
        public bool IsWalkablegrav(GameObject gObj)
        {
            int bottomLeftX = (int)((gObj.Position.X - (gObj.sprite.TextureRect.Width / 2) + 11 + gObj.MovingDirection.X) / TileSize);
            int bottomLeftY = (int)((gObj.Position.Y + (gObj.sprite.TextureRect.Height / 2) + gObj.MovingDirection.Y + 0.5) / TileSize );

            int bottomRightX = (int)((gObj.Position.X + (gObj.sprite.TextureRect.Width / 2) - 11 + gObj.MovingDirection.X) / TileSize);
            int bottomRightY = (int)((gObj.Position.Y + (gObj.sprite.TextureRect.Height / 2) + gObj.MovingDirection.Y + 0.5) / TileSize );

            int bottomCenterX = (int)((gObj.Position.X + gObj.MovingDirection.X) / TileSize);
            int bottomCenterY = (int)((gObj.Position.Y + (gObj.sprite.TextureRect.Height / 2) + gObj.MovingDirection.Y + 0.5) / TileSize);

            try
            {
                return tiles[bottomLeftX, bottomLeftY].Walkablegrav && tiles[bottomRightX, bottomRightY].Walkablegrav
                    && tiles[bottomCenterX, bottomCenterY].Walkable;
            }
            catch(IndexOutOfRangeException)
            {
                return false;
            }
        }
Exemplo n.º 2
0
        //COllision mit Wand[Rechts,Links]
        public bool IsWalkable(GameObject gObj)
        {
            int topLeftX = (int)((gObj.Position.X - (gObj.sprite.TextureRect.Width / 2) + gObj.MovingDirection.X) / TileSize);
            int topLeftY = (int)((gObj.Position.Y - (gObj.sprite.TextureRect.Height / 2) + gObj.MovingDirection.Y) / TileSize);

            int topRightX = (int)((gObj.Position.X + (gObj.sprite.TextureRect.Width / 2) + gObj.MovingDirection.X) / TileSize);
            int topRightY = (int)((gObj.Position.Y - (gObj.sprite.TextureRect.Height / 2) + gObj.MovingDirection.Y) / TileSize );

            // Achtung: zur Berechnung der Position auf der y-Achse wird hier ein konstante von der y-Höhe abgezogen
            int bottomLeftX = (int)((gObj.Position.X - (gObj.sprite.TextureRect.Width / 2) + gObj.MovingDirection.X) / TileSize);
            int bottomLeftY = (int)((gObj.Position.Y + (gObj.sprite.TextureRect.Height / 2) - 11 + gObj.MovingDirection.Y) / TileSize);

            int bottomRightX = (int)((gObj.Position.X + (gObj.sprite.TextureRect.Width / 2) + gObj.MovingDirection.X) / TileSize);
            int bottomRightY = (int)((gObj.Position.Y + (gObj.sprite.TextureRect.Height / 2) - 11 + gObj.MovingDirection.Y) / TileSize);

            try
            {
                return tiles[topLeftX, topLeftY].Walkable && tiles[topRightX, topRightY].Walkable
                    && tiles[bottomLeftX, bottomLeftY].Walkable && tiles[bottomRightX, bottomRightY].Walkable;
            }
            catch (IndexOutOfRangeException)
            {
                return false;
            }
        }