示例#1
0
void alert_motion(submarine sub, submarine enemy)
{
    if (enemy.move || enemy.turn)
    {
        // subtract player position from enemy position for direction to enemy
        vector ray = subtract(enemy.position, sub.position);

        // compare direction to enemy with current rotation
        int prod = dot(ray, sub.rotation);

        // alert if facing enemy in motion (does not detect directly to the side)
        if (prod > 0 && manhattan_length(ray) <= DETECT_DISTANCE)
        {
            printf(MOTION_ALERT, DETECT_DISTANCE);
        }
    }
}
示例#2
0
const typename t::value_type
manhattan_distance (const t& lhs, const t& rhs)
{
    return manhattan_length(diff(lhs, rhs));
}