Commit 4522d483 authored by 9831111's avatar 9831111 🙂

Add bulletCollision method to find collision with walls.

parent 3aa528a8
......@@ -11,6 +11,7 @@ import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;
import java.awt.geom.AffineTransform;
import java.awt.geom.Ellipse2D;
import java.awt.image.BufferedImage;
/**
......@@ -366,6 +367,35 @@ public class GameState {
}
}
}
public void bulletCollision(Bullet bullet) {
for (Wall wall : Controller.walls) {
Rectangle rectangle = new Rectangle(wall.getX(), wall.getY(), wall.getWidth(), wall.getHeight());
Ellipse2D ellipse2D = new Ellipse2D.Double(bullet.x, bullet.y, 7, 7);
if (ellipse2D.intersects(rectangle)) {
new AudioPlayer("sound effects/select.wav", 0);
if (wall.getWidth() == 5 && wall.getHeight() == 50) {
if ((rotateAmountBullet >= 0 && rotateAmountBullet <= 180) || (rotateAmountBullet <= -180 && rotateAmountBullet > -360)) {
rotateAmountBullet = -rotateAmountBullet - 180;
break;
} else {
rotateAmountBullet = 180 - rotateAmountBullet;
break;
}
} else if (wall.getWidth() == 50 && wall.getHeight() == 5) {
rotateAmountBullet = -rotateAmountBullet;
break;
} else if (wall.getWidth() == 5 && wall.getHeight() == 5) {
if ((rotateAmountBullet >= 0 && rotateAmountBullet <= 180) || (rotateAmountBullet <= -180 && rotateAmountBullet > -360)) {
rotateAmountBullet = 180 - rotateAmountBullet;
break;
} else {
rotateAmountBullet = -rotateAmountBullet;
break;
}
}
}
}
}
......
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