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
1f112716
Commit
1f112716
authored
4 years ago
by
nargessalehi98
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add new Condition for tank movement limit.
parent
e4255210
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
45 additions
and
17 deletions
+45
-17
GameState.java
src/GameState.java
+45
-17
No files found.
src/GameState.java
View file @
1f112716
...
@@ -32,12 +32,15 @@ public class GameState {
...
@@ -32,12 +32,15 @@ public class GameState {
private
boolean
one
=
false
;
private
boolean
one
=
false
;
private
boolean
two
=
false
;
private
boolean
two
=
false
;
private
boolean
three
=
false
;
private
boolean
three
=
false
;
boolean
PermissionDown
=
true
;
boolean
PermissionUp
=
true
;
public
GameState
(
int
num
)
{
public
GameState
(
int
num
)
{
locX
=
100
;
locX
=
100
;
locY
=
100
;
locY
=
100
;
diam
=
42
;
//changed from 42 to 25
diam
=
25
;
rotateAmount
=
0
;
rotateAmount
=
0
;
gameOver
=
false
;
gameOver
=
false
;
//
//
...
@@ -65,7 +68,7 @@ public class GameState {
...
@@ -65,7 +68,7 @@ public class GameState {
public
Rectangle
getBounds
(
int
locX
,
int
locY
)
{
public
Rectangle
getBounds
(
int
locX
,
int
locY
)
{
return
new
Rectangle
(
locX
,
locY
,
2
5
,
25
);
return
new
Rectangle
(
locX
,
locY
,
2
8
,
28
);
}
}
/**
/**
...
@@ -78,44 +81,69 @@ public class GameState {
...
@@ -78,44 +81,69 @@ public class GameState {
locX
=
mouseX
-
diam
/
2
;
locX
=
mouseX
-
diam
/
2
;
}
}
if
(
keyUP
)
{
if
(
keyUP
)
{
boolean
Permission
=
true
;
PermissionUp
=
true
;
for
(
Wall
wall
:
Controller
.
walls
)
{
for
(
Wall
wall
:
Controller
.
walls
)
{
if
(
wall
.
intersects
(
getBounds
(
locX
+
5
,
locY
+
5
)))
{
System
.
out
.
println
(
"4"
);
if
(
wall
.
getWidth
()
==
5
&&
wall
.
getHeight
()
==
50
)
{
Permission
=
false
;
if
((
getBounds
(
locX
,
locY
).
intersects
(
new
Rectangle
((
int
)
wall
.
getX
(),
(
int
)
wall
.
getY
(),
5
,
50
))))
{
PermissionUp
=
false
;
break
;
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
);
move
(+
5
);
}
}
if
(
keyDOWN
)
{
if
(
keyDOWN
)
{
boolean
Permissio
n
=
true
;
PermissionDow
n
=
true
;
for
(
Wall
wall
:
Controller
.
walls
)
{
for
(
Wall
wall
:
Controller
.
walls
)
{
if
(
wall
.
intersects
(
getBounds
(
locX
+
5
,
locY
+
5
)
))
{
if
(
wall
.
getWidth
()
==
5
&&
(
wall
.
getHeight
()
==
50
||
wall
.
getHeight
()
==
5
))
{
System
.
out
.
println
(
"5"
);
if
((
getBounds
(
locX
,
locY
).
intersects
(
new
Rectangle
((
int
)
wall
.
getX
(),
(
int
)
wall
.
getY
(),
5
,
50
))))
{
Permissio
n
=
false
;
PermissionDow
n
=
false
;
break
;
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
);
move
(-
5
);
}
}
if
(
keyLEFT
)
if
(
keyLEFT
)
{
rotateAmount
-=
15
;
rotateAmount
-=
15
;
}
if
(
keyRIGHT
)
if
(
keyRIGHT
)
{
rotateAmount
+=
15
;
rotateAmount
+=
15
;
}
locX
=
Math
.
max
(
locX
,
40
);
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
.
min
(
locX
,
20
+
(((
Controller
.
col
-
1
)
/
2
)
*
50
)
+
(((
Controller
.
col
-
1
)
/
2
)
+
1
)
*
5
-
25
);
locY
=
Math
.
max
(
locY
,
70
);
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
)
{
public
void
move
(
int
px
)
{
...
...
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