Commit 3beb84ce authored by Benjamin LEROUX's avatar Benjamin LEROUX

collision try ben

parent 27a3b70f
......@@ -114,10 +114,16 @@ public class MainActivity extends AppCompatActivity {
firstView .getLocationOnScreen(firstPosition);
secondView.getLocationOnScreen(secondPosition);
Rect rectFirstView = new Rect(firstPosition [0], firstPosition [1],
firstPosition [0] + firstView .getMeasuredWidth(), firstPosition [1] + firstView .getMeasuredHeight());
firstPosition [0] + firstView .getMeasuredWidth()/2, firstPosition [1] + firstView .getMeasuredHeight()/2);
Rect rectSecondView = new Rect(secondPosition[0], secondPosition[1],
secondPosition[0] + secondView.getMeasuredWidth(), secondPosition[1] + secondView.getMeasuredHeight());
float x_inter = Math.max(0, Math.min(rectFirstView.right, rectSecondView.right) - Math.max(rectFirstView.left, rectSecondView.left));
float y_inter = Math.max(0, Math.min(rectFirstView.bottom, rectSecondView.bottom) - Math.max(rectFirstView.top, rectSecondView.top));
float aireInter = x_inter * y_inter;
return(rectFirstView. intersect (rectSecondView));
}
}
......@@ -69,8 +69,8 @@
<ImageView
android:id="@+id/asteroid2"
android:layout_width="138dp"
android:layout_height="113dp"
android:layout_width="84dp"
android:layout_height="72dp"
android:layout_marginStart="50dp"
android:layout_marginLeft="80dp"
android:layout_marginTop="150dp"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment