<< Chapter < Page
  Xna game studio     Page 7 / 13
Chapter >> Page >

There is nothing unusual about the code that was added to the Move method, so it shouldn't require further explanation beyond the embedded comments.

End of discussion of the Sprite class

There were no additional changes made to the Sprite class other than those identified above, so that will end the discussion of the Sprite class.

The Game1 class for XNA0132Proj

General information

This project demonstrates how to write a simple 2D arcade style game.

Ten spiders try to make it from the top to the bottom of a spider web.

The bottom of the web is guarded by two large ladybugs that are intent on eating the spiders.

If a ladybug collides with a spider, the spider gets eaten by the ladybug and removed from the population of spiders. If the player plays long enough, all ofthe spiders should eventually be eaten.

The objective of the game

The objective of the game is for the player to cause as many spiders as possible to be eaten by the ladybugs before they make it to the bottom of thegame window.

Ladybug control

The ladybugs can be moved by the player using either the keyboard or the mouse. Pressing the arrow keys moves one of the ladybugs. Holding down the A keyand pressing the arrow keys moves the other ladybug.

The player can drag one of the ladybugs with the mouse pointer by pressing the left mouse button. The player can drag the other ladybug by pressing theright mouse button.

Spiders are recycled

Even though the game begins with only ten spiders, those that are not eaten before they reach the bottom of the game window are recycled. If a spider makesit from the top to the bottom of the game window without being eaten, the spider wraps around and appears back at the top of the game window ready to start thetrip over.

Keeping score

A counter keeps track of the number of spiders that cross the bottom of the game window. On-screen text displays that number as the game progresses as shownin Figure 1 . Note, however, that if two or more spiders cross the bottom edge of the game window during the same iteration of the game loop, only one will becounted. In hindsight, therefore, the elapsed time required to cause the ladybugs to eat all of the spiders might be a better scorekeeping mechanism thancounting spider crossings.

Modifying the program to keep score on the basis of elapsed time might make a good student project.

Code for the Game1 Class

Listing 6 shows the beginning of the Game1 class along with the constructor in abbreviated form. By abbreviated form, I mean that much ofthe code is very similar to code that I have explained in earlier modules so I deleted that code from Listing 6 for brevity. You can view all of the code for the Game1 class in Listing 14 .

Listing 6 . Abbreviated beginning of the Game1 Class for the XNA0132Proj project.

namespace XNA0132Proj { public class Game1 : Microsoft.Xna.Framework.Game {GraphicsDeviceManager graphics; SpriteBatch spriteBatch;//code deleted for brevity //The following variable is used to count the number// of spiders that make it past the ladybugs and // reach the bottom of the game window.int spiderCount = 0; SpriteFont Font1;//font for on-screen textVector2 FontPos;//position of on-screen text //-------------------------------------------------//public Game1() {//constructor //code deleted for brevity}//end constructor

Questions & Answers

what is biology
Hajah Reply
the study of living organisms and their interactions with one another and their environments
AI-Robot
what is biology
Victoria Reply
HOW CAN MAN ORGAN FUNCTION
Alfred Reply
the diagram of the digestive system
Assiatu Reply
allimentary cannel
Ogenrwot
How does twins formed
William Reply
They formed in two ways first when one sperm and one egg are splited by mitosis or two sperm and two eggs join together
Oluwatobi
what is genetics
Josephine Reply
Genetics is the study of heredity
Misack
how does twins formed?
Misack
What is manual
Hassan Reply
discuss biological phenomenon and provide pieces of evidence to show that it was responsible for the formation of eukaryotic organelles
Joseph Reply
what is biology
Yousuf Reply
the study of living organisms and their interactions with one another and their environment.
Wine
discuss the biological phenomenon and provide pieces of evidence to show that it was responsible for the formation of eukaryotic organelles in an essay form
Joseph Reply
what is the blood cells
Shaker Reply
list any five characteristics of the blood cells
Shaker
lack electricity and its more savely than electronic microscope because its naturally by using of light
Abdullahi Reply
advantage of electronic microscope is easily and clearly while disadvantage is dangerous because its electronic. advantage of light microscope is savely and naturally by sun while disadvantage is not easily,means its not sharp and not clear
Abdullahi
cell theory state that every organisms composed of one or more cell,cell is the basic unit of life
Abdullahi
is like gone fail us
DENG
cells is the basic structure and functions of all living things
Ramadan
What is classification
ISCONT Reply
is organisms that are similar into groups called tara
Yamosa
in what situation (s) would be the use of a scanning electron microscope be ideal and why?
Kenna Reply
A scanning electron microscope (SEM) is ideal for situations requiring high-resolution imaging of surfaces. It is commonly used in materials science, biology, and geology to examine the topography and composition of samples at a nanoscale level. SEM is particularly useful for studying fine details,
Hilary
cell is the building block of life.
Condoleezza Reply
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




Source:  OpenStax, Xna game studio. OpenStax CNX. Feb 28, 2014 Download for free at https://legacy.cnx.org/content/col11634/1.6
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Xna game studio' conversation and receive update notifications?

Ask