| XNA Game-Themed CS1 Examples ( XGC1 ) | |
|
Release 2.0 (XNA V3.1)
|
|
References:
Goals:
1. Obtain the example code
When the game starts, you'll see a screen that
looks similar to this:
You'll notice that this is almost identical to the 050 tutorial , except that when the player pushes the 'A' button, the laser now extends across the entire screen. You'll notice that when the hero's laser beam overlaps the enemy soccer ball, the hero gets a point. The enemy's laser beam is still only a couple of circles long, leaving it with no hope of reaching the hero, which makes this version of the game a bit lopsided. You'll also notice that the laser beam is NOT stopped by the blocks in the middle of the screen. As you can see in the above picture, the laser beam is drawn behind the block, and continues on afterwards. We'll fix both problems a future tutorials.
Because the program is almost entirely the same as the previous tutorial that used this program, we will focus only what's new in this program. If you need to refresh your memory about how the game is set up overall, please refer to the 050 tutorial .
2. Examining The Program:
Let's examine the C# source code that produces the behavior we see on-screen
|
#region
Hero zapping
if
(GamePad.ButtonAClicked())
{
PlayACue(
"ZapPath"
);
XNACS1Circle
lastCircle =
null
;
Vector2
HeroBeam =
m_Hero.Center;
while
(HeroBeam.X <=
m_Enemy.CenterX)
{
HeroBeam.X += 1f;
lastCircle
= CreateHeroPath(HeroBeam);
}
if
(
lastCircle
.Collided(m_Enemy))
{
m_Enemy.Texture =
null
;
PlayACue(
@"EnemyZapped"
);
m_HeroScore++;
}
}
#endregion
hero zapping
|
Vector2
HeroBeam =
m_Hero.Center;
while
(HeroBeam.X <=
m_Enemy.CenterX)
{
HeroBeam.X += 1f;
lastCircle
=
CreateHeroPath(HeroBeam);
}
if
(
lastCircle
.Collided(m_Enemy))
{
m_Enemy.Texture =
null
;
PlayACue(
@"EnemyZapped"
);
m_HeroScore++;
}
m_Enemy.Texture =
@"SoccerBall"
;
FURTHER EXERCISES::