Stay Updated!



Designed by:

XNA Tutorials
XNA Platformer Starter Kit - Adding Melee - Level.cs
Written by Jeff Brown   
Article Index
XNA Platformer Starter Kit - Adding Melee
Player.cs
Enemy.cs
Level.cs
All Pages

Level.cs


Next in Level.cs find the following in the UpdateEnemies method

// Touching an enemy instantly kills the player
if (enemy.BoundingRectangle.Intersects(Player.BoundingRectangle))
{
    OnPlayerKilled(enemy);
}


And change it to the following:

if (enemy.IsAlive && enemy.BoundingRectangle.Intersects(Player.MeleeRectangle))
{
    if(Player.isAttacking)
        OnEnemyKilled(enemy, Player);
}


Now under the UpdateEnemies method add a new method:

private void OnEnemyKilled(Enemy enemy, Player killedBy)
{
    enemy.OnKilled(killedBy);
}


And that's it! Give it a try and see if you can finally kill those enemies!



 

Add comment


Security code
Refresh