Presentation is loading. Please wait.

Presentation is loading. Please wait.

Finishing 2D COSC 315 Fall 2014 Bridget M. Blodgett.

Similar presentations


Presentation on theme: "Finishing 2D COSC 315 Fall 2014 Bridget M. Blodgett."— Presentation transcript:

1 Finishing 2D COSC 315 Fall 2014 Bridget M. Blodgett

2 Text Overlay Right now our game functions but is lacking in a challenge to keep the player playing One of the simplest to implement is a score component Add the following code to Sprite public int scoreValue {get; protected set;} All of the constructors for Sprite and its children should be modified to accept the new int

3 Score Now that there is data to draw from add a variable to Game1 for the current games score – int currentScore = 0; Drawing text is similar to drawing sprites Make a folder to hold your fonts and add a new item to it – Select the Sprite Font from the template and name it Score

4 Fonts By default XNA uses a font called Kootenay If you want to change fonts it is safest to select one from the Redistributable Font Pack Once made the spritefont is simply an XML file – Altering the XML will change that font You will need to load the font just like the sprite images – SpriteFont scoreFont; – scoreFont = Content.Load (@”fonts\score”);

5 Adding the Font Once it is loaded you need to call the font in the Draw method spriteBatch.Begin(); spriteBatch.DrawString(scoreFont, “Score: “ + currentScore, new Vector2(10,10), Color.DarkBlue, 0, Vector2.Zero, 1, SpriteEffects.None, 1); spriteBatch.End();

6 Random Sprite Types Another way to make the game more interesting is to vary the types of enemies available You can weight the different types so that some types spawn more frequently than others In sprite manager: int likelihoodAutomated = 75; int likelihoodChasing = 20; int likelihoodEvading = 5;

7 Applying Weights Replace the code to spawn the skullball with code that picks a random number and based upon the weights picks which item to spawn int random = ((Game1)Game).rnd.Next(100); if(random < likelihoodAutomated) { spriteList.Add(new AutomatedSprite(Game.Content.Load (@”images\skullball”), position, new Point(75,75), 10, new Point (0,0), new Point (6,8), speed, “skullcollision”, 0)); } else if (random < likelihoodAutomated + likelihoodChasing) { spriteList.Add(new ChasingSprite(Game.Content.Load (@”images\skullball”), position, new Point(75,75), 10, new Point (0,0), new Point (6,8), speed, “skullcollision”, 0)); } else { spriteList.Add(new EvadingSprite(Game.Content.Load (@”images\skullball”), position, new Point(75,75), 10, new Point (0,0), new Point (6,8), speed, “skullcollision”, 0)); }

8 Activity Take the code we just wrote and expand it to offer up to 5 types of non-player sprites Three BladesAutomatedSprite50% Four BladesAutomatedSprite50% Skull BallChasingSprite50% PlusChasingSprite50% BoltEvadingSprite100%


Download ppt "Finishing 2D COSC 315 Fall 2014 Bridget M. Blodgett."

Similar presentations


Ads by Google