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
a4d7d19a
Commit
a4d7d19a
authored
Aug 01, 2020
by
nargessalehi98
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update GameState.
parent
f803e3b3
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
68 additions
and
86 deletions
+68
-86
GameState.java
src/GameState.java
+68
-86
No files found.
src/GameState.java
View file @
a4d7d19a
...
@@ -32,6 +32,10 @@ public class GameState {
...
@@ -32,6 +32,10 @@ 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
;
private
int
step
=
0
;
boolean
PermissionUp
=
true
;
boolean
PermissionDown
=
true
;
boolean
check
=
true
;
public
GameState
(
int
num
)
{
public
GameState
(
int
num
)
{
...
@@ -80,114 +84,83 @@ public class GameState {
...
@@ -80,114 +84,83 @@ public class GameState {
if
(
keyUP
)
{
if
(
keyUP
)
{
move
(+
5
);
PermissionUp
=
true
;
}
if
(
keyDOWN
)
{
move
(-
5
);
}
if
(
keyLEFT
)
rotateAmount
-=
15
;
if
(
keyRIGHT
)
rotateAmount
+=
15
;
locX
=
Math
.
max
(
locX
,
40
);
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
);
}
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
)
{
if
((
getBounds
(
locX
,
locY
).
intersects
(
new
Rectangle
((
int
)
wall
.
getX
(),
(
int
)
wall
.
getY
(),
5
,
50
))))
{
if
((
getBounds
(
locX
,
locY
).
intersects
(
new
Rectangle
((
int
)
wall
.
getX
(),
(
int
)
wall
.
getY
(),
5
,
50
))))
{
return
wall
;
//&&
}
// ((rotateAmount == 0 && locX < wall.getX()) || ((rotateAmount == 180 || rotateAmount == -180) && locX > wall.getX()))
}
PermissionUp
=
false
;
break
;
}
}
return
null
;
}
}
public
Wall
horizontalWallCollision
()
{
for
(
Wall
wall
:
Controller
.
walls
)
{
if
(
wall
.
getWidth
()
==
50
&&
wall
.
getHeight
()
==
5
)
{
if
(
wall
.
getWidth
()
==
50
&&
wall
.
getHeight
()
==
5
)
{
if
((
getBounds
(
locX
,
locY
).
intersects
(
new
Rectangle
((
int
)
wall
.
getX
(),
(
int
)
wall
.
getY
(),
50
,
5
))))
{
if
((
getBounds
(
locX
,
locY
).
intersects
(
new
Rectangle
((
int
)
wall
.
getX
(),
(
int
)
wall
.
getY
(),
50
,
5
))))
{
return
wall
;
// &&
// (((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
;
}
}
return
null
;
}
}
public
boolean
isMoveAllowed
(
int
px
)
{
if
(
keyDOWN
)
{
PermissionDown
=
true
;
if
(
verticalWallCollision
()
!=
null
)
{
for
(
Wall
wall
:
Controller
.
walls
)
{
if
(
verticalWallCollision
().
getX
()
>
locX
&&
px
>
0
)
{
if
(
wall
.
getWidth
()
==
5
&&
wall
.
getHeight
()
==
50
)
{
if
((
rotateAmount
<=
90
&&
rotateAmount
>=
-
90
)
||
(
rotateAmount
<=
-
270
&&
rotateAmount
>
-
360
)
||
(
rotateAmount
>=
270
&&
rotateAmount
<
360
))
{
if
((
getBounds
(
locX
,
locY
).
intersects
(
new
Rectangle
((
int
)
wall
.
getX
(),
(
int
)
wall
.
getY
(),
5
,
50
))))
{
return
false
;
//&&
}
else
return
true
;
// ((((rotateAmount == 0) || locX >= wall.getX())) || (((rotateAmount == -180 || rotateAmount == 180) && locX <= wall.getX())))
PermissionDown
=
false
;
break
;
}
}
if
(
verticalWallCollision
().
getX
()
<
locX
&&
px
<
0
)
{
if
((
rotateAmount
<=
90
&&
rotateAmount
>=
-
90
)
||
(
rotateAmount
<=
-
270
&&
rotateAmount
>
-
360
)
||
(
rotateAmount
>=
270
&&
rotateAmount
<
360
))
{
return
false
;
}
else
return
true
;
}
}
if
(
verticalWallCollision
().
getX
()
>
locX
&&
px
<
0
)
{
if
(
wall
.
getWidth
()
==
50
&&
wall
.
getHeight
()
==
5
)
{
if
((
rotateAmount
>=
90
&&
rotateAmount
<=
270
)
||
(
rotateAmount
<=
-
90
&&
rotateAmount
>=
-
270
))
{
if
((
getBounds
(
locX
,
locY
).
intersects
(
new
Rectangle
((
int
)
wall
.
getX
(),
(
int
)
wall
.
getY
(),
50
,
5
))))
{
return
false
;
// &&
}
else
return
true
;
// (((rotateAmount == -90 || rotateAmount == 270) && locY<wall.getY()))|| (((rotateAmount==90||rotateAmount==-270)&& locY>wall.getY()))
PermissionDown
=
false
;
break
;
}
}
if
(
verticalWallCollision
().
getX
()
<
locX
&&
px
>
0
)
{
if
((
rotateAmount
>=
90
||
rotateAmount
<=
270
)
||
(
rotateAmount
<=
-
90
&&
rotateAmount
>=
-
270
))
{
return
false
;
}
else
return
true
;
}
}
}
}
if
(
horizontalWallCollision
()
!=
null
)
{
if
(
PermissionDown
)
if
(
horizontalWallCollision
().
getY
()
>
locY
&&
px
>
0
)
{
move
(-
5
);
if
((
rotateAmount
<=
180
&&
rotateAmount
>=
0
)
||
(
rotateAmount
<=
-
180
&&
rotateAmount
>
-
360
))
{
for
(
Wall
wall
:
Controller
.
walls
)
System
.
out
.
println
(
"1"
);
if
(!
PermissionUp
&&
(!(
getBounds
(
locX
,
locY
).
intersects
(
new
Rectangle
((
int
)
wall
.
getX
(),
(
int
)
wall
.
getY
(),
50
,
5
)))
||
return
false
;
!(
getBounds
(
locX
,
locY
).
intersects
(
new
Rectangle
((
int
)
wall
.
getX
(),
(
int
)
wall
.
getY
(),
5
,
50
)))))
{
}
else
return
true
;
move
(-
5
);
break
;
}
}
if
(
horizontalWallCollision
().
getY
()
<
locY
&&
px
<
0
)
{
// }
if
((
rotateAmount
<=
180
&&
rotateAmount
>=
0
)
||
(
rotateAmount
<=
-
180
&&
rotateAmount
>
-
360
))
{
System
.
out
.
println
(
"2"
);
return
false
;
}
else
return
true
;
}
}
if
(
horizontalWallCollision
().
getY
()
<
locY
&&
px
>
0
)
{
if
((
rotateAmount
>=
-
180
&&
rotateAmount
<=
0
)
||
(
rotateAmount
>=
180
&&
rotateAmount
<
360
))
{
System
.
out
.
println
(
"3"
);
return
false
;
}
else
return
true
;
}
if
(
horizontalWallCollision
().
getY
()
>
locY
&&
px
<
0
)
{
if
((
rotateAmount
>=
-
180
&&
rotateAmount
<=
0
)
||
(
rotateAmount
>=
180
&&
rotateAmount
<
360
))
{
System
.
out
.
println
(
"4"
);
return
false
;
if
(
keyLEFT
)
}
else
return
true
;
rotateAmount
-=
15
;
}
}
if
(
keyRIGHT
)
return
true
;
rotateAmount
+=
15
;
locX
=
Math
.
max
(
locX
,
40
);
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
);
}
}
public
void
move
(
int
px
)
{
public
void
move
(
int
px
)
{
double
d
;
double
d
;
if
(!
isMoveAllowed
(
px
))
px
=
0
;
if
(
rotateAmount
==
0
)
locX
+=
px
;
if
(
rotateAmount
==
0
)
locX
+=
px
;
if
(
rotateAmount
==
90
||
rotateAmount
==
-
270
)
locY
+=
px
;
if
(
rotateAmount
==
90
||
rotateAmount
==
-
270
)
locY
+=
px
;
if
(
rotateAmount
==
-
90
||
rotateAmount
==
270
)
locY
-=
px
;
if
(
rotateAmount
==
-
90
||
rotateAmount
==
270
)
locY
-=
px
;
...
@@ -241,6 +214,15 @@ public class GameState {
...
@@ -241,6 +214,15 @@ public class GameState {
}
}
public
void
checkWall
()
{
for
(
Wall
wall
:
Controller
.
walls
)
{
if
(
wall
.
getX
()
==
locX
+
5
||
wall
.
getY
()
==
locY
+
5
)
{
keyDOWN
=
false
;
}
else
if
(
wall
.
getX
()
==
locX
-
5
||
wall
.
getY
()
==
locY
-
5
)
{
keyUP
=
false
;
}
}
}
public
KeyListener
getKeyListener
()
{
public
KeyListener
getKeyListener
()
{
return
keyHandler
;
return
keyHandler
;
...
...
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