If those pipes are line shaped and if you know their line formula(or at least coords. of end points), then you can use "perpendicular distance to a line" calculation to know if it is close enough.
That is already answered: here
If a pipe needs to be a complex shape, and if you are ok with a particle simulation, here is very simple, inefficient but easy to use example that builds an object on a group of collidable objects and checks collision with a single object(bird):
import java.util.ArrayList;
import java.util.List;
public class FactoryClass {
public class CollidableResult
{
public Collidable c;
public boolean yesItIs;
}
public class Collidable
{
public float x;
public float y;
public static final float tolerance=600.001f;
public Collidable()
{
//just giving random starting coordinates for fun
// so the object may not be a pipe with these. Please add some parameters
// for your needs
x=(float) (Math.random()*1000.0);
y=(float) (Math.random()*1000.0);
}
public CollidableResult isTooClose(Collidable c)
{
float deltax=(c.x - this.x);
float deltay=(c.y - this.y);
// checks if close enough
if(Math.sqrt(deltax*deltax + deltay*deltay)<tolerance)
{
CollidableResult cr=new CollidableResult();
cr.yesItIs=true;
cr.c=this;
return cr;
}
else
{
CollidableResult cr=new CollidableResult();
cr.yesItIs=false;
cr.c=null;
return cr;
}
}
public List<Collidable> collide(List<Collidable> cl)
{
List<Collidable> c=new ArrayList<Collidable>();
for(Collidable co:cl)
{
if(this.isTooClose(co).yesItIs)
{
c.add(co);
}
}
return c;
}
public void die()
{
// AnimateDead();
try {this.finalize();} catch (Throwable e) {e.printStackTrace();}
System.gc();
}
public void levelUp()
{
System.out.println("Level Up! Hit points incremented by 12.");
}
}
public static void main(String[] args) {
FactoryClass factory=new FactoryClass();
List<Collidable> pointsOfAPipe = new ArrayList<Collidable>();
pointsOfAPipe.add(factory.new Collidable(/*parameters for pipe */));
pointsOfAPipe.add(factory.new Collidable(/*parameters for pipe */));
pointsOfAPipe.add(factory.new Collidable(/*parameters for pipe */));
//...
// build your pipe object using many colllidable points (can build complex shapes with this)
//...
pointsOfAPipe.add(factory.new Collidable(/*parameters for pipe */));
pointsOfAPipe.add(factory.new Collidable(/*parameters for pipe */));
pointsOfAPipe.add(factory.new Collidable(/*parameters for pipe */));
Collidable bird=factory.new Collidable();
bird.x=100;
bird.y=350;
List<Collidable> collisionPoints = bird.collide(pointsOfAPipe);
if(collisionPoints.size()>0)
{
System.out.println("Bird collides pipe on "+collisionPoints.size()+" different points and dies");
bird.die();
}
else {System.out.println("Bird survived");bird.levelUp();}
}
}
most of the time, output for me is:
Bird collides pipe on 4 different points and dies
You can add another class that integrates different collections to make even more complex scenarios such as rotating turrets mounted on a spaceship which fires beams to cut pipes and even collides other spaceships and birds.