Search | Statistics | User Listing Forums
XNA Resources
XNA Resources ->  General Discussion -> XNA Resource News -> View Thread

You are logged in as a guest. ( logon | register )

My XNA Game Development Book
Jump to page : 1
Now viewing page 1 [25 messages per page]
View previous thread :: View next thread
   General Discussion -> XNA Resource NewsMessage format
 
Kurt Jaegers
Posted 2010-09-27 12:00 AM (#136)
Subject: My XNA Game Development Book


100100252525





Update: Packt Publishing has put up a sample chapter from the book which can be found at https://www.packtpub.com/sites/default/files/0669-chapter-02-flood-control-underwater-puzzling.pdf. Additionally, the book is now available on Amazon as well as other book sites.


 


Over the past several months, I've mentioned a couple of times a "special project" that I have been working on. Late last week, that was all wrapped up, and I'm happy to announce that my first book has officially been published by Packt Publishing.


XNA 4.0 Game Development by Example : Beginner's Guide is now available, and you can find more details about the book here.



Those who have worked through the Star Defense tutorial series will find the approach of the book familiar. I look at building four different 2D games throughout the course of the book, covering topics such as sprite animation, sound effects, drawing text, path finding with A*, platform physics, particle-based explosions, integrating XNA with Windows Forms, and more.



The four games covered in the book are (Click on the images for full sized screenshots):




































Flood Control

Flood Control - A puzzle style game, where users race against the ever-increasing water level to build continuous trails of pipes from the left side of the board to the right. In addition to basic sprite animation (rotation, movement, and alpha-based fading), Flood Control looks at recursive logic and game structure, building increasingly difficult levels into the game, and the basics of drawing text.

Asteroid Belt Assault

Asteroid Belt Assault - A space shooter which places the player into a chaotic asteroid field, fighting waves of enemy ships which fly through the game area along a set of way points. Asteroid Belt Assault introduces frame-based sprite animation, elastic collisions, sound effects, and particle-based explosions.

Robot Rampage

Robot Rampage - Play as a tank with either the XBox controller or the keyboard as you fight enemy tanks intent on your destruction. Two different weapon upgrades are available to the player as you try to survive while disabling the computer terminals that spawn the enemy robots. Levels are generated automatically, and both level object placement and enemy AI utilizes the A* path finding algorithm.


Gemstone Hunter - A classic style platform game, utilizing a multi-layered tile engine in which the player gathers gem stones while attempting to either avoid or crush zombies. In addition to building the game, the Gemstone Hunter project also introduces creating a Game Library project to isolate the tile engine from the game code, and using that library to build a Windows Forms based map editor in which to create levels for the game.


 

Top of the page Bottom of the page
Guest
Posted 2010-11-11 3:47 PM (#169 - in reply to #136)
Subject: RE: My XNA Game Development Book


I purchased your book and I would greatly appreciate it if you would post an "extra credit" tutorial on how to handle ramps (diagonal tiles or any uneven tile type) in the Platform Game.
Top of the page Bottom of the page
Kurt Jaegers
Posted 2010-11-12 11:41 AM (#170 - in reply to #169)
Subject: RE: My XNA Game Development Book


100100252525

Expanding on the Platform Game is something I would definitely like to do, depending upon available time. I currently have the Tile Engine series in the works (complete revamp of the old series) and have been digging into Windows Phone 7 development, so it will take me a while to get going on updates to the platformer.
Top of the page Bottom of the page
ZebulonPi
Posted 2010-12-01 12:07 PM (#177 - in reply to #136)
Subject: Re: My XNA Game Development Book


New user

Posts: 3

Barnes & Noble is mailing me my copy as we speak. Can't tell you how glad I am to be able to put money in your pocket, to pay you back for all this site as taught me!
Top of the page Bottom of the page
Digital Savior
Posted 2010-12-03 10:34 PM (#180 - in reply to #136)
Subject: RE: My XNA Game Development Book


New user

Posts: 1

Purchased from Amazon, reading it and loving it so far! Thanks for the book!
Top of the page Bottom of the page
Kurt Jaegers
Posted 2010-12-04 6:02 AM (#181 - in reply to #180)
Subject: RE: My XNA Game Development Book


100100252525
Thanks both of you Hope you enjoy!
Top of the page Bottom of the page
fryedrycestyle
Posted 2010-12-07 9:14 PM (#183 - in reply to #136)
Subject: RE: My XNA Game Development Book


New user

Posts: 2

Hi, I'm really enjoying the book so far. Hope this is an okay to post this but I've hit a snag unfortunately on the second part of Flood Control. The game runs fine but falling pieces are displayed as blank tiles instead of pipes! Here's the code I have so far for each class, I'm not sure where I went wrong since there are no errors being displayed:

 Game1.cs

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 Flood_Control
{
    ///
    /// This is the main type for your game
    ///
    public class Game1 : Microsoft.Xna.Framework.Game
    {
        GraphicsDeviceManager graphics;
        SpriteBatch spriteBatch;

        // Variables

        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;



        public Game1()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";
        }

        ///
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        ///
        protected override void Initialize()
        {
            this.IsMouseVisible = true;
            graphics.PreferredBackBufferWidth = 800;
            graphics.PreferredBackBufferHeight = 600;
            graphics.ApplyChanges();
            gameBoard = new GameBoard();



            base.Initialize();
        }

        ///
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        ///
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            playingPieces = Content.Load(@"Textures\Tile_Sheet");
            backgroundScreen = Content.Load(@"Textures\Background");
            titleScreen = Content.Load(@"Textures\TitleScreen");


        }

        ///
        /// UnloadContent will be called once per game and is the place to unload
        /// all content.
        ///
        protected override void UnloadContent()
        {
            // TODO: Unload any non ContentManager content here
        }

        private int DetermineScore(int SquareCount)
        {
            return (int)((Math.Pow((SquareCount / 5), 2) + SquareCount) * 10);
        }

        private void CheckScoringChain(List 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.AddFadingPiece(
                                (int)ScoringSquare.X,
                                (int)ScoringSquare.Y,
                                gameBoard.GetSquare(
                                (int)ScoringSquare.X,
                                (int)ScoringSquare.Y));

                            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.AddRotatingPiece(x, y,
                        gameBoard.GetSquare(x, y), false);

                    gameBoard.RotatePiece(x, y, false);
                    timeSinceLastInput = 0.0f;
                }

                if (mouseState.RightButton == ButtonState.Pressed)
                {
                    gameBoard.AddRotatingPiece(x, y,
                        gameBoard.GetSquare(x, y), true);

                    gameBoard.RotatePiece(x, y, true);
                    timeSinceLastInput = 0.0f;
                }
            }
        }

        ///
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        ///
        /// Provides a snapshot of timing values.
        protected override void Update(GameTime gameTime)
        {
            // Allows the game to exit
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed)
                this.Exit();

            switch (gameState)
            {
                case GameStates.TitleScreen:
                    if (Keyboard.GetState().IsKeyDown(Keys.Space))
                    {
                        gameBoard.ClearBoard();
                        gameBoard.GenerateNewPieces(false);
                        playerScore = 0;
                        gameState = GameStates.Playing;
                    }
                    break;

                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);
        }

        private void DrawEmptyPiece(int pixelX, int pixelY)
        {
            spriteBatch.Draw(
                playingPieces,
                new Rectangle(pixelX, pixelY,
                    GamePiece.PieceWidth, GamePiece.PieceHeight),
                    EmptyPiece,
                    Color.White);
        }

        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 is called when the game should draw itself.
        ///
        /// Provides a snapshot of timing values.
        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(Color.CornflowerBlue);

            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();
            }

            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);

                        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);
                        }
                    }


                this.Window.Title = playerScore.ToString();

                spriteBatch.End();


            }
            base.Draw(gameTime);
        }

    }
}


