Archive Browser
Download aitest.zip, last updated 19/06/2010 (11.27 KB)
Download- md5: 9764f053887f43bd6b0b57f7db7496fa
using System.Drawing;
namespace AiTest
{
// Movement rules sourced from:
// http://www.elmerproductions.com/sp/peterb/BDCFF/objects/0009.html
class Butterfly : Sprite
{
#region Public Constructors
public Butterfly()
{
this.Direction = Direction.Down;
}
#endregion Public Constructors
#region Public Overridden Methods
public override void Move()
{
Tile tile;
// TODO: In this sample, we are only checking if a tile is non-solid. We aren't checking the positions of other sprites.
// first see if we can move in our preferred direction, right
tile = this.GetAdjacentTile(this.GetNewDirection(Direction.Right));
if (!tile.Solid)
{
// we can move here, update our position and also set our new direction
this.Location = tile.Location;
this.Direction = this.GetNewDirection(Direction.Right);
}
else
{
// can't move in our preferred direction, so lets try the direction the sprite is facing
tile = this.GetAdjacentTile(this.Direction);
if (!tile.Solid)
{
// we can move here, update our position, but not the direction
this.Location = tile.Location;
}
else
{
// can't move forwards either, so finally lets just turn left
this.Direction = this.GetNewDirection(Direction.Left);
}
}
}
#endregion Public Overridden Methods
#region Public Properties
public override Color Color
{
get { return Color.FromKnownColor(KnownColor.Goldenrod); }
}
#endregion Public Properties
}
}
Donate
This software may be used free of charge, but as with all free software there are costs involved to develop and maintain.
If this site or its services have saved you time, please consider a donation to help with running costs and timely updates.
Donate