Example #1
0
 public void DrawPieces(SpriteBatch spriteBatch, Camera cam, List <CheckerPiece> allPieces, int tileScale)
 {
     spriteBatch.Begin(SpriteSortMode.BackToFront,
                       BlendState.AlphaBlend,
                       null,
                       null,
                       null,
                       null,
                       cam.get_transformation(_device));
     for (int i = 0; i < allPieces.Count(); i++)
     {
         CheckerPiece currentPiece = allPieces[i];
         if (currentPiece != null)
         {
             spriteBatch.Draw(_checkerTileTexture, new Vector2((currentPiece.Col * tileScale + tileScale * .5f), currentPiece.Row * tileScale + tileScale * .5f), new Rectangle(currentPiece.Color * tileScale, (int)currentPiece.Status * tileScale, tileScale, tileScale), Color.White, 0, new Vector2(tileScale / 2.0f, tileScale / 2.0f), 1, SpriteEffects.None, 0);
         }
     }
     spriteBatch.End();
 }
Example #2
0
 public void DrawPieces(SpriteBatch spriteBatch, Camera cam, List<CheckerPiece> allPieces, int tileScale)
 {
     spriteBatch.Begin(SpriteSortMode.BackToFront,
                   BlendState.AlphaBlend,
                   null,
                   null,
                   null,
                   null,
                   cam.get_transformation(_device));
     for (int i = 0; i < allPieces.Count(); i++)
     {
         CheckerPiece currentPiece = allPieces[i];
         if (currentPiece != null)
         {
             spriteBatch.Draw(_checkerTileTexture, new Vector2((currentPiece.Col * tileScale + tileScale * .5f), currentPiece.Row * tileScale + tileScale * .5f), new Rectangle(currentPiece.Color * tileScale, (int)currentPiece.Status * tileScale, tileScale, tileScale), Color.White, 0, new Vector2(tileScale / 2.0f, tileScale / 2.0f), 1, SpriteEffects.None, 0);
         }
     }
     spriteBatch.End();
 }
Example #3
0
        public void DrawCheckerBoard(CheckerTile[,] tileBoard, List <CheckerPiece> allPieces, CheckerPiece selectedPiece, List <CheckerPiece>[] movablePieces, Dictionary <CheckerPiece, List <MoveSet> > MoveDict, int TILE_SCALE, SpriteBatch spriteBatch, Camera cam)
        {
            if (!_contentLoaded)
            {
                return;
            }
            spriteBatch.Begin(SpriteSortMode.BackToFront,
                              BlendState.AlphaBlend,
                              null,
                              null,
                              null,
                              null,
                              cam.get_transformation(_device));
            //Checker Tiles
            for (var row = 0; row < tileBoard.GetLength(0); row++)
            {
                for (int col = 0; col < tileBoard.GetLength(1); col++)
                {
                    spriteBatch.Draw(_blankTexture, new Rectangle(col * TILE_SCALE, row * TILE_SCALE, TILE_SCALE, TILE_SCALE), null, (tileBoard[row, col].Color == 1)?Color.Gray:Color.White, 0, Vector2.Zero, SpriteEffects.None, 1);
                }
            }
            //Lines
            for (var row = 0; row <= tileBoard.GetLength(0); row++)
            {
                spriteBatch.Draw(_blankTexture, new Rectangle(0, row * TILE_SCALE, tileBoard.GetLength(1) * TILE_SCALE, 1), null, Color.Black, 0, Vector2.Zero, SpriteEffects.None, 0);
            }
            for (var col = 0; col <= tileBoard.GetLength(1); col++)
            {
                spriteBatch.Draw(_blankTexture, new Rectangle(col * TILE_SCALE, 0, 1, tileBoard.GetLength(0) * TILE_SCALE), null, Color.Black, 0, Vector2.Zero, SpriteEffects.None, 0);
            }
            spriteBatch.End();

            //Draw Pieces
            DrawPieces(spriteBatch, cam, allPieces, TILE_SCALE);

            //Draw the possible moves
            if (selectedPiece != null && movablePieces != null && movablePieces[selectedPiece.Color].Contains(selectedPiece) && MoveDict.ContainsKey(selectedPiece))
            {
                DrawPossibleMoves(spriteBatch, cam, MoveDict[selectedPiece], TILE_SCALE, selectedPiece);
            }
        }
