I have made a game in XNA where there is a player and some enemies (called LittleEnemy's). I want the enemies to throw an object to where it is facing at a random time. This "ThrowAttack" is a special attack, the enemy can have one special attack at a time (I use XML where I enter the special attack that needs to be used for that specific enemy).
But I can't figure out how to create a true ThrowAttack object which is drawn and moves to the left/right of the screen (and perhaps intersects with the player which will get some damage). I also don't really know where/how to set it's texture. Preferably at .use since every enemy can have it's own texture (for the throwattack).
For now I have this:
The ThrowAttack class:
namespace Jumping.Models.Features
{
[XmlRoot(ElementName = "ThrowAttack")]
public class ThrowAttack : MovableObject, IAttackBehavior
{
private Type typeThatThrows;
public Boolean available;
public void Use(Type objectType)
{
this.typeThatThrows = objectType;
this.Walk(Direction.Right, 2f);
}
}
The walk function used in the above:
public void Walk(Direction direction, float speed)
{
if (direction == Direction.Left)
{
if (velocity.X > -speed)
velocity.X -= (1.0f / 10);
else
velocity.X = -1.0f;
}
else if (direction == Direction.Right)
{
if (velocity.X < speed)
velocity.X += (1.0f / 10);
else
velocity.X = 1.0f;
}
this.direction = direction;
}
This is how I load the enemy in the xml file:
<LittleEnemy>
<TextureName>enemy</TextureName>
<Position>
<X>300</X>
<Y>900</Y>
</Position>
<Speed>2.0</Speed>
<ScreenBoundWidth>
3000
</ScreenBoundWidth>
<ScreenBoundHeight>
1000
</ScreenBoundHeight>
<FrameWidth>60</FrameWidth>
<FrameHeight>37</FrameHeight>
<StrategyBehavior>curious</StrategyBehavior>
<AttackBehavior>ThrowAttack</AttackBehavior>
</LittleEnemy>
And somewhere I finally perform the use function in the ThrowAttack class:
if (enemy.getAttack() != null)
{
ThrowAttack attack = ((ThrowAttack)enemy.getAttack());
Random random = new Random();
if (random.Next(0, 100) > 50 && attack.available)
{
enemy.getAttack().Use(enemy.GetType());
}
else
{
((ThrowAttack)enemy.getAttack()).setPosition(enemy.position);
}
}
 
No comments:
Post a Comment