Commit 1f112716 authored by nargessalehi98's avatar nargessalehi98

Add new Condition for tank movement limit.

parent e4255210
......@@ -32,12 +32,15 @@ public class GameState {
private boolean one = false;
private boolean two = false;
private boolean three = false;
boolean PermissionDown = true;
boolean PermissionUp = true;
public GameState(int num) {
locX = 100;
locY = 100;
diam = 42;
//changed from 42 to 25
diam = 25;
rotateAmount = 0;
gameOver = false;
//
......@@ -65,7 +68,7 @@ public class GameState {
public Rectangle getBounds(int locX, int locY) {
return new Rectangle(locX, locY, 25, 25);
return new Rectangle(locX, locY, 28, 28);
}
/**
......@@ -78,44 +81,69 @@ public class GameState {
locX = mouseX - diam / 2;
}
if (keyUP) {
boolean Permission = true;
PermissionUp = true;
for (Wall wall : Controller.walls) {
if (wall.intersects(getBounds(locX + 5, locY + 5))) {
System.out.println("4");
Permission = false;
if (wall.getWidth() == 5 && wall.getHeight() == 50 ) {
if ((getBounds(locX, locY).intersects(new Rectangle((int) wall.getX(), (int) wall.getY(), 5, 50)))) {
PermissionUp = false;
break;
}
}
if (Permission)
//&& rotateAmount != 90 && rotateAmount != -90 && rotateAmount != 270 && rotateAmount != -270
if (wall.getWidth() == 50 && wall.getHeight() == 5) {
if ((getBounds(locX, locY).intersects(new Rectangle((int) wall.getX(), (int) wall.getY(), 50, 5)))) {
PermissionUp = false;
break;
}
}
// && rotateAmount != 180 && rotateAmount != -180 && rotateAmount != 0
}
if (PermissionUp)
move(+5);
}
if (keyDOWN) {
boolean Permission = true;
PermissionDown = true;
for (Wall wall : Controller.walls) {
if (wall.intersects(getBounds(locX + 5, locY + 5))) {
System.out.println("5");
Permission = false;
if (wall.getWidth() == 5 && (wall.getHeight() == 50 || wall.getHeight() == 5)) {
if ((getBounds(locX, locY).intersects(new Rectangle((int) wall.getX(), (int) wall.getY(), 5, 50)))) {
PermissionDown = false;
break;
}
}
if (Permission)
//&& rotateAmount != 90 && rotateAmount != -90 && rotateAmount != 270 && rotateAmount != -270
if ((wall.getWidth() == 50 || wall.getWidth() == 5) && wall.getHeight() == 5) {
if ((getBounds(locX, locY).intersects(new Rectangle((int) wall.getX(), (int) wall.getY(), 50, 5)))) {
PermissionDown = false;
break;
}
}
//&& rotateAmount != 180 && rotateAmount != -180 && rotateAmount != 0
}
if (PermissionDown)
move(-5);
}
if (keyLEFT)
if (keyLEFT) {
rotateAmount -= 15;
}
if (keyRIGHT)
if (keyRIGHT) {
rotateAmount += 15;
}
locX = Math.max(locX, 40);
//Formula for tank movement limit
locX = Math.min(locX, 20 + (((Controller.col - 1) / 2) * 50) + (((Controller.col - 1) / 2) + 1) * 5 - 25);
locY = Math.max(locY, 70);
locY = Math.min(locY, 50 + ((Controller.row - 1) / 2) * 50 + (((Controller.row - 1) / 2) + 1)*5 -25);
//Formula for tank movement limit
locY = Math.min(locY, 50 + ((Controller.row - 1) / 2) * 50 + (((Controller.row - 1) / 2) + 1) * 5 - 25);
}
public void move(int px) {
......
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