public void Act(float timeElapsed) { Vector2D steeringForce = new Vector2D(0, 0); if (hobgoblin._WB != null) { steeringForce += hobgoblin._WB.Calculate(); } if (hobgoblin._OA != null) { steeringForce += hobgoblin._OA.Calculate(); } if (hobgoblin._WA != null) { steeringForce += hobgoblin._WA.Calculate(); } steeringForce.Truncate(hobgoblin.MaxForce); Vector2D acceleration = steeringForce / hobgoblin.Mass; hobgoblin.Velocity += (acceleration * timeElapsed); hobgoblin.Velocity = hobgoblin.Velocity.Truncate(hobgoblin.MaxSpeed); hobgoblin.OldPos = hobgoblin.Pos; hobgoblin.Pos += (hobgoblin.Velocity * timeElapsed); if (hobgoblin.Velocity.LengthSquared() > 0.00000001) { hobgoblin.Heading = hobgoblin.Velocity.Normalize(); hobgoblin.Side = hobgoblin.Heading.Perp(); } hobgoblin.WrapAround(); hobgoblin.world.rePosGoblin(hobgoblin.Key, hobgoblin.OldPos, hobgoblin.Pos); }
public void Act(float timeElapsed) { timeElapsedSinceLastAttack += timeElapsed; if (VectorMath.DistanceBetweenPositions(hobgoblin.Pos, hobgoblin.world.Hero.Pos) >= hobgoblin.AttackRange) { Vector2D steeringForce = new Vector2D(0, 0); if (hobgoblin._SB != null) { steeringForce += hobgoblin._SB.Calculate() * 4; } if (hobgoblin._OA != null) { steeringForce += hobgoblin._OA.Calculate(); } if (hobgoblin._WA != null) { steeringForce += hobgoblin._WA.Calculate(); } steeringForce.Truncate(hobgoblin.MaxForce); Vector2D acceleration = steeringForce / hobgoblin.Mass; hobgoblin.Velocity += (acceleration * timeElapsed); hobgoblin.Velocity = hobgoblin.Velocity.Truncate(hobgoblin.MaxSpeed); hobgoblin.OldPos = hobgoblin.Pos; hobgoblin.Pos += (hobgoblin.Velocity * timeElapsed); if (hobgoblin.Velocity.LengthSquared() > 0.00000001) { hobgoblin.Heading = hobgoblin.Velocity.Normalize(); hobgoblin.Side = hobgoblin.Heading.Perp(); } hobgoblin.WrapAround(); hobgoblin.world.rePosGoblin(hobgoblin.Key, hobgoblin.OldPos, hobgoblin.Pos); } else if (AttackAvailable()) { //AttackPlayer(); } // Checks wether a state change is in order. StateCheck(); }