Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder Nerevarine's Avatar
    Join Date
    Jan 2013
    Location
    Phendrana Drifts, Tallon IV, W-Class
    Posts
    285
    Thanks
    0
    Thanked 17 Times in 17 Posts

    XNA Logic Error, spriteBatch.Begin(); Must be Called

    So for about two days now, I've been getting an extremely annoying, circular error.

    Yes this is for school, but I have been troubleshooting it with the help of my classmates for two days, to no avail. I have two weeks to figure it out, but would like help as soon as possible.

    So, I have to create a game similar to Bioshock 1's hacking minigame. (Feel free to Google it to see what it looks like) It's called flood control. The idea is that you have to align a series of pipes to get water to flow through to the other side. You can rotate the pipes in place to get this to happen.

    Now, I have no error with the main logic of the game, the error I'm having is that I am trying to get the pieces to be animated. So instead of clicking on them and having them appear in a angle, it would actually animate the rotating.

    I run my code through debug, and it gives me no errors on the error list, but tells me that there is an unhandled exception. Here is the error verbatim:
    "Begin must be called successfully before a Draw can be called."

    However, when I call a
    Code:
    spriteBatch.Begin();
    It tells me that a
    Code:
    spriteBatch.End();
    has to be called first. Now, if I call that, it tells me that I need a 'begin' again.

    This is very circular and annoying.

    Here is the code: (Prepare for large amounts, though it is for the most part commented)
    The main file (Game1.cs):
    Code:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using Microsoft.Xna.Framework;
    using Microsoft.Xna.Framework.Audio;
    using Microsoft.Xna.Framework.Content;
    using Microsoft.Xna.Framework.GamerServices;
    using Microsoft.Xna.Framework.Graphics;
    using Microsoft.Xna.Framework.Input;
    using Microsoft.Xna.Framework.Media;
    
    namespace FloodControlGG
    {
        public class Game1 : Microsoft.Xna.Framework.Game
        {
            GraphicsDeviceManager graphics;
            SpriteBatch spriteBatch;
            Texture2D playingPieces;
            Texture2D backgroundScreen;
            Texture2D titleScreen;
            GameBoard gameBoard;
    
            Vector2 gameBoardDisplayOrigin = new Vector2(70, 89);
    
            int playerScore = 0;
    
            enum GameStates { TitleScreen, Playing };
            GameStates gameState = GameStates.TitleScreen;
    
            Rectangle EmptyPiece = new Rectangle(1, 247, 40, 40);
    
            const float MinTimeSinceLastInput = 0.25f;
            float timeSinceLastInput = 0.0f;
    
    
            private int DetermineScore(int SquareCount)
            {
                return (int)((Math.Pow((SquareCount / 5), 2) + SquareCount) * 10);
            }
    
            private void CheckScoringChain(List<Vector2> WaterChain)
            {
                if (WaterChain.Count > 0)
                {
                    Vector2 LastPipe = WaterChain[WaterChain.Count - 1];
    
                    if (LastPipe.X == GameBoard.GameBoardWidth - 1)
                    {
                        if (gameBoard.HasConnector(
                            (int)LastPipe.X, (int)LastPipe.Y, "Right"))
                        {
                            playerScore += DetermineScore(WaterChain.Count);
    
                            foreach (Vector2 ScoringSquare in WaterChain)
                            {
                                gameBoard.SetSquare((int)ScoringSquare.X,
                                    (int)ScoringSquare.Y, "Empty");
                            }
                        }
                    }
                }
            }
    
            private void HandleMouseInput(MouseState mouseState)
            {
                int x = ((mouseState.X -
                    (int)gameBoardDisplayOrigin.X) / GamePiece.PieceWidth);
    
                int y = ((mouseState.Y -
                    (int)gameBoardDisplayOrigin.Y) / GamePiece.PieceHeight);
    
                if ((x >= 0) && (x < GameBoard.GameBoardWidth) &&
                    (y >= 0) && (y < GameBoard.GameBoardHeight))
                {
                    if (mouseState.LeftButton == ButtonState.Pressed)
                    {
                        gameBoard.RotatePiece(x, y, false);
                        timeSinceLastInput = 0.0f;
                    }
    
                    if (mouseState.RightButton == ButtonState.Pressed)
                    {
                        gameBoard.RotatePiece(x, y, false);
                        timeSinceLastInput = 0.0f;
                    }
                }
            }
         
            public Game1()
            {
    
                graphics = new GraphicsDeviceManager(this);
                Content.RootDirectory = "Content";
            }
    
            protected override void Initialize()
            {
                this.IsMouseVisible = true;
                graphics.PreferredBackBufferWidth = 800;
                graphics.PreferredBackBufferHeight = 600;
                graphics.ApplyChanges();
                gameBoard = new GameBoard();
                 
                base.Initialize();
            }
          
            protected override void LoadContent()
            {
                spriteBatch = new SpriteBatch(GraphicsDevice);
    
                playingPieces = Content.Load<Texture2D>(@"Textures\Tile_Sheet");
                backgroundScreen =
                    Content.Load<Texture2D>(@"Textures\Background");
                titleScreen = Content.Load<Texture2D>(@"Textures\TitleScreen");
    
             
            }
    
            protected override void UnloadContent()
            {
             
            }
    
            protected override void Update(GameTime gameTime)
            {
                if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                    this.Exit();
    
                if (gameState == GameStates.Playing)
                {
                    spriteBatch.Begin();
    
                    spriteBatch.Draw(backgroundScreen,
                        new Rectangle(0, 0,
                            this.Window.ClientBounds.Width,
                            this.Window.ClientBounds.Height),
                            Color.White);
    
                    for (int x = 0; x < GameBoard.GameBoardWidth; x++)
                        for (int y = 0; y < GameBoard.GameBoardHeight; y++)
                        {
                            int pixelX = (int)gameBoardDisplayOrigin.X +
                                (x * GamePiece.PieceWidth);
                            int pixelY = (int)gameBoardDisplayOrigin.Y +
                                (y * GamePiece.PieceHeight);
    
                            spriteBatch.Draw(
                                playingPieces,
                                new Rectangle(
                                    pixelX,
                                    pixelY,
                                    GamePiece.PieceWidth,
                                    GamePiece.PieceHeight),
                                    EmptyPiece,
                                    Color.White);
    
                            spriteBatch.Draw(
                                playingPieces, new Rectangle(
                                    pixelX,
                                    pixelY,
                                    GamePiece.PieceWidth,
                                    GamePiece.PieceHeight),
                                    gameBoard.GetSourceRect(x, y),
                                    Color.White);
                        }
    
                    this.Window.Title = playerScore.ToString();
    
                    spriteBatch.End();
                }
    
                switch (gameState)
                {
                    case GameStates.TitleScreen:
                        if (Keyboard.GetState().IsKeyDown(Keys.Space))
                        {
                            gameBoard.ClearBoard();
                            gameBoard.GenerateNewPieces(false);
                            playerScore = 0;
                            gameState = GameStates.Playing;
                        }
                        break;
    
    
                        //The update method for animated pieces for Rough Edges
                    case GameStates.Playing:
                        timeSinceLastInput +=
                            (float)gameTime.ElapsedGameTime.TotalSeconds;
    
                        if (gameBoard.ArePiecesAnimating())
                        {
                            gameBoard.UpdateAnimatedPieces();
                        }
                        else
                        {
                            gameBoard.ResetWater();
    
                            for (int y = 0; y < GameBoard.GameBoardHeight; y++)
                            {
                                CheckScoringChain(gameBoard.GetWaterChain(y));
                            }
    
                            gameBoard.GenerateNewPieces(true);
    
                            if (timeSinceLastInput >= MinTimeSinceLastInput)
                            {
                                HandleMouseInput(Mouse.GetState());
                            }
                        }
    
                        break;
                }
    
                base.Update(gameTime);
            }
    
    
    
    
    
    
    
            protected override void Draw(GameTime gameTime)
            {
                
    
                if (gameState == GameStates.TitleScreen)
                {
                    spriteBatch.Begin();
                    spriteBatch.Draw(titleScreen,
                        new Rectangle(0, 0,
                            this.Window.ClientBounds.Width,
                            this.Window.ClientBounds.Height),
                            Color.White);
                    spriteBatch.End();
                }
    
                for (int x = 0; x < GameBoard.GameBoardWidth; x++)
                    for (int y = 0; y < GameBoard.GameBoardHeight; y++)
                    {
                        int pixelX = (int)gameBoardDisplayOrigin.X +
                            (x * GamePiece.PieceWidth);
                        int pixelY = (int)gameBoardDisplayOrigin.Y +
                            (y * GamePiece.PieceHeight);
    
                       DrawEmptyPiece(pixelX, pixelY);
    
                        bool pieceDrawn = false;
    
                        string positionName = x.ToString() + "_" + y.ToString();
    
                        if (gameBoard.rotatingPieces.ContainsKey(positionName))
                        {
                            DrawRotatingPiece(pixelX, pixelY, positionName);
                            pieceDrawn = true;
                        }
    
                        if (gameBoard.fadingPieces.ContainsKey(positionName))
                        {
                            DrawFadingPiece(pixelX, pixelY, positionName);
                            pieceDrawn = true;
                        }
    
                        if (gameBoard.fallingPieces.ContainsKey(positionName))
                        {
                            DrawFallingPiece(pixelX, pixelY, positionName);
                            pieceDrawn = true;
                        }
    
                        if (!pieceDrawn)
                        {
                            DrawStandardPiece(x, y, pixelX, pixelY);
                        }
                    }
    
                base.Draw(gameTime);
            }
    
           //Below is where the logic error is occuring.
          
            private void DrawEmptyPiece(int pixelX, int pixelY)
            {
                spriteBatch.Begin();
                spriteBatch.Draw(
                    playingPieces,
                    new Rectangle(pixelX, pixelY,
                        GamePiece.PieceWidth, GamePiece.PieceHeight),
                        EmptyPiece,
                        Color.White);
                spriteBatch.End();
             
    
            }
    
            private void DrawStandardPiece(int x, int y,
                int pixelX, int pixelY)
            {
                spriteBatch.Draw(
                    playingPieces, new Rectangle(pixelX, pixelY,
                        GamePiece.PieceWidth, GamePiece.PieceHeight),
                        gameBoard.GetSourceRect(x, y),
                        Color.White);
            }
    
            private void DrawFallingPiece(int pixelX, int pixelY,
                string positionName)
            {
                spriteBatch.Draw(
                    playingPieces,
                    new Rectangle(pixelX, pixelY -
                        gameBoard.fallingPieces[positionName].VerticalOffset,
                        GamePiece.PieceWidth, GamePiece.PieceHeight),
                        gameBoard.fallingPieces[positionName].GetSourceRect(),
                        Color.White);
            }
    
            private void DrawFadingPiece(int pixelX, int pixelY,
                string positionName)
            {
                spriteBatch.Draw(
                    playingPieces,
                    new Rectangle(pixelX, pixelY,
                        GamePiece.PieceWidth, GamePiece.PieceHeight),
                        gameBoard.fadingPieces[positionName].GetSourceRect(),
                        Color.White *
                        gameBoard.fadingPieces[positionName].alphaLevel);
            }
    
            private void DrawRotatingPiece(int pixelX, int pixelY,
                string positionName)
            {
                spriteBatch.Draw(
                    playingPieces,
                    new Rectangle(pixelX + (GamePiece.PieceWidth / 2),
                        pixelY + (GamePiece.PieceHeight / 2),
                        GamePiece.PieceWidth,
                        GamePiece.PieceHeight),
                        gameBoard.rotatingPieces[positionName].GetSourceRect(),
                        Color.White,
                        gameBoard.rotatingPieces[positionName].RotationAmount,
                        new Vector2(GamePiece.PieceWidth / 2,
                            GamePiece.PieceHeight / 2),
                            SpriteEffects.None, 0.0f);
            }
    
        }
    
    }
    This next one (in the reply) one is the GameBoard code. It is called GameBoard.cs. There is also the 'Rotating Pieces' code.

    The comments that say 'Rough Edges' are the secondary part of the program. They will more than likely be part of the influence on my errors.
    (This will be in the first reply, as the thread was too long.

    And finally, the code for the game pieces themselves.
    (This will be in the second reply, as the thread was too long.)

    Thank you in advance for any help you may/may not be able to give me or any attempt to do so.
    Last edited by Nerevarine; 10-11-2013 at 03:43 PM.
    Time kills us in our sleep and we watch it happen in our dreams. -K.K.
    THE END-ALL PROGRAMMING REFERENCE: CLICK HERE (Courtesy of Major Payne)
    My username was previously L0adOpt1c. :: Please read this before posting in the HTML/CSS forum.
    Validate your HTML here and your CSS here. :: Need basic HTML/CSS tutorials? Click here, don't post about it.

  • #2
    Regular Coder Nerevarine's Avatar
    Join Date
    Jan 2013
    Location
    Phendrana Drifts, Tallon IV, W-Class
    Posts
    285
    Thanks
    0
    Thanked 17 Times in 17 Posts
    The GameBoard code:
    Code:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Microsoft.Xna.Framework;
    
    namespace FloodControlGG
    {
        class GameBoard
        {
            Random rand = new Random();
    
            public const int GameBoardWidth = 8;
            public const int GameBoardHeight = 10;
            public Dictionary<string, FallingPiece> fallingPieces =
                new Dictionary<string, FallingPiece>();
            public Dictionary<string, RotatingPiece> rotatingPieces =
                new Dictionary<string, RotatingPiece>();
            public Dictionary<string, FadingPiece> fadingPieces =
                new Dictionary<string, FadingPiece>();
    
            private GamePiece[,] boardSquares =
                new GamePiece[GameBoardWidth, GameBoardHeight];
    
            private List<Vector2> WaterTracker = new List<Vector2>();
    
            public GameBoard()
            {
                ClearBoard();
            }
    
            public void ClearBoard()
            {
                for (int x = 0; x < GameBoardWidth; x++)
                    for (int y = 0; y < GameBoardHeight; y++)
                        boardSquares[x, y] = new GamePiece("Empty");
            }
    
            //Where the interactions for pieces such as rotating begins
    
            public void RotatePiece(int x, int y, bool clockwise)
            {
                boardSquares[x, y].RotatePiece(clockwise);
            }
    
            public Rectangle GetSourceRect(int x, int y)
            {
                return boardSquares[x, y].GetSourceRect();
            }
    
            public string GetSquare(int x, int y)
            {
                return boardSquares[x, y].PieceType;
            }
    
            public void SetSquare(int x, int y, string pieceName)
            {
                boardSquares[x, y].SetPiece(pieceName);
            }
    
            public bool HasConnector(int x, int y, string direction)
            {
                return boardSquares[x, y].HasConnector(direction);
            }
    
            //Where it stops
    
            public void RandomPiece(int x, int y)
            {
                boardSquares[x, y].SetPiece(GamePiece.PieceTypes[rand.Next(0,
                    GamePiece.MaxPlayablePieceIndex+1)]);
            }
    
            public void FillFromAbove(int x, int y)
            {
                //Added by the Rough Edges
                int rowLookup = y - 1;
    
                AddFallingPiece(x, y, GetSquare(x, y),
                    GamePiece.PieceHeight * (y - rowLookup));
    
                //int rowLookup = y - 1; 
                //Improperly Placed?
    
                while (rowLookup >= 0)
                {
                    if (GetSquare(x, rowLookup) != "Empty")
                    {
                        SetSquare(x, y,
                            GetSquare(x, rowLookup));
                        SetSquare(x, rowLookup, "Empty");
                        rowLookup = -1;
                    }
                    rowLookup--;
                }
            }
    
            public void GenerateNewPieces(bool dropSquares)
            {
    
                if (dropSquares)
                {
                    for (int x = 0; x < GameBoard.GameBoardWidth; x++)
                    {
                        for (int y = GameBoard.GameBoardHeight - 1; y >= 0;
                            y--)
                        {
                            if (GetSquare(x, y) == "Empty")
                            {
                                FillFromAbove(x, y);
                            }
                        }
                    }
                }
    
                for (int y = 0; y < GameBoard.GameBoardHeight; y++)
                    for (int x = 0; x < GameBoard.GameBoardWidth; x++)
                    {
                        if (GetSquare(x, y) == "Empty")
                        {
                            RandomPiece(x, y);
                            //More Rough Edges stuff
                            AddFallingPiece(x, y, GetSquare(x, y),
                                GamePiece.PieceHeight * GameBoardHeight);
                        }
                    }
            }
    
            public void ResetWater()
            {
                for (int y = 0; y < GameBoardHeight; y++)
                    for (int x = 0; x < GameBoardWidth; x++)
                        boardSquares[x, y].RemoveSuffix("W");
            }
    
            public void FillPiece(int X, int Y)
            {
                boardSquares[X,Y].AddSuffix("W");
            }
    
            //Making the connections
    
            public void PropagateWater(int x, int y, string fromDirection)
            {
                if ((y >= 0) && (y < GameBoardHeight) &&
                    (x >= 0) && (x < GameBoardWidth))
                {
                    if (boardSquares[x, y].HasConnector(fromDirection) &&
                        !boardSquares[x, y].Suffix.Contains("W"))
                    {
                        FillPiece(x, y);
                        WaterTracker.Add(new Vector2(x, y));
                        foreach (string end in
                            boardSquares[x,y].
                            GetOtherEnds(fromDirection))
                            switch (end)
                            {
                                case "Left": PropagateWater(x - 1, y,
                                    "Right");
                                    break;
                                case "Right": PropagateWater(x + 1, y,
                                    "Left");
                                    break;
                                case "Top": PropagateWater(x, y - 1,
                                    "Bottom");
                                    break;
                                case "Bottom": PropagateWater(x, y + 1,
                                    "Top");
                                    break;
                            }
                    }
                }
            }
    
            public List<Vector2> GetWaterChain(int y)
            {
                WaterTracker.Clear();
                PropagateWater(0, y, "Left");
                return WaterTracker;
            }
    
            //Rough edges methods
    
    
            public void AddFallingPiece(int X, int Y,
                string PieceName, int VerticalOffset)
            {
                fallingPieces[X.ToString() + "_" + Y.ToString()] = new
                FallingPiece(PieceName, VerticalOffset);
            }
    
            public void AddRotatingPiece(int X, int Y,
                string PieceName, bool Clockwise)
            {
                rotatingPieces[X.ToString() + "_" + Y.ToString()] = new
                RotatingPiece(PieceName, Clockwise);
            }
    
            public void AddFadingPiece(int X, int Y, string PieceName)
            {
                fadingPieces[X.ToString() + "_" + Y.ToString()] = new
                    FadingPiece(PieceName, "W");
            }
    
    
            //Now it's the animating pieces
    
            public bool ArePiecesAnimating()
            {
                if ((fallingPieces.Count == 0) &&
                    (rotatingPieces.Count == 0) &&
                    (fadingPieces.Count == 0))
                {
                    return false;
                }
                else
                {
                    return true;
                }
            }
    
            //Fading Piece update
    
            private void UpdateFadingPieces()
            {
                Queue<string> RemoveKeys = new Queue<string>();
    
                foreach (string thisKey in fadingPieces.Keys)
                {
                    fadingPieces[thisKey].UpdatePiece();
    
                    if (fadingPieces[thisKey].alphaLevel == 0)
                        RemoveKeys.Enqueue(thisKey.ToString());
                }
    
                while (RemoveKeys.Count > 0)
                    fadingPieces.Remove(RemoveKeys.Dequeue());
            }
    
            //Falling Piece update
    
            private void UpdateFallingPieces()
            {
                Queue<string> RemoveKeys = new Queue<string>();
    
                foreach (string thisKey in fallingPieces.Keys)
                {
                    fallingPieces[thisKey].UpdatePiece();
    
                    if (fallingPieces[thisKey].VerticalOffset == 0)
                        RemoveKeys.Enqueue(thisKey.ToString());
                }
    
                while (RemoveKeys.Count > 0)
                    fallingPieces.Remove(RemoveKeys.Dequeue());
            }
    
            //Rotating Piece update
    
            private void UpdateRotatingPieces()
              {
                Queue<string> RemoveKeys = new Queue<string>();
    
                foreach (string thisKey in rotatingPieces.Keys)
                {
                    rotatingPieces[thisKey].UpdatePiece();
    
                    if (rotatingPieces[thisKey].rotationTicksRemaining == 0)
                        RemoveKeys.Enqueue(thisKey.ToString());
                }
    
                while (RemoveKeys.Count > 0)
                    rotatingPieces.Remove(RemoveKeys.Dequeue());
            }
    
            //Ending update
    
            public void UpdateAnimatedPieces()
            {
                if (fadingPieces.Count == 0)
                {
                    UpdateFallingPieces();
                    UpdateRotatingPieces();
                }
                else
                {
    
                    UpdateFadingPieces();
                }
            }
                    
    
    
    
        }
    }
    Code for rotating the pieces:
    Code:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Microsoft.Xna.Framework;
    
    namespace FloodControlGG
    {
        class RotatingPiece : GamePiece
        {
            public bool clockwise;
    
            public static float rotationRate = (MathHelper.PiOver2 / 10);
            private float rotationAmount = 0;
            public int rotationTicksRemaining = 10;
    
            public float RotationAmount
            {
                get
                {
                    if (clockwise)
                        return rotationAmount;
                    else return(MathHelper.Pi * 2) - rotationAmount;
                }
            }
    
            public RotatingPiece(string pieceType, bool clockwise)
                : base(pieceType)
            {
                this.clockwise = clockwise;
            }
    
            public void UpdatePiece()
            {
                rotationAmount += rotationRate;
                rotationTicksRemaining = (int)MathHelper.Max(
                    0,
                    rotationTicksRemaining - 1);
            }
    
    
    
    
    
    
    
    
    
        }
    }
    Time kills us in our sleep and we watch it happen in our dreams. -K.K.
    THE END-ALL PROGRAMMING REFERENCE: CLICK HERE (Courtesy of Major Payne)
    My username was previously L0adOpt1c. :: Please read this before posting in the HTML/CSS forum.
    Validate your HTML here and your CSS here. :: Need basic HTML/CSS tutorials? Click here, don't post about it.

  • #3
    Regular Coder Nerevarine's Avatar
    Join Date
    Jan 2013
    Location
    Phendrana Drifts, Tallon IV, W-Class
    Posts
    285
    Thanks
    0
    Thanked 17 Times in 17 Posts
    And now the code for the game pieces.
    Code:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Microsoft.Xna.Framework.Graphics;
    using Microsoft.Xna.Framework;
    
    
    
    namespace FloodControlGG
    {
        class GamePiece
        {
            public static string[] PieceTypes =
            {
                "Left,Right",
                "Top,Bottom",
                "Left,Top",
                "Top,Right",
                "Right,Bottom",
                "Bottom,Left",
                "Empty"
            };
    
            public const int PieceHeight = 40;
            public const int PieceWidth = 40;
    
            public const int MaxPlayablePieceIndex = 5;
            public const int EmptyPieceIndex = 6;
    
            private const int textureOffsetX = 1;
            private const int textureOffsetY = 1;
            private const int texturePaddingX = 1;
            private const int texturePaddingY = 1;
    
            private string pieceType = "";
            private string pieceSuffix = "";
    
            public string PieceType
            {
                get { return pieceType; }
            }
    
            public string Suffix
            {
                get { return pieceSuffix; }
            }
    
            //The end of the "Gets"
    
            //Beggining of string types
    
            public GamePiece(string type, string suffix)
            {
                pieceType = type;
                pieceSuffix = suffix;
            }
    
            public GamePiece(string type)
            {
                pieceType = type;
                pieceSuffix = "";
            }
    
            public void SetPiece(string type, string suffix)
            {
                pieceType = type;
                pieceSuffix = suffix;
            }
    
            public void SetPiece(string type)
            {
                SetPiece(type,"");
            }
    
            public void AddSuffix(string suffix)
            {
                if (!pieceSuffix.Contains(suffix))
                    pieceSuffix += suffix;
            }
    
            public void RemoveSuffix(string suffix)
            {
                pieceSuffix = pieceSuffix.Replace(suffix, "");
            }
    
            //Rotation conditions begin
    
            public void RotatePiece(bool Clockwise)
            {
                switch (pieceType)
                {
                    case "Left,Right":
                        pieceType = "Top,Bottom";
                        break;
                    case "Top,Bottom":
                        pieceType = "Left,Right";
                        break;
                    case "Left,Top":
                        if (Clockwise)
                            pieceType = "Top,Right";
                        else
                            pieceType = "Bottom,Left";
                        break;
                    case "Top,Right":
                        if (Clockwise)
                            pieceType = "Right,Bottom";
                        else
                            pieceType = "Left,Top";
                        break;
                    case "Right,Bottom":
                        if (Clockwise)
                            pieceType = "Bottom,Left";
                        else
                            pieceType = "Top,Right";
                        break;
                    case "Bottom,Left":
                        if (Clockwise)
                            pieceType = "Left,Top";
                        else
                            pieceType = "Right,Bottom";
                        break;
                    case "Empty":
                        break;
                }
            }
    
            //Connection methods
    
            public string[] GetOtherEnds(string startingEnd)
            {
                List<string> opposites = new List<string>();
    
                foreach (string end in pieceType.Split(','))
                {
                    if (end != startingEnd)
                        opposites.Add(end);
                }
                return opposites.ToArray();
            }
    
            public bool HasConnector(string direction)
            {
                return pieceType.Contains(direction);
            }
    
            public Rectangle GetSourceRect()
            {
                int x = textureOffsetX;
                int y = textureOffsetY;
    
                if (pieceSuffix.Contains("W"))
                    x += PieceWidth + texturePaddingX;
    
                y += (Array.IndexOf(PieceTypes, pieceType) *
                    (PieceHeight + texturePaddingY));
    
                return new Rectangle(x, y, PieceWidth, PieceHeight);
            }
    
    
    
    
    
    
    
    
    
    
        }
    }
    Time kills us in our sleep and we watch it happen in our dreams. -K.K.
    THE END-ALL PROGRAMMING REFERENCE: CLICK HERE (Courtesy of Major Payne)
    My username was previously L0adOpt1c. :: Please read this before posting in the HTML/CSS forum.
    Validate your HTML here and your CSS here. :: Need basic HTML/CSS tutorials? Click here, don't post about it.

  • #4
    Regular Coder Nerevarine's Avatar
    Join Date
    Jan 2013
    Location
    Phendrana Drifts, Tallon IV, W-Class
    Posts
    285
    Thanks
    0
    Thanked 17 Times in 17 Posts
    Self bump. I would appreciate some help. Does anyone have any idea?
    Time kills us in our sleep and we watch it happen in our dreams. -K.K.
    THE END-ALL PROGRAMMING REFERENCE: CLICK HERE (Courtesy of Major Payne)
    My username was previously L0adOpt1c. :: Please read this before posting in the HTML/CSS forum.
    Validate your HTML here and your CSS here. :: Need basic HTML/CSS tutorials? Click here, don't post about it.

  • #5
    Regular Coder Nerevarine's Avatar
    Join Date
    Jan 2013
    Location
    Phendrana Drifts, Tallon IV, W-Class
    Posts
    285
    Thanks
    0
    Thanked 17 Times in 17 Posts
    Well, tried to fix it myself, got like 18 more errors and almost gave up.
    Gonna clear my head.
    Time kills us in our sleep and we watch it happen in our dreams. -K.K.
    THE END-ALL PROGRAMMING REFERENCE: CLICK HERE (Courtesy of Major Payne)
    My username was previously L0adOpt1c. :: Please read this before posting in the HTML/CSS forum.
    Validate your HTML here and your CSS here. :: Need basic HTML/CSS tutorials? Click here, don't post about it.


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •