| 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:
This version of the 'zap' game looks and plays very similarly to the prior version, which was explained in the 380 tutorial . The major change in this version is that the game will detect when the player's zapping beam has collided with BlockA, and if it has collided, it will cause the laser beam to go up the wall, and then continue on towards the enemy. Note that collisions with all the other blocks are still unhandled
Notice that we will also adjust the hero's laser beam so that there are no spaces in it.
2. Examining The Program:
Let's examine the C# source code that produces the behavior we see on-screen
| Version of code in 315 tutorial | Version of code in this tutorial |
|
XNACS1Circle
lastCircle = null
;
Vector2
HeroBeam = m_Hero.Center;
for
(float x = m_Hero.CenterX+1;
{
HeroBeam.X = x;
lastCircle = CreateHeroPath(HeroBeam);
}
if
(lastCircle.Collided(m_Enemy))
{
m_Enemy.Texture = null
;
PlayACue(@"EnemyZapped");
m_HeroScore++;
}
|
XNACS1Circle
lastCircle = null
;
Vector2
HeroBeam = m_Hero.Center;
for
(float x = m_Hero.CenterX + 1;
{
HeroBeam.X = x;
lastCircle = CreateHeroPath(HeroBeam);
if
(lastCircle.Collided(m_BlockA))
{
for
(
float
y = HeroBeam.Y + 1;
{
HeroBeam.Y = y;
lastCircle = CreateHeroPath(HeroBeam);
}
}
}
if
(lastCircle.Collided(m_Enemy))
{
m_Enemy.Texture
= null
;
PlayACue(@"EnemyZapped");
m_HeroScore++;
} |
if
(lastCircle.Collided(m_BlockA))
for
(
float
y = HeroBeam.Y + 1; y <= m_BlockA.MaxBound.Y; y++)
{
HeroBeam.Y = y;
lastCircle = CreateHeroPath(HeroBeam);
FURTHER EXERCISES: