Commit c32410b3 authored by 9831111's avatar 9831111 🙂

Merge remote-tracking branch 'origin/master'

# Conflicts:
#	src/GameState.java
parents 4da00adb 3a518db6
......@@ -32,15 +32,12 @@ 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;
//changed from 42 to 25
diam = 25;
diam = 42;
rotateAmount = 0;
gameOver = false;
//
......@@ -67,82 +64,48 @@ public class GameState {
}
public Rectangle getBounds(int locX, int locY) {
return new Rectangle(locX, locY, 28, 28);
public Rectangle getBounds(int locX,int locY){
return new Rectangle( locX, locY, 25, 25);
}
/**
* The method which updates the game state.
*/
public void update() {
public void update() throws AWTException {
if (rotateAmount >= 360 || rotateAmount <= -360) rotateAmount = 0;
if (mousePress) {
locY = mouseY - diam / 2;
locX = mouseX - diam / 2;
}
if (keyUP) {
PermissionUp = true;
for (Wall wall : Controller.walls) {
//if (Math.abs(locX - wall.getX()) <= 5 && Math.abs(locY - wall.getY()) <= 5) {
if (wall.getWidth() == 5 && wall.getHeight() == 50 && rotateAmount != 90 && rotateAmount != -90 && rotateAmount != 270 && rotateAmount != -270) {
if ((getBounds(locX, locY).intersects(new Rectangle((int) wall.getX(), (int) wall.getY(), 5, 50)))) {
System.out.println("2");
//if (PermissionDown)
PermissionUp = false;
break;
}
}
}
if (PermissionUp)
// boolean Permission=true;
// for (Wall wall : Controller.walls) {
// if(wall.intersects(getBounds(locX+5,locY+5))){
// System.out.println("4");
// Permission = false;
// break;
// }
// }
// if (Permission)
move(+5);
}
if (keyDOWN) {
PermissionDown = true;
for (Wall wall : Controller.walls) {
if (wall.getWidth() == 5 && wall.getHeight() == 50) {
if ((getBounds(locX, locY).intersects(new Rectangle((int) wall.getX(), (int) wall.getY(), 5, 50)))) {
System.out.println("3");
if (PermissionUp)
PermissionDown = false;
break;
}
}
if (wall.getWidth() == 50 && wall.getHeight() == 5) {
if ((getBounds(locX, locY - 2).intersects(new Rectangle((int) wall.getX(), (int) wall.getY(), 50, 5)))) {
System.out.println("4");
if (PermissionUp)
PermissionDown = false;
break;
}
}
}
if (PermissionDown)
boolean Permission=true;
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);
locX = Math.max(locX, 42);
locX = Math.min(locX, GameFrame.GAME_WIDTH - diam - 42);
locY = Math.max(locY, 70);
//Formula for tank movement limit
locY = Math.min(locY, 50 + ((Controller.row - 1) / 2) * 50 + (((Controller.row - 1) / 2) + 1) * 5 - 25);
locY = Math.min(locY, ((Controller.row-1)/2)*50+60);
}
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