| 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 almost identically to the prior version, which was explained in the 360 tutorial . The major change is that in this version, we will detect if the enemy's laser beam has hit a block, and if it has, we will stop the beam at that point. The player's beam will continue to ignore the blocks, as pictured above.
2. Examining The Program:
Let's examine the C# source code that produces the behavior we see on-screen
| Version of code in 360 tutorial | Version of code in this tutorial |
|
�@
XNACS1Circle
lastEnemyCircle = null
;
Vector2
EnemyBeam = m_Enemy.Center;
while
(
EnemyBeam.X > m_Hero.CenterX
)
{
EnemyBeam.X -= 1f;
lastEnemyCircle = CreateEnemyPath(EnemyBeam);
} �@ �@ �@ �@ �@ �@ �@ |
XNACS1Circle
lastEnemyCircle = null
;
Vector2
EnemyBeam = m_Enemy.Center;
bool
blocked =
false
;
// if enemy zap path has encountered a
block
while (!blocked && EnemyBeam.X > m_Hero.CenterX)
{
EnemyBeam.X
-= 1f;
lastEnemyCircle = CreateEnemyPath(EnemyBeam);
// did this last path-element collide with
any of the blocking blocks?
blocked =
CollidedWithBlocks(lastEnemyCircle);
} |
private bool CollidedWithBlocks( XNACS1Circle path)
{
return m_BlockA.Collided(path) || m_BlockB.Collided(path) || m_BlockC.Collided(path);
}
FURTHER EXERCISES::