Обнаружение столкновения между овалом и линией - PullRequest
0 голосов
/ 29 ноября 2018

Есть ли способ обнаружить столкновение между овалом и линией в Java.Я делаю игру, в которой пользователь проводит ракету через «пещеру», где «пещера» состоит из линий, и мне нужно как-то обнаружить столкновение.Код ниже

@Override //draws all the lines and ship
public void paintComponent(Graphics g) {
    super.paintComponent(g);
    Graphics2D g2=(Graphics2D) g;
    Rectangle r=new Rectangle();
    g2.setStroke(new BasicStroke(3));
    g2.drawLine(0, getHeight()-(getHeight()/6), getWidth()/6, getHeight()-(getHeight()/6));
    g2.drawLine(getWidth()/6, getHeight()-(getHeight()/6), getWidth()/6, getHeight()-getHeight()/4);
    g2.drawLine(getWidth()/6, getHeight()-getHeight()/4, getWidth()/6+getWidth()/10, getHeight()-getHeight()/4);
    g2.drawLine(getWidth()/6+getWidth()/10, getHeight()-getHeight()/4, getWidth()/6+getWidth()/10, getHeight()-getHeight()/12);
    g2.drawLine(getWidth()/6+getWidth()/10, getHeight()-getHeight()/12, getWidth()/2, getHeight()-getHeight()/12);
    g2.drawLine(getWidth()/2, getHeight()-getHeight()/12, getWidth()/2, getHeight()-getHeight()/4);
    g2.drawLine(getWidth()/2, getHeight()-getHeight()/4, getWidth()/3+getWidth()/15, getHeight()-getHeight()/4);
    g2.drawLine(getWidth()/3+getWidth()/15, getHeight()-getHeight()/4, getWidth()/3+getWidth()/15, getHeight()-getHeight()/3);
    g2.drawLine(getWidth()/3+getWidth()/15, getHeight()-getHeight()/3, getWidth()/2+getWidth()/7, getHeight()-getHeight()/3);
    g2.drawLine(getWidth()/2+getWidth()/7, getHeight()-getHeight()/3, getWidth()/2+getWidth()/7, getHeight()-getHeight()/6);
    g2.drawLine(getWidth()/2+getWidth()/7, getHeight()-getHeight()/6, getWidth()-getWidth()/4 , getHeight()-getHeight()/6);
    g2.drawLine(getWidth()-getWidth()/4, getHeight()-getHeight()/6, getWidth()-getWidth()/4, getHeight()-getHeight()/4);
    g2.drawLine(getWidth()-getWidth()/4, getHeight()-getHeight()/4, getWidth()-getWidth()/7,  getHeight()-getHeight()/4);
    g2.drawLine(getWidth()-getWidth()/7,  getHeight()-getHeight()/4, getWidth()-getWidth()/7, getHeight()-getHeight()/8);
    g2.drawLine(getWidth()-getWidth()/7, getHeight()-getHeight()/8, getWidth(), getHeight()-getHeight()/8);
    g2.setColor(Color.YELLOW);
    g2.fillRect(getWidth()-getWidth()/7, getHeight()-getHeight()/8, getWidth()/7, 20);
    g2.rotate(Math.toRadians(theta),rocketx+10, rockety+20);
    g2.setColor(Color.orange);
    g2.fillOval(rocketx, rockety, 20, 40);//draws ship
}

public void initialRocket(int x, int y) {//inital position of ship
    rocketx=x/12-10;
    rockety=y-(y/4)-20;
}
...