Example #4
0
        public void DrawCheckerBoard(CheckerTile[,] tileBoard, List<CheckerPiece> allPieces, CheckerPiece selectedPiece, List<CheckerPiece>[] movablePieces, Dictionary<CheckerPiece, List<MoveSet>> MoveDict, int TILE_SCALE, SpriteBatch spriteBatch, Camera cam)
        {
            if (!_contentLoaded)
                return;
            spriteBatch.Begin(SpriteSortMode.BackToFront,
                          BlendState.AlphaBlend,
                          null,
                          null,
                          null,
                          null,
                          cam.get_transformation(_device));
            //Checker Tiles
            for (var row = 0; row < tileBoard.GetLength(0); row++)
            {
                for (int col = 0; col < tileBoard.GetLength(1); col++)
                {
                    spriteBatch.Draw(_blankTexture, new Rectangle(col * TILE_SCALE, row * TILE_SCALE, TILE_SCALE, TILE_SCALE), null, (tileBoard[row, col].Color == 1)?Color.Gray:Color.White, 0, Vector2.Zero, SpriteEffects.None, 1);
                }
            }
            //Lines
            for (var row = 0; row <= tileBoard.GetLength(0); row++)
            {
                spriteBatch.Draw(_blankTexture, new Rectangle(0, row * TILE_SCALE, tileBoard.GetLength(1) * TILE_SCALE, 1), null, Color.Black, 0, Vector2.Zero, SpriteEffects.None, 0);
            }
            for (var col = 0; col <= tileBoard.GetLength(1); col++)
            {
                spriteBatch.Draw(_blankTexture, new Rectangle(col * TILE_SCALE, 0, 1, tileBoard.GetLength(0) * TILE_SCALE), null, Color.Black, 0, Vector2.Zero, SpriteEffects.None, 0);
            }
            spriteBatch.End();

            //Draw Pieces
            DrawPieces(spriteBatch, cam, allPieces, TILE_SCALE);

            //Draw the possible moves
            if (selectedPiece != null && movablePieces != null && movablePieces[selectedPiece.Color].Contains(selectedPiece) && MoveDict.ContainsKey(selectedPiece))
            {
                DrawPossibleMoves(spriteBatch, cam, MoveDict[selectedPiece], TILE_SCALE, selectedPiece);
            }
        }
Example #5
0
 public void DrawPossibleMoves(SpriteBatch spriteBatch, Camera cam, List <MoveSet> allTile, int TILE_SCALE, CheckerPiece SelectedPiece)
 {
     spriteBatch.Begin(SpriteSortMode.BackToFront,
                       BlendState.AlphaBlend,
                       null,
                       null,
                       null,
                       null,
                       cam.get_transformation(_device));
     for (int i = 0; i < allTile.Count(); i++)
     {
         for (int j = 0; j < allTile[i].MoveList.Count(); j++)
         {
             Color color = (j == 0) ? new Color(255, 255, 255, 127) : new Color(255, 255, 255, 50);
             spriteBatch.Draw(_checkerTileTexture,
                              new Vector2((allTile[i].MoveList[j].Col * TILE_SCALE + TILE_SCALE * .5f),
                                          allTile[i].MoveList[j].Row * TILE_SCALE + TILE_SCALE * .5f),
                              new Rectangle(SelectedPiece.Color * TILE_SCALE, 0, TILE_SCALE, TILE_SCALE),
                              color, 0, new Vector2(TILE_SCALE * .5f, TILE_SCALE * .5f), 1,
                              SpriteEffects.None, 0);
         }
     }
     spriteBatch.End();
 }
