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
4522d483
Commit
4522d483
authored
4 years ago
by
9831111
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add bulletCollision method to find collision with walls.
parent
3aa528a8
No related merge requests found
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
30 additions
and
0 deletions
+30
-0
GameState.java
src/GameState.java
+30
-0
No files found.
src/GameState.java
View file @
4522d483
...
@@ -11,6 +11,7 @@ import java.awt.event.MouseEvent;
...
@@ -11,6 +11,7 @@ import java.awt.event.MouseEvent;
import
java.awt.event.MouseListener
;
import
java.awt.event.MouseListener
;
import
java.awt.event.MouseMotionListener
;
import
java.awt.event.MouseMotionListener
;
import
java.awt.geom.AffineTransform
;
import
java.awt.geom.AffineTransform
;
import
java.awt.geom.Ellipse2D
;
import
java.awt.image.BufferedImage
;
import
java.awt.image.BufferedImage
;
/**
/**
...
@@ -366,6 +367,35 @@ public class GameState {
...
@@ -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
;
}
}
}
}
}
...
...
This diff is collapsed.
Click to expand it.
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