Game Development Reference
In-Depth Information
foreach (Vector v in points)
{
_spline.AddPoint(v);
}
_tween ¼ new Tween(0, 1, travelTime);
}
public void UpdatePosition(double elapsedTime, Enemy enemy)
{
_tween.Update(elapsedTime);
Vector position ¼ _spline.GetPositionOnLine(_tween.Value());
enemy.SetPosition(position);
}
}
The class constructor takes in a time and a list of points; from this it creates a
spline and a tween object. The travelTime determines how long the
enemy will take to travel the path defined by the spline. The UpdatePosition
method updates the tween and gets a new position from the spline, which is used
to reposition the enemy. The following code modifies the Enemy to use the
Path class.
public Path Path { get; set; }
public void Update(double elapsedTime)
{
if (Path != null)
{
Path.UpdatePosition(elapsedTime, this);
}
if (_hitFlashCountDown != 0)
{
_hitFlashCountDown ¼ Math.Max(0, _hitFlashCountDown - elapsedTime);
double scaledTime ¼ 1 - (_hitFlashCountDown / HitFlashTime);
_sprite.SetColor(new Engine.Color(1, 1, (float)scaledTime, 1));
}
}
Now that all enemies have paths, the StartPosition variable from the
EnemyDef can be removed, as the path will define where the enemy starts.
Enemies can move through the level, but to do this they need to be given a path.
Search WWH ::




Custom Search