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
a1f26f07
Commit
a1f26f07
authored
Jul 30, 2020
by
nargessalehi98
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix keyUp and keyDown.
parent
230e2705
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
17 deletions
+29
-17
GameState.java
src/GameState.java
+29
-17
No files found.
src/GameState.java
View file @
a1f26f07
...
@@ -32,9 +32,10 @@ public class GameState {
...
@@ -32,9 +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
;
private
int
step
=
0
;
boolean
PermissionUp
=
true
;
boolean
PermissionUp
=
true
;
boolean
PermissionDown
=
true
;
boolean
PermissionDown
=
true
;
boolean
check
=
true
;
public
GameState
(
int
num
)
{
public
GameState
(
int
num
)
{
...
@@ -80,23 +81,23 @@ public class GameState {
...
@@ -80,23 +81,23 @@ public class GameState {
locY
=
mouseY
-
diam
/
2
;
locY
=
mouseY
-
diam
/
2
;
locX
=
mouseX
-
diam
/
2
;
locX
=
mouseX
-
diam
/
2
;
}
}
//
// if(step<2)
// step=0;
if
(
keyUP
)
{
if
(
keyUP
)
{
PermissionUp
=
true
;
PermissionUp
=
true
;
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
))))
{
//&&
// ((rotateAmount == 0 && locX < wall.getX()) || ((rotateAmount == 180 || rotateAmount == -180) && locX > wall.getX()))
PermissionUp
=
false
;
PermissionUp
=
false
;
//System.out.println(wall.getHeight());
break
;
break
;
}
}
}
}
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
))))
{
//System.out.println(wall.getHeight());
// &&
// (((rotateAmount == +90 || rotateAmount == -270) && locY < wall.getY()) || (((rotateAmount == -90 || rotateAmount == -270) && locY > wall.getY())))
PermissionUp
=
false
;
PermissionUp
=
false
;
break
;
break
;
}
}
...
@@ -104,22 +105,29 @@ public class GameState {
...
@@ -104,22 +105,29 @@ public class GameState {
}
}
if
(
PermissionUp
)
if
(
PermissionUp
)
move
(+
5
);
move
(+
5
);
if
(!
PermissionDown
){
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
);
move
(+
5
);
break
;
}
}
}
}
if
(
keyDOWN
)
{
if
(
keyDOWN
)
{
PermissionDown
=
true
;
PermissionDown
=
true
;
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
))))
{
//&&
// ((((rotateAmount == 0) || locX >= wall.getX())) || (((rotateAmount == -180 || rotateAmount == 180) && locX <= wall.getX())))
PermissionDown
=
false
;
PermissionDown
=
false
;
break
;
break
;
}
}
}
}
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
))))
{
// &&
// (((rotateAmount == -90 || rotateAmount == 270) && locY<wall.getY()))|| (((rotateAmount==90||rotateAmount==-270)&& locY>wall.getY()))
PermissionDown
=
false
;
PermissionDown
=
false
;
break
;
break
;
}
}
...
@@ -127,9 +135,13 @@ public class GameState {
...
@@ -127,9 +135,13 @@ public class GameState {
}
}
if
(
PermissionDown
)
if
(
PermissionDown
)
move
(-
5
);
move
(-
5
);
if
(!
PermissionUp
)
{
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
);
move
(-
5
);
break
;
}
}
// }
}
}
...
@@ -143,7 +155,7 @@ public class GameState {
...
@@ -143,7 +155,7 @@ public class GameState {
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
);
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
)
{
...
...
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