Example #6
0
        public void HandleInput(GameTime gameTime)
        {
            lastKeyboardState = currentKeyboardState;
            lastGamePadState  = currentGamePadState;

            currentKeyboardState = Keyboard.GetState();
            currentGamePadState  = GamePad.GetState(PlayerIndex.One);

            // Check for exit.
            if (currentKeyboardState.IsKeyDown(Keys.Escape) ||
                currentGamePadState.Buttons.Back == ButtonState.Pressed)
            {
                Exit();
            }

            if (CurrentGameStatus == GameStatus.Setup)
            {
            }
            else if (CurrentGameStatus == GameStatus.InProgress)
            {
                if (Mouse.GetState().LeftButton == Microsoft.Xna.Framework.Input.ButtonState.Pressed)
                {
                    if ((CurrentVsType == VsType.PlayerVsCpu && _currentTurn == PlayerColor) || CurrentVsType == VsType.PlayerVsPlayer)
                    {
                        Vector2     worldPosition = Vector2.Transform(new Vector2(Mouse.GetState().X, Mouse.GetState().Y), Matrix.Invert(_cam.get_transformation(GraphicsDevice)));
                        CheckerTile tile          = _checkerBoard.Board.GetCheckerTile(worldPosition);

                        //Handle mouse input for the game if it is player vs player or (player vs cpu if it is the player's turn)
                        if (CurrentVsType == VsType.PlayerVsPlayer || CurrentVsType == VsType.PlayerVsCpu && _currentTurn == PlayerColor)
                        {
                            //Check that the user clicked on a tile
                            if (tile != null)
                            {
                                //User clicked on his own piece
                                var checkerPiece = _checkerBoard.GetCheckerPiece(tile);
                                if ((checkerPiece) != null && checkerPiece.Color == _currentTurn)
                                {
                                    _checkerBoard.SelectedPiece = checkerPiece;
                                    if (_selectedParticle != null)
                                    {
                                        _selectedParticle.status = ParticleStatus.Dead;
                                        _selectedParticle        = null;
                                    }
                                    _selectedParticle = _particleManager.Spawn(_particleManager.particleSystemInfoDict["fireSmall"], _checkerBoard.GetCenterOfTile(checkerPiece.Row, checkerPiece.Col));
                                }

                                //If a user has selected a piece and the piece is a movable piece
                                if (_checkerBoard.SelectedPiece != null && _checkerBoard.MovablePieces[_currentTurn].Contains(_checkerBoard.SelectedPiece) &&
                                    _checkerBoard.MoveDict.ContainsKey(_checkerBoard.SelectedPiece) && _checkerBoard.MoveDict[_checkerBoard.SelectedPiece].Any(moveSet => moveSet.MoveList.First().Row == tile.Row && moveSet.MoveList.First().Col == tile.Col))
                                {
                                    //Handle the move to that location
                                    _checkerBoard.HandleMove(tile.Row, tile.Col);
                                    if (_selectedParticle != null)
                                    {
                                        _selectedParticle.status = ParticleStatus.Dead;
                                        _selectedParticle        = null;
                                    }
                                    //Move to the next turn
                                    _currentTurn = _checkerBoard.NextTurn(_currentTurn);
                                }
                            }
                        }
                    }
                }
            }
        }
Example #7
0
 public void DrawPossibleMoves(SpriteBatch spriteBatch, Camera cam, List<MoveSet> allTile, int TILE_SCALE, CheckerPiece SelectedPiece)
 {
     spriteBatch.Begin(SpriteSortMode.BackToFront,
                   BlendState.AlphaBlend,
                   null,
                   null,
                   null,
                   null,
                   cam.get_transformation(_device));
     for (int i = 0; i < allTile.Count(); i++)
     {
         for (int j = 0; j < allTile[i].MoveList.Count(); j++)
         {
             Color color = (j == 0) ? new Color(255, 255, 255, 127) : new Color(255, 255, 255, 50);
             spriteBatch.Draw(_checkerTileTexture,
                              new Vector2((allTile[i].MoveList[j].Col * TILE_SCALE + TILE_SCALE * .5f),
                                          allTile[i].MoveList[j].Row * TILE_SCALE + TILE_SCALE * .5f),
                              new Rectangle(SelectedPiece.Color*TILE_SCALE, 0, TILE_SCALE, TILE_SCALE),
                              color, 0, new Vector2(TILE_SCALE * .5f, TILE_SCALE * .5f), 1,
                              SpriteEffects.None, 0);
         }
     }
     spriteBatch.End();
 }
 public void Draw(SpriteBatch spriteBatch, Camera cam)
 {
     spriteBatch.Begin(SpriteSortMode.Immediate, particleInfo.BlendState, null, null, null, null, cam.get_transformation(device));
     for (var i = 0; i < particles.Count; i++)
     {
         spriteBatch.Draw(contentManager.Load <Texture2D>("Textures/" + particleInfo.TextureName), new Vector2((int)particles[i].Position.X, (int)particles[i].Position.Y), null, particles[i].Color, particles[i].Rotation, new Vector2(5f, 5f), particles[i].Scale, SpriteEffects.None, 0);
     }
     spriteBatch.End();
 }
        public void Draw(SpriteBatch spriteBatch, Camera cam)
        {
            spriteBatch.Begin(SpriteSortMode.Immediate, particleInfo.BlendState, null, null, null, null, cam.get_transformation(device));
            for (var i = 0; i < particles.Count; i++)
            {
                spriteBatch.Draw(contentManager.Load<Texture2D>("Textures/" + particleInfo.TextureName), new Vector2((int)particles[i].Position.X, (int)particles[i].Position.Y), null, particles[i].Color, particles[i].Rotation, new Vector2(5f, 5f), particles[i].Scale, SpriteEffects.None, 0 );

            }
            spriteBatch.End();
        }