GameBoard.cs

 

 using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace Flood_Control
{
    class GameBoard
    {
        Random rand = new Random();

        public const int GameBoardWidth = 8;
        public const int GameBoardHeight = 10;

        private GamePiece[,] boardSquares =
          new GamePiece[GameBoardWidth, GameBoardHeight];

        private List WaterTracker = new List();

        public Dictionary fallingPieces = new Dictionary();

        public Dictionary rotatingPieces = new Dictionary();

        public Dictionary fadingPieces = new Dictionary();



        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");
        }

        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);
        }

        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)
        {
            int rowLookup = y - 1;

            while (rowLookup >= 0)
            {
                if (GetSquare(x, rowLookup) != "Empty")
                {
                    SetSquare(x, y,
                      GetSquare(x, rowLookup));
                    SetSquare(x, rowLookup, "Empty");

                    AddFallingPiece(x, y, GetSquare(x, y),
                        GamePiece.PieceHeight * (y - rowLookup));

                    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")
                    {
                        AddFallingPiece(x, y, GetSquare(x, y),
                            GamePiece.PieceHeight * GameBoardHeight);

                        RandomPiece(x, y);
                    }
                }
        }

        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");
        }

        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 GetWaterChain(int y)
        {
            WaterTracker.Clear();
            PropagateWater(0, y, "Left");
            return WaterTracker;
        }

        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");
        }

        public bool ArePiecesAnimating()
        {
            if ((fallingPieces.Count == 0) &&
                (rotatingPieces.Count == 0) &&
                (fadingPieces.Count == 0))
            {
                return false;
            }
            else
            {
                return true;
            }
        }

        private void UpdateFadingPieces()
        {
            Queue RemoveKeys = new Queue();

            foreach (string thisKey in fadingPieces.Keys)
            {
                fadingPieces[thisKey].UpdatePiece();

                if (fadingPieces[thisKey].alphaLevel == 0.0f)
                    RemoveKeys.Enqueue(thisKey.ToString());
            }

            while (RemoveKeys.Count > 0)
                fadingPieces.Remove(RemoveKeys.Dequeue());
        }

        private void UpdateFallingPieces()
        {
            Queue RemoveKeys = new Queue();

            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());
        }

        private void UpdateRotatingPieces()
        {
            Queue RemoveKeys = new Queue();

            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());
        }

        public void UpdateAnimatedPieces()
        {
            if (fadingPieces.Count == 0)
            {
                UpdateFallingPieces();
                UpdateRotatingPieces();
            }
            else
            {
                UpdateFadingPieces();
            }
        }



    }
}


 GamePiece.cs

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;

