- Home
- Products
- Integration
- Tutorial
- Barcode FAQ
- Purchase
- Company
c# print barcode The MeteorsManager GameComponent in Font
Listing 4-4. The MeteorsManager GameComponent DataMatrix Maker In None Using Barcode creation for Font Control to generate, create Data Matrix image in Font applications. www.OnBarcode.comData Matrix ECC200 Drawer In None Using Barcode creation for Font Control to generate, create ECC200 image in Font applications. www.OnBarcode.com#region Using Statements using using using using using System; System.Collections.Generic; Microsoft.Xna.Framework; Microsoft.Xna.Framework.Graphics; RockRainEnhanced.Core; Barcode Creator In None Using Barcode printer for Font Control to generate, create Barcode image in Font applications. www.OnBarcode.comQR Code ISO/IEC18004 Generation In None Using Barcode creation for Font Control to generate, create QR Code image in Font applications. www.OnBarcode.com#endregion namespace RockRainEnhanced { /// <summary> /// This GameComponent implements a manager for all Meteors in the game. /// </summary> public class MeteorsManager : DrawableGameComponent { // List of active meteors protected List<Meteor> meteors; // Constant for initial meteor count private const int STARTMETEORCOUNT = 10; // Time for a new meteor private const int ADDMETEORTIME = 5000; USS Code 39 Drawer In None Using Barcode printer for Font Control to generate, create ANSI/AIM Code 39 image in Font applications. www.OnBarcode.comGTIN - 13 Drawer In None Using Barcode generation for Font Control to generate, create EAN13 image in Font applications. www.OnBarcode.comCHAPTER 4 s IMPROVING YOUR FIRST 2-D GAME
UCC-128 Creator In None Using Barcode generation for Font Control to generate, create GTIN - 128 image in Font applications. www.OnBarcode.comDraw British Royal Mail 4-State Customer Code In None Using Barcode generation for Font Control to generate, create RM4SCC image in Font applications. www.OnBarcode.comprotected Texture2D meteorTexture; protected TimeSpan elapsedTime = TimeSpan.Zero; protected AudioComponent audioComponent; Data Matrix ECC200 Generator In Java Using Barcode generator for Java Control to generate, create Data Matrix image in Java applications. www.OnBarcode.comScan Data Matrix In VB.NET Using Barcode decoder for VS .NET Control to read, scan read, scan image in Visual Studio .NET applications. www.OnBarcode.compublic MeteorsManager(Game game, ref Texture2D theTexture) : base(game) { meteorTexture = theTexture; meteors = new List<Meteor>(); } /// <summary> /// Allows the GameComponent to perform any initialization it needs to /// before starting to run. This is where it can query for any required /// services and load content. /// </summary> public override void Initialize() { audioComponent = (AudioComponent) Game.Services.GetService(typeof (AudioComponent)); meteors.Clear(); Start(); for (int i = 0; i < meteors.Count; i++) { meteors[i].Initialize(); } base.Initialize(); } /// <summary> /// Start the Meteor Rain /// </summary> public void Start() { // Initialize a counter elapsedTime = TimeSpan.Zero; Code 128C Scanner In None Using Barcode recognizer for Software Control to read, scan read, scan image in Software applications. www.OnBarcode.comUSS Code 39 Creation In Objective-C Using Barcode drawer for iPhone Control to generate, create Code 39 image in iPhone applications. www.OnBarcode.comCHAPTER 4 s IMPROVING YOUR FIRST 2-D GAME
Print European Article Number 13 In C#.NET Using Barcode maker for Visual Studio .NET Control to generate, create UPC - 13 image in .NET applications. www.OnBarcode.comEncoding UPC-A Supplement 2 In .NET Framework Using Barcode printer for ASP.NET Control to generate, create UPC-A image in ASP.NET applications. www.OnBarcode.com// Add the meteors for (int i = 0; i < STARTMETEORCOUNT; i++) { AddNewMeteor(); } } /// <summary> /// All Meteors in the game /// </summary> public List<Meteor> AllMeteors { get { return meteors; } } /// <summary> /// Check if it is time for a new meteor /// </summary> private void CheckforNewMeteor(GameTime gameTime) { // Add a rock each ADDMETEORTIME elapsedTime += gameTime.ElapsedGameTime; if (elapsedTime > TimeSpan.FromMilliseconds(ADDMETEORTIME)) { elapsedTime -= TimeSpan.FromMilliseconds(ADDMETEORTIME); AddNewMeteor(); // Play a sound for a new meteor audioComponent.PlayCue("newmeteor"); } } /// <summary> /// Add a new meteor in the scene /// </summary> private void AddNewMeteor() { Meteor newMeteor = new Meteor(Game, ref meteorTexture); newMeteor.Initialize(); meteors.Add(newMeteor); Paint ECC200 In Objective-C Using Barcode encoder for iPhone Control to generate, create Data Matrix ECC200 image in iPhone applications. www.OnBarcode.comBarcode Recognizer In Java Using Barcode Control SDK for Java Control to generate, create, read, scan barcode image in Java applications. www.OnBarcode.comCHAPTER 4 s IMPROVING YOUR FIRST 2-D GAME
Code 128 Code Set C Drawer In Objective-C Using Barcode generator for iPhone Control to generate, create Code128 image in iPhone applications. www.OnBarcode.comQR Code Drawer In None Using Barcode encoder for Office Word Control to generate, create Quick Response Code image in Word applications. www.OnBarcode.com// Set the meteor identifier newMeteor.Index = meteors.Count - 1; } /// <summary> /// Allows the GameComponent to update itself. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> public override void Update(GameTime gameTime) { CheckforNewMeteor(gameTime); // Update Meteors for (int i = 0; i < meteors.Count; i++) { meteors[i].Update(gameTime); } base.Update(gameTime); } /// <summary> /// Check if the ship collided with a meteor /// <returns>true, if has a collision</returns> /// </summary> public bool CheckForCollisions(Rectangle rect) { for (int i = 0; i < meteors.Count; i++) { if (meteors[i].CheckCollision(rect)) { // BOOM !! audioComponent.PlayCue("explosion"); // Put the meteor back to your initial position meteors[i].PutinStartPosition(); return true; } } Making Barcode In Visual C#.NET Using Barcode creator for .NET Control to generate, create Barcode image in .NET applications. www.OnBarcode.comRecognizing UCC.EAN - 128 In Visual Basic .NET Using Barcode decoder for Visual Studio .NET Control to read, scan read, scan image in VS .NET applications. www.OnBarcode.comCHAPTER 4 s IMPROVING YOUR FIRST 2-D GAME
return false; } /// <summary> /// Allows the GameComponent to draw your content in the game screen /// </summary> public override void Draw(GameTime gameTime) { // Draw the meteors for (int i = 0; i < meteors.Count; i++) { meteors[i].Draw(gameTime); } base.Draw(gameTime); } } } Observe that this class contains a great deal of the code that was previously inside the Game1 class in the previous chapter, but essentially it does the same thing. You ll use this class later to compose the action scene. s Note Overall, it s a good idea to create a management class for each group of GameComponents in a
game. It s normal to see classes such as EnemyManager, WizardManager, and so on, because this puts all the complexity of this type of game element in only one class. This simplifies the code and maximizes the reuse of these components in other games. Creating the Scoreboard
You still need to create one element of the action scene: the scoreboard. This scoreboard shows the quantity of points and energy of the player s ship. This class is simple: it only draws two lines of text on the screen. Add a class to the project called Score and add the code in Listing 4-5. CHAPTER 4 s IMPROVING YOUR FIRST 2-D GAME
Listing 4-5. The Score GameComponent
#region Using Statements using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; #endregion namespace RockRainEnhanced { /// <summary> /// This is a GameComponent that implements the Game Score. /// </summary> public class Score : DrawableGameComponent { // Spritebatch protected SpriteBatch spriteBatch = null; // Score Position protected Vector2 position = new Vector2(); // Values protected int value; protected int power; protected readonly SpriteFont font; protected readonly Color fontColor; public Score(Game game, SpriteFont font, Color fontColor) : base(game) { this.font = font; this.fontColor = fontColor; // Get the current spritebatch spriteBatch = (SpriteBatch) Game.Services.GetService(typeof (SpriteBatch)); } /// <summary> /// Points value /// </summary>
|
|