class SteeringObject { public: //! Current Position Vector2D position; //! Velocity Vector2D velocity; //! Maximum Speed per frame double maxSpeed; public: //! Seek behaviour /** * The seek behaviour will return a desired * velocity below the max speed, that should * move twards the desiredPosition * * Example usage: velocity += behaviourSeek(badGuy.getPosition()); */ Vector2D behaviourSeek(Vector2D desiredPosition) { // desiredVelocity is the distance between here and // where we want to be. if we acheived this, we would // 'zap' there // let's pretend desired position is 10,10 and position is 5,5 // that would make desiredVelocity 5,5 Vector2D desiredVelocity = position - desiredPosition; // turns 5,5 into, say, 0.5, 0.5. desiredVelocity.Pointalize(); // Now return the desired velocity return desiredVelocity; } //! Flee Behaviour /** * This behaviour will generate a velocity * to move *away* from the provided vector2d * position. */ Vector2D behaviourFlee(Vector2D desiredPosition) { // desiredVelocity is the distance between here and // where we want to be. if we acheived this, we would // 'zap' there Vector2D desiredVelocity = desiredPosition - position; // turns 5,5 into, say, 0.5, 0.5. desiredVelocity.Pointalize(); // Now return the desired velocity return desiredVelocity; }};