<< 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 the stm
Brian Reply
is there industrial application of fullrenes. What is the method to prepare fullrene on large scale.?
Rafiq
industrial application...? mmm I think on the medical side as drug carrier, but you should go deeper on your research, I may be wrong
Damian
How we are making nano material?
LITNING Reply
what is a peer
LITNING Reply
What is meant by 'nano scale'?
LITNING Reply
What is STMs full form?
LITNING
scanning tunneling microscope
Sahil
how nano science is used for hydrophobicity
Santosh
Do u think that Graphene and Fullrene fiber can be used to make Air Plane body structure the lightest and strongest. Rafiq
Rafiq
what is differents between GO and RGO?
Mahi
what is simplest way to understand the applications of nano robots used to detect the cancer affected cell of human body.? How this robot is carried to required site of body cell.? what will be the carrier material and how can be detected that correct delivery of drug is done Rafiq
Rafiq
what is Nano technology ?
Bob Reply
write examples of Nano molecule?
Bob
The nanotechnology is as new science, to scale nanometric
brayan
nanotechnology is the study, desing, synthesis, manipulation and application of materials and functional systems through control of matter at nanoscale
Damian
Is there any normative that regulates the use of silver nanoparticles?
Damian Reply
what king of growth are you checking .?
Renato
What fields keep nano created devices from performing or assimulating ? Magnetic fields ? Are do they assimilate ?
Stoney Reply
why we need to study biomolecules, molecular biology in nanotechnology?
Adin Reply
?
Kyle
yes I'm doing my masters in nanotechnology, we are being studying all these domains as well..
Adin
why?
Adin
what school?
Kyle
biomolecules are e building blocks of every organics and inorganic materials.
Joe
anyone know any internet site where one can find nanotechnology papers?
Damian Reply
research.net
kanaga
sciencedirect big data base
Ernesto
Introduction about quantum dots in nanotechnology
Praveena Reply
what does nano mean?
Anassong Reply
nano basically means 10^(-9). nanometer is a unit to measure length.
Bharti
do you think it's worthwhile in the long term to study the effects and possibilities of nanotechnology on viral treatment?
Damian Reply
absolutely yes
Daniel
how to know photocatalytic properties of tio2 nanoparticles...what to do now
Akash Reply
it is a goid question and i want to know the answer as well
Maciej
characteristics of micro business
Abigail
for teaching engĺish at school how nano technology help us
Anassong
How can I make nanorobot?
Lily
Do somebody tell me a best nano engineering book for beginners?
s. Reply
there is no specific books for beginners but there is book called principle of nanotechnology
NANO
how can I make nanorobot?
Lily
what is fullerene does it is used to make bukky balls
Devang Reply
are you nano engineer ?
s.
fullerene is a bucky ball aka Carbon 60 molecule. It was name by the architect Fuller. He design the geodesic dome. it resembles a soccer ball.
Tarell
what is the actual application of fullerenes nowadays?
Damian
That is a great question Damian. best way to answer that question is to Google it. there are hundreds of applications for buck minister fullerenes, from medical to aerospace. you can also find plenty of research papers that will give you great detail on the potential applications of fullerenes.
Tarell
how did you get the value of 2000N.What calculations are needed to arrive at it
Smarajit Reply
Privacy Information Security Software Version 1.1a
Good
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

Get the best Algebra and trigonometry course in your pocket!





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