namespace Flood_Control
{
    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; }
        }

        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, "");
        }

        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;
            }
        }

        public string[] GetOtherEnds(string startingEnd)
        {
            List opposites = new List();

            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);
        }

    }
}


 

Falling Piece

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace Flood_Control
{
    class FallingPiece : GamePiece
    {
        public int VerticalOffset;
        public static int fallRate = 5;

        public FallingPiece(string pieceType, int verticalOffset)
            : base(pieceType)
        {
            VerticalOffset = verticalOffset;
        }

        public void UpdatePiece()
        {
            VerticalOffset = (int)MathHelper.Max(0, VerticalOffset - fallRate);
        }


    }
}

 


Fading Piece

 

 using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace Flood_Control
{
    class FadingPiece : GamePiece
    {
        public float alphaLevel = 1.0f;
        public static float alphaChangeRate = 0.02f;

        public FadingPiece(string pieceType, string suffix)
            : base(pieceType, suffix)
        {
        }

        public void UpdatePiece()
        {
            alphaLevel = MathHelper.Max(0, alphaLevel - alphaChangeRate);
        }


    }
}


 

 And... Rotating Piece

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace Flood_Control
{
    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);
        }


    }
}

 

 I've compared my code with the sample code and am not seeing what I did differently to cause this. Obviously I've done something but I'm just not seeing it.

 

Sorry if this is a bad place to post this. 

 



Edited by fryedrycestyle 2010-12-07 9:15 PM
Top of the page Bottom of the page
fryedrycestyle
Posted 2010-12-08 2:52 PM (#184 - in reply to #183)
Subject: Re: My XNA Game Development Book


New user

Posts: 2

Sorry for the double post but I can't seem to edit my post a second time. =S

Just wanted to say I discovered what I did wrong and everything works as it should now!

Top of the page Bottom of the page
M2r4Miller
Posted 2011-01-03 9:57 PM (#201 - in reply to #136)
Subject: RE: My XNA Game Development Book


New user

Posts: 1

Kurt,

I've been working through your book and LOVE it! I just finished chapter 6 and took a short break to work on my own tile engine. I have learned a LOT from working through the first 6 chapters and look forward to the remainder of the book.

Great job and I look forward to reading through this site. If this site is anything like your book, I know it will be excellent.

-Mark
Top of the page Bottom of the page
blackshire
Posted 2011-11-12 6:55 AM (#376 - in reply to #136)
Subject: RE: My XNA Game Development Book


New user

Posts: 1

Kurt, awesome book so far!!!! I am just getting to flood control chapter. Pakt's website is giving me some trouble (very slow) and the code zip file takes 30 minutes to download but then is invalid. I am hoping the site is just having maintenance done on it.

I can't wait to get the content resources and go forward. I am having so much fun!

Thanks for the book, and if there is another place to download the graphics for your book, let me know.

Marketing Info for you:
book purchased from Amazon.com for Kindle via Motorola Xoom.

On my windows PC, i have the kindle app and your book on one screen, and VS2010 on the other screen.
Top of the page Bottom of the page
Dethfuse
Posted 2012-04-23 2:52 PM (#447 - in reply to #136)
Subject: Re: My XNA Game Development Book


New user

Posts: 1

Hi. My name is Eric. I'm very new to programming and your book was just what I needed to get started. However, upon completion of Robot Rampage i encountered an error. The error was "NullReferenceException was unhandled. Object reference not set to an instance of an object. The error occurred in the Enemy class in the AI Methods category at the line: if (path.Count > 1)

Any help would be greatly appreciated. Thank you.

Edited by Dethfuse 2012-04-23 2:54 PM
Top of the page Bottom of the page
powerhdd
Posted 2012-09-24 7:25 PM (#515 - in reply to #136)
Subject: RE: My XNA Game Development Book


New user

Posts: 1

I am new guy

Please Help me to explain these:

public const int MaxPlayablePieceIndex = 5;
public const int EmptyPieceIndex = 6;

and

private string pieceType = "";
private string pieceSuffix = "";

These are codes in the FloodControl Game

Thanks so much
Top of the page Bottom of the page
Jump to page : 1
Now viewing page 1 [25 messages per page]
Jump to forum :
Search this forum
Printer friendly version
E-mail a link to this thread

(Delete all cookies set by this site)
Running MegaBBS ASP Forum Software
© 2002-2017 PD9 Software