Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
J
JTankTrouble
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
9831111
JTankTrouble
Commits
1f14476f
Commit
1f14476f
authored
Aug 07, 2020
by
nargessalehi98
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add PC move new method.
parent
6c645224
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
241 additions
and
148 deletions
+241
-148
GameState.java
src/GameState.java
+241
-148
No files found.
src/GameState.java
View file @
1f14476f
...
@@ -16,22 +16,25 @@ import java.awt.image.BufferedImage;
...
@@ -16,22 +16,25 @@ import java.awt.image.BufferedImage;
import
java.io.File
;
import
java.io.File
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
import
java.util.Random
;
/**
/**
* This class holds the state of game and all of its elements.
* This class holds the state of game and all of its elements.
* This class also handles user inputs, which affect the game state.
* This class also handles user inputs, which affect the game state.
*
*
* @author Seyed Mohammad Ghaffarian
* @author Seyed Mohammad Ghaffarian
* @version 2.1
*/
*/
public
class
GameState
{
public
class
GameState
{
//keep location of tank
public
int
locX
,
locY
,
diam
;
public
int
locX
,
locY
,
diam
;
//keep location of enemy
public
int
pcX
,
pcY
;
public
int
pcX
,
pcY
;
public
boolean
gameOver
,
keyM
;
public
boolean
gameOver
,
keyM
;
public
boolean
keyUP
,
keyDOWN
,
keyRIGHT
,
keyLEFT
;
public
boolean
keyUP
,
keyDOWN
,
keyRIGHT
,
keyLEFT
;
private
boolean
mousePress
;
private
boolean
mousePress
;
private
int
mouseX
,
mouseY
;
private
int
mouseX
,
mouseY
;
private
int
bulletTime
=
0
;
private
KeyHandler
keyHandler
;
private
KeyHandler
keyHandler
;
private
MouseHandler
mouseHandler
;
private
MouseHandler
mouseHandler
;
public
double
rotateAmountTank
;
public
double
rotateAmountTank
;
...
@@ -43,24 +46,24 @@ public class GameState {
...
@@ -43,24 +46,24 @@ public class GameState {
private
boolean
right
;
private
boolean
right
;
private
boolean
up
;
private
boolean
up
;
private
boolean
down
;
private
boolean
down
;
boolean
PermissionUp
=
true
;
boolean
PermissionDown
=
true
;
public
double
rotateAmountBullet
;
public
double
rotateAmountBullet
;
private
int
bulletTime
=
0
;
private
int
tankTime
=
0
;
public
ArrayList
<
Bullet
>
bullets
;
public
ArrayList
<
Bullet
>
bullets
;
//count number of enemy moves
public
int
move
=
0
;
/**
* create a new Game State with given number which is used for tank type
*
* @param num of tank
*/
public
GameState
(
int
num
)
{
public
GameState
(
int
num
)
{
locX
=
100
;
//set default value
locX
=
40
;
locY
=
100
;
locY
=
100
;
diam
=
32
;
diam
=
32
;
pcX
=
4
0
;
pcX
=
30
0
;
pcY
=
1
00
;
pcY
=
4
00
;
rotateAmountTank
=
0
;
rotateAmountTank
=
0
;
rotateAmountBullet
=
0
;
rotateAmountBullet
=
0
;
gameOver
=
false
;
gameOver
=
false
;
...
@@ -101,6 +104,7 @@ public class GameState {
...
@@ -101,6 +104,7 @@ public class GameState {
public
Rectangle
getBounds
(
int
locX
,
int
locY
)
{
public
Rectangle
getBounds
(
int
locX
,
int
locY
)
{
return
new
Rectangle
(
locX
,
locY
,
25
,
25
);
return
new
Rectangle
(
locX
,
locY
,
25
,
25
);
}
}
public
Wall
verticalWallCollision
()
{
public
Wall
verticalWallCollision
()
{
for
(
Wall
wall
:
Controller
.
walls
)
{
for
(
Wall
wall
:
Controller
.
walls
)
{
if
(
wall
.
getWidth
()
==
5
&&
wall
.
getHeight
()
==
50
)
{
if
(
wall
.
getWidth
()
==
5
&&
wall
.
getHeight
()
==
50
)
{
...
@@ -176,90 +180,225 @@ public class GameState {
...
@@ -176,90 +180,225 @@ public class GameState {
return
true
;
return
true
;
}
}
public
void
pcUpdate
()
{
public
Wall
verticalWallCollisionPC
()
{
for
(
Wall
wall
:
Controller
.
walls
)
{
for
(
Wall
wall
:
Controller
.
walls
)
{
if
(
wall
.
getWidth
()
==
5
&&
wall
.
getHeight
()
==
50
)
{
if
(
wall
.
getWidth
()
==
5
&&
wall
.
getHeight
()
==
50
)
{
if
(
getBounds
(
pcX
,
pcY
).
intersects
(
new
Rectangle
((
int
)
wall
.
getX
(),
(
int
)
wall
.
getY
(),
(
int
)
wall
.
getWidth
(),
(
int
)
wall
.
getHeight
()))
&&
wall
.
getX
()
<
pcX
)
{
if
((
getBounds
(
pcX
,
pcY
).
intersects
(
new
Rectangle
((
int
)
wall
.
getX
(),
(
int
)
wall
.
getY
(),
5
,
50
))))
{
left
=
false
;
return
wall
;
System
.
out
.
println
(
"3"
);
break
;
}
if
(
getBounds
(
pcX
,
pcY
).
intersects
(
new
Rectangle
((
int
)
wall
.
getX
(),
(
int
)
wall
.
getY
(),
(
int
)
wall
.
getWidth
(),
(
int
)
wall
.
getHeight
()))
&&
wall
.
getX
()
>
pcX
)
{
right
=
false
;
System
.
out
.
println
(
"4"
);
break
;
}
}
}
}
if
(
wall
.
getWidth
()
==
50
&&
wall
.
getHeight
()
==
5
)
{
}
return
null
;
}
if
(
getBounds
(
pcX
,
pcY
).
intersects
(
new
Rectangle
((
int
)
wall
.
getX
(),
(
int
)
wall
.
getY
(),
(
int
)
wall
.
getWidth
(),
(
int
)
wall
.
getHeight
()))
&&
wall
.
getY
()
>
pcY
)
{
public
Wall
horizontalWallCollisionPC
()
{
down
=
false
;
for
(
Wall
wall
:
Controller
.
walls
)
{
System
.
out
.
println
(
"2"
);
if
(
wall
.
getWidth
()
==
50
&&
wall
.
getHeight
()
==
5
)
{
break
;
if
((
getBounds
(
pcX
,
pcY
).
intersects
(
new
Rectangle
((
int
)
wall
.
getX
(),
(
int
)
wall
.
getY
(),
50
,
5
))))
{
}
return
wall
;
if
(
getBounds
(
pcX
,
pcY
).
intersects
(
new
Rectangle
((
int
)
wall
.
getX
(),
(
int
)
wall
.
getY
(),
(
int
)
wall
.
getWidth
(),
(
int
)
wall
.
getHeight
()))
&&
wall
.
getY
()
<
pcY
)
{
System
.
out
.
println
(
"1"
);
up
=
false
;
break
;
}
}
}
}
if
(!
up
&&
!
down
&&
!
left
&&
!
right
)
{
}
if
(
getBounds
(
pcX
,
pcY
).
intersects
(
new
Rectangle
((
int
)
wall
.
getX
(),
(
int
)
wall
.
getY
(),
(
int
)
wall
.
getWidth
(),
(
int
)
wall
.
getHeight
()))
&&
wall
.
getX
()
<
pcX
)
{
return
null
;
left
=
false
;
}
System
.
out
.
println
(
"33"
);
}
else
{
left
=
true
;
}
if
(
getBounds
(
pcX
,
pcY
).
intersects
(
new
Rectangle
((
int
)
wall
.
getX
(),
(
int
)
wall
.
getY
(),
(
int
)
wall
.
getWidth
(),
(
int
)
wall
.
getHeight
()))
&&
wall
.
getX
()
>
pcX
)
{
right
=
false
;
System
.
out
.
println
(
"44"
);
}
else
right
=
true
;
public
boolean
isMoveAllowedPC
()
{
if
(
wall
.
getWidth
()
==
50
&&
wall
.
getHeight
()
==
5
)
{
if
(
verticalWallCollisionPC
()
!=
null
)
{
if
(
verticalWallCollisionPC
().
getX
()
>
pcX
)
{
if
(
rotateAmountTank
==
0
)
{
return
false
;
}
else
return
true
;
}
if
(
verticalWallCollisionPC
().
getX
()
<
pcX
)
{
if
(
rotateAmountTank
==
180
)
{
return
false
;
}
else
return
true
;
}
}
if
(
getBounds
(
pcX
,
pcY
).
intersects
(
new
Rectangle
((
int
)
wall
.
getX
(),
(
int
)
wall
.
getY
(),
(
int
)
wall
.
getWidth
(),
(
int
)
wall
.
getHeight
()))
&&
wall
.
getY
()
>
pcY
)
{
if
(
horizontalWallCollisionPC
()
!=
null
)
{
down
=
false
;
if
(
horizontalWallCollisionPC
().
getY
()
>
pcY
)
{
System
.
out
.
println
(
"22"
);
if
(
rotateAmountTank
==
90
)
{
break
;
return
false
;
}
else
}
else
return
true
;
down
=
true
;
}
if
(
getBounds
(
pcX
,
pcY
).
intersects
(
new
Rectangle
((
int
)
wall
.
getX
(),
(
int
)
wall
.
getY
(),
(
int
)
wall
.
getWidth
(),
(
int
)
wall
.
getHeight
()))
&&
wall
.
getY
()
<
pcY
)
{
if
(
horizontalWallCollisionPC
().
getY
()
<
pcY
)
{
System
.
out
.
println
(
"11"
);
if
(
rotateAmountTank
==
270
)
{
up
=
false
;
return
false
;
break
;
}
else
return
true
;
}
else
}
up
=
true
;
}
return
true
;
}
public
void
pcUpdate
()
{
System
.
out
.
println
(
isMoveAllowedPC
());
if
(
move
>
0
&&
move
<
200
)
{
if
(
move
<
100
)
{
rotateAmountPC
=
90
;
if
(
isMoveAllowedPC
())
pcY
+=
2
;
else
{
rotateAmountPC
=
270
;
pcY
-=
2
;
}
}
else
{
rotateAmountPC
=
0
;
if
(
isMoveAllowedPC
())
pcX
+=
2
;
else
{
rotateAmountPC
=
180
;
pcX
-=
2
;
}
}
}
}
}
}
if
(
up
)
{
if
(
move
>=
200
&&
move
<
500
)
{
pcY
-=
2
;
if
(
move
<=
250
)
{
rotateAmountPC
=
270
;
rotateAmountPC
=
180
;
}
else
if
(
down
)
{
if
(
isMoveAllowedPC
())
pcY
+=
2
;
pcX
-=
2
;
rotateAmountPC
=
90
;
else
{
}
else
if
(
right
)
{
rotateAmountPC
=
0
;
pcX
-=
2
;
pcX
+=
2
;
rotateAmountPC
=
180
;
}
}
else
if
(
left
)
{
}
else
{
pcX
+=
2
;
rotateAmountPC
=
270
;
rotateAmountPC
=
0
;
if
(
isMoveAllowedPC
())
pcY
-=
2
;
else
{
rotateAmountPC
=
90
;
pcY
+=
2
;
}
}
}
}
if
(
move
>=
500
&&
move
<
800
)
{
// pcX = Math.max(pcX, 40);
if
(
move
<
650
)
{
// pcX = Math.min(pcX, 20 + (((Controller.col - 1) / 2) * 50) + (((Controller.col - 1) / 2) + 1) * 5 - 25);
rotateAmountPC
=
270
;
if
(
isMoveAllowedPC
())
pcY
-=
2
;
else
{
rotateAmountPC
=
90
;
pcY
+=
2
;
}
}
else
{
rotateAmountPC
=
180
;
if
(
isMoveAllowedPC
())
pcX
-=
2
;
else
{
rotateAmountPC
=
0
;
pcX
+=
2
;
}
}
}
if
(
move
>=
800
&&
move
<
1200
)
{
if
(
move
<
950
)
{
rotateAmountPC
=
0
;
if
(
isMoveAllowedPC
())
pcX
+=
2
;
else
{
rotateAmountPC
=
180
;
pcX
-=
2
;
}
}
else
{
rotateAmountPC
=
90
;
if
(
isMoveAllowedPC
())
pcY
+=
2
;
else
{
rotateAmountPC
=
270
;
pcY
-=
2
;
}
}
}
move
++;
if
(
move
==
1200
)
move
=
0
;
// for (Wall wall : Controller.walls) {
// if (wall.getWidth() == 5 && wall.getHeight() == 50 || wall.getWidth() == 5 && wall.getHeight() == 5) {
// if (getBounds(pcX, pcY).intersects(new Rectangle((int) wall.getX(), (int) wall.getY(), (int) wall.getWidth(), (int) wall.getHeight())) && wall.getX() < pcX) {
// left = false;
// System.out.println("3");
// break;
// }
// if (getBounds(pcX, pcY).intersects(new Rectangle((int) wall.getX(), (int) wall.getY(), (int) wall.getWidth(), (int) wall.getHeight())) && wall.getX() > pcX) {
// right = false;
// System.out.println("4");
// break;
// }
// }
// if (wall.getWidth() == 50 && wall.getHeight() == 5 || wall.getWidth() == 5 && wall.getHeight() == 5) {
// if (getBounds(pcX, pcY).intersects(new Rectangle((int) wall.getX(), (int) wall.getY(), (int) wall.getWidth(), (int) wall.getHeight())) && wall.getY() > pcY) {
// down = false;
// System.out.println("2");
// break;
// }
// if (getBounds(pcX, pcY).intersects(new Rectangle((int) wall.getX(), (int) wall.getY(), (int) wall.getWidth(), (int) wall.getHeight())) && wall.getY() < pcY ) {
// System.out.println("1");
// up = false;
// break;
// }
// }
//
//
// pcY = Math.max(pcY, 70);
// if (!up && !down && !left && !right) {
// pcY = Math.min(pcY, 50 + ((Controller.row - 1) / 2) * 50 + (((Controller.row - 1) / 2) + 1) * 5 - 25);
// if (wall.getWidth() == 5 && wall.getHeight() == 50) {
// if (getBounds(pcX, pcY).intersects(new Rectangle((int) wall.getX(), (int) wall.getY(), (int) wall.getWidth(), (int) wall.getHeight())) && wall.getX() < pcX) {
// left = false;
// System.out.println("33");
// } else {
// left = true;
// System.out.println("3333");
//
// }
// if (getBounds(pcX, pcY).intersects(new Rectangle((int) wall.getX(), (int) wall.getY(), (int) wall.getWidth(), (int) wall.getHeight())) && wall.getX() > pcX) {
// right = false;
// System.out.println("44");
// } else {
// right = true;
// System.out.println("4444");
// }
// }
// if (wall.getWidth() == 50 && wall.getHeight() == 5) {
// if (getBounds(pcX, pcY).intersects(new Rectangle((int) wall.getX(), (int) wall.getY(), (int) wall.getWidth(), (int) wall.getHeight())) && wall.getY() > pcY) {
// down = false;
// System.out.println("22");
// break;
// } else {
// down = true;
// System.out.println("2222");
// }
// if (getBounds(pcX, pcY).intersects(new Rectangle((int) wall.getX(), (int) wall.getY(), (int) wall.getWidth(), (int) wall.getHeight())) && wall.getY() < pcY) {
// System.out.println("11");
// up = false;
// break;
// } else {
// up = true;
// System.out.println("1111");
// }
// }
// }
// }
// if (up) {
// pcY -= 2;
// rotateAmountPC = 270;
// } else if (down) {
// pcY += 2;
// rotateAmountPC = 90;
// } else if (left) {
// pcX -= 2;
// rotateAmountPC = 180;
// } else if (right) {
// pcX += 2;
// rotateAmountPC = 0;
// }
pcX
=
Math
.
max
(
pcX
,
40
);
pcX
=
Math
.
min
(
pcX
,
20
+
(((
Controller
.
col
-
1
)
/
2
)
*
50
)
+
(((
Controller
.
col
-
1
)
/
2
)
+
1
)
*
5
-
25
);
pcY
=
Math
.
max
(
pcY
,
70
);
pcY
=
Math
.
min
(
pcY
,
50
+
((
Controller
.
row
-
1
)
/
2
)
*
50
+
(((
Controller
.
row
-
1
)
/
2
)
+
1
)
*
5
-
25
);
}
}
...
@@ -275,75 +414,24 @@ public class GameState {
...
@@ -275,75 +414,24 @@ public class GameState {
if
(
keyUP
)
{
if
(
keyUP
)
{
calculateBullet
(
"x"
);
calculateBullet
(
"x"
);
calculateBullet
(
"y"
);
calculateBullet
(
"y"
);
move
(+
5
);
PermissionUp
=
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
))))
{
//&&
// ((rotateAmount == 0 && locX < wall.getX()) || ((rotateAmount == 180 || rotateAmount == -180) && locX > wall.getX()))
PermissionUp
=
false
;
break
;
}
}
if
(
wall
.
getWidth
()
==
50
&&
wall
.
getHeight
()
==
5
)
{
if
((
getBounds
(
locX
,
locY
).
intersects
(
new
Rectangle
((
int
)
wall
.
getX
(),
(
int
)
wall
.
getY
(),
50
,
5
))))
{
// &&
// (((rotateAmount == +90 || rotateAmount == -270) && locY < wall.getY()) || (((rotateAmount == -90 || rotateAmount == -270) && locY > wall.getY())))
PermissionUp
=
false
;
break
;
}
}
}
if
(
PermissionUp
)
move
(+
5
);
for
(
Wall
wall
:
Controller
.
walls
)
if
(!
PermissionDown
&&
(!(
getBounds
(
locX
,
locY
).
intersects
(
new
Rectangle
((
int
)
wall
.
getX
(),
(
int
)
wall
.
getY
(),
50
,
5
)))
||
!(
getBounds
(
locX
,
locY
).
intersects
(
new
Rectangle
((
int
)
wall
.
getX
(),
(
int
)
wall
.
getY
(),
5
,
50
)))))
{
move
(+
5
);
break
;
}
}
}
if
(
keyDOWN
)
{
if
(
keyDOWN
)
{
calculateBullet
(
"x"
);
calculateBullet
(
"x"
);
calculateBullet
(
"y"
);
calculateBullet
(
"y"
);
PermissionDown
=
true
;
move
(-
5
);
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
))))
{
//&&
// ((((rotateAmount == 0) || locX >= wall.getX())) || (((rotateAmount == -180 || rotateAmount == 180) && locX <= wall.getX())))
PermissionDown
=
false
;
break
;
}
}
if
(
wall
.
getWidth
()
==
50
&&
wall
.
getHeight
()
==
5
)
{
if
((
getBounds
(
locX
,
locY
).
intersects
(
new
Rectangle
((
int
)
wall
.
getX
(),
(
int
)
wall
.
getY
(),
50
,
5
))))
{
// &&
// (((rotateAmount == -90 || rotateAmount == 270) && locY<wall.getY()))|| (((rotateAmount==90||rotateAmount==-270)&& locY>wall.getY()))
PermissionDown
=
false
;
break
;
}
}
}
if
(
PermissionDown
)
move
(-
5
);
for
(
Wall
wall
:
Controller
.
walls
)
if
(!
PermissionUp
&&
(!(
getBounds
(
locX
,
locY
).
intersects
(
new
Rectangle
((
int
)
wall
.
getX
(),
(
int
)
wall
.
getY
(),
50
,
5
)))
||
!(
getBounds
(
locX
,
locY
).
intersects
(
new
Rectangle
((
int
)
wall
.
getX
(),
(
int
)
wall
.
getY
(),
5
,
50
)))))
{
move
(-
5
);
break
;
}
}
}
for
(
Prize
prize
:
Controller
.
prizes
)
{
for
(
Prize
prize
:
Controller
.
prizes
)
{
if
((
getBounds
(
locX
,
locY
).
intersects
(
new
Rectangle
((
int
)
prize
.
getX
(),
(
int
)
prize
.
getY
(),
prize
.
getWidth
(),
prize
.
getHeight
())))
)
{
if
((
getBounds
(
locX
,
locY
).
intersects
(
new
Rectangle
((
int
)
prize
.
getX
(),
(
int
)
prize
.
getY
(),
prize
.
getWidth
(),
prize
.
getHeight
())))
)
{
Controller
.
getPrize
=
true
;
Controller
.
getPrize
=
true
;
Controller
.
tanks
.
get
(
0
).
setPrize
(
prize
.
getName
());
Controller
.
tanks
.
get
(
0
).
setPrize
(
prize
.
getName
());
}
}
if
((
getBounds
(
pcX
,
pcY
).
intersects
(
new
Rectangle
((
int
)
prize
.
getX
(),
(
int
)
prize
.
getY
(),
prize
.
getWidth
(),
prize
.
getHeight
())))){
Controller
.
getPrize
=
true
;
Controller
.
tanks
.
get
(
1
).
setPrize
(
prize
.
getName
());
}
}
}
if
(
keyLEFT
)
if
(
keyLEFT
)
...
@@ -365,14 +453,17 @@ public class GameState {
...
@@ -365,14 +453,17 @@ public class GameState {
if
(
keyM
&&
Controller
.
tanks
.
size
()
>
0
)
{
if
(
keyM
&&
Controller
.
tanks
.
size
()
>
0
)
{
if
(
rotateAmountBullet
>=
360
||
rotateAmountBullet
<=
-
360
)
rotateAmountBullet
=
0
;
if
(
rotateAmountBullet
>=
360
||
rotateAmountBullet
<=
-
360
)
rotateAmountBullet
=
0
;
Bullet
bullet
=
new
Bullet
(
calculateBullet
(
"x"
),
calculateBullet
(
"y"
),
rotateAmountBullet
,
30
);
Bullet
bullet
=
new
Bullet
(
calculateBullet
(
"x"
),
calculateBullet
(
"y"
),
rotateAmountBullet
,
Controller
.
bulletDamage
);
bullets
.
add
(
bullet
);
bullets
.
add
(
bullet
);
bulletCollision
(
bullets
.
get
(
0
));
bulletCollision
(
bullets
.
get
(
0
));
shotBullet
(
8
,
bullets
.
get
(
0
));
if
(
Controller
.
bulletSpeed
==
0
)
Controller
.
bulletSpeed
=
4
;
shotBullet
(
Controller
.
bulletSpeed
,
bullets
.
get
(
0
));
if
(
Controller
.
laser
)
g2d
.
setColor
(
Color
.
red
);
else
g2d
.
setColor
(
Color
.
black
);
g2d
.
fillOval
(
bullets
.
get
(
0
).
x
,
bullets
.
get
(
0
).
y
,
7
,
7
);
g2d
.
fillOval
(
bullets
.
get
(
0
).
x
,
bullets
.
get
(
0
).
y
,
7
,
7
);
if
(
bullets
.
size
()
>
5
&&
Controller
.
tanks
.
size
()
>
0
)
if
(
bullets
.
size
()
>
7
&&
Controller
.
tanks
.
size
()
>
0
)
checkTankDestroyed
(
Controller
.
tanks
.
get
(
0
),
bullets
.
get
(
0
));
checkTankDestroyed
(
Controller
.
tanks
.
get
(
0
),
bullets
.
get
(
0
));
if
(
bulletTime
>
60
)
{
if
(
bulletTime
>
60
)
{
...
@@ -386,7 +477,6 @@ public class GameState {
...
@@ -386,7 +477,6 @@ public class GameState {
}
}
bulletTime
++;
bulletTime
++;
}
}
}
}
...
@@ -543,15 +633,18 @@ public class GameState {
...
@@ -543,15 +633,18 @@ public class GameState {
public
void
checkTankDestroyed
(
Tank
tankToCheck
,
Bullet
bullet
)
{
public
void
checkTankDestroyed
(
Tank
tankToCheck
,
Bullet
bullet
)
{
Rectangle
rectangle
=
new
Rectangle
(
tankToCheck
.
getX
(),
tankToCheck
.
getY
(),
25
,
25
);
Rectangle
rectangle
=
new
Rectangle
(
tankToCheck
.
getX
(),
tankToCheck
.
getY
(),
25
,
25
);
Ellipse2D
ellipse2D
=
new
Ellipse2D
.
Double
(
bullet
.
x
,
bullet
.
y
,
7
,
7
);
Ellipse2D
ellipse2D
=
new
Ellipse2D
.
Double
(
bullet
.
x
,
bullet
.
y
,
7
,
7
);
if
(
ellipse2D
.
intersects
(
rectangle
))
{
if
(
ellipse2D
.
intersects
(
rectangle
)
&&
!
tankToCheck
.
bulletEffect
)
{
new
AudioPlayer
(
"sound effects/enemydestroyed.wav"
,
0
);
new
AudioPlayer
(
"sound effects/enemydestroyed.wav"
,
0
);
tankToCheck
.
setHealth
(
Controller
.
bulletDamage
);
Controller
.
tanks
.
remove
(
tankToCheck
);
//Controller.tanks.remove(tankToCheck);
tankToCheck
.
alive
=
false
;
bullet
.
alive
=
false
;
bullet
.
alive
=
false
;
rotateAmountTank
=
0
;
bulletTime
=
61
;
bulletTime
=
61
;
System
.
out
.
println
(
tankToCheck
.
getHealth
());
if
(
tankToCheck
.
getHealth
()
<=
0
)
{
tankToCheck
.
alive
=
false
;
rotateAmountTank
=
0
;
}
}
}
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment