Game Development Reference
In-Depth Information
int _armor ¼ 1;
public void TakeDamage(int damage)
{
_health ¼ _health - Math.Max(0, damage - _armor);
}
}
Far more understandable!
Creating Functions
Often when writing a section of code, a function that's not been written yet is
needed. The generate tools in Visual Studio let you write your code as if the
function did exist, and then automatically create it. As an example, let's take an
update loop for a player class.
class Player
{
public void Update(float timeSinceLastFrame)
{
}
}
In the update loop, the player animation needs to be updated. It's best to do
this in a separate function, and that new function would look something
like this.
class Player
{
public void Update(float timeSinceLastFrame)
{
UpdateAnimation(timeSinceLastFrame);
}
}
This function doesn't exist yet. Instead of writing it all out manually, the generate
functions can do it (see Figure 4.7).
Right-click the function name and choose Generate > Method Stub. The
following code will be created in the Player class.
 
Search WWH ::




Custom Search