コード例 #1
0
        public bool TileCollision(Sprite objet1, int tileSize, int mapWidth, int mapHeight, CollisionLayer collisionLayer, int direction)
        {
            int nextX, nextY, currentX, currentY;

            if (sensPositif)
            {
                nextX = (int)Math.Ceiling((this.Center.X + (int)Inc_X) / tileSize) - 1;
                nextY = (int)Math.Ceiling((this.Center.Y + (int)Inc_Y) / tileSize) - 1;
            }
            else
            {
                nextX = (int)Math.Ceiling((this.Center.X - (int)Inc_X) / tileSize) - 1;
                nextY = (int)Math.Ceiling((this.Center.Y - (int)Inc_Y) / tileSize) - 1;
            }
            currentX = (int)Math.Ceiling((this.Center.X) / tileSize) - 1;
            currentY = (int)Math.Ceiling((this.Center.Y) / tileSize) - 1;

            if (nextX > (mapWidth - 1) || nextY > (mapHeight - 1) || nextY <= 1 || nextX <= 1)
            {
                return(false);
            }

            else
            {
                return(!collisionLayer.GetTile(nextX, nextY) || !collisionLayer.GetTile(currentX, currentY));
            }
        }
コード例 #2
0
ファイル: Character.cs プロジェクト: TODO-Project/TODO-game
        public bool TileCollision(Sprite objet1, int tileSize, int mapWidth, int mapHeight, CollisionLayer collisionLayer, int direction)
        {
            int tileX = (int)Math.Ceiling(((this.Center.X) / tileSize)) - 1;
            int tileY = (int)Math.Ceiling(((this.Center.Y) / tileSize)) - 1;

            switch (direction)
            {
            case 0:         // Gauche
                if (tileX > 0)
                {
                    tileX--;
                }
                break;

            case 1:         // Droite
                if (tileX < mapWidth)
                {
                    tileX++;
                }
                break;

            case 2:         // Haut
                if (tileY > 0)
                {
                    tileY--;
                }
                break;

            case 3:         // Bas
                if (tileY < mapHeight)
                {
                    tileY++;
                }
                break;

            default:
                break;
            }
            return(collisionLayer.GetTile(tileX, tileY));
        }