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
729912de
Commit
729912de
authored
Jul 25, 2020
by
nargessalehi98
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Set GameLoop for multiple player.
parent
29652f44
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
4 deletions
+24
-4
GameLoop.java
src/GameLoop.java
+24
-4
No files found.
src/GameLoop.java
View file @
729912de
/*** In The Name of Allah ***/
/*** In The Name of Allah ***/
import
java.io.IOException
;
import
java.util.PrimitiveIterator
;
/**
/**
* A very simple structure for the main game loop.
* A very simple structure for the main game loop.
* THIS IS NOT PERFECT, but works for most situations.
* THIS IS NOT PERFECT, but works for most situations.
...
@@ -24,6 +27,8 @@ public class GameLoop implements Runnable {
...
@@ -24,6 +27,8 @@ public class GameLoop implements Runnable {
private
GameFrame
canvas
;
private
GameFrame
canvas
;
private
GameState
state
;
private
GameState
state
;
private
GameState
state1
;
private
GameState
state2
;
public
GameLoop
(
GameFrame
frame
)
{
public
GameLoop
(
GameFrame
frame
)
{
canvas
=
frame
;
canvas
=
frame
;
...
@@ -33,10 +38,18 @@ public class GameLoop implements Runnable {
...
@@ -33,10 +38,18 @@ public class GameLoop implements Runnable {
* This must be called before the game loop starts.
* This must be called before the game loop starts.
*/
*/
public
void
init
()
{
public
void
init
()
{
state
=
new
GameState
();
state
=
new
GameState
(
1
);
state1
=
new
GameState
(
2
);
state2
=
new
GameState
(
3
);
canvas
.
addKeyListener
(
state
.
getKeyListener
());
canvas
.
addKeyListener
(
state
.
getKeyListener
());
canvas
.
addMouseListener
(
state
.
getMouseListener
());
canvas
.
addMouseListener
(
state
.
getMouseListener
());
canvas
.
addMouseMotionListener
(
state
.
getMouseMotionListener
());
canvas
.
addMouseMotionListener
(
state
.
getMouseMotionListener
());
canvas
.
addKeyListener
(
state1
.
getKeyListener
());
canvas
.
addMouseListener
(
state1
.
getMouseListener
());
canvas
.
addMouseMotionListener
(
state1
.
getMouseMotionListener
());
canvas
.
addKeyListener
(
state2
.
getKeyListener
());
canvas
.
addMouseListener
(
state2
.
getMouseListener
());
canvas
.
addMouseMotionListener
(
state2
.
getMouseMotionListener
());
}
}
@Override
@Override
...
@@ -47,15 +60,22 @@ public class GameLoop implements Runnable {
...
@@ -47,15 +60,22 @@ public class GameLoop implements Runnable {
long
start
=
System
.
currentTimeMillis
();
long
start
=
System
.
currentTimeMillis
();
//
//
state
.
update
();
state
.
update
();
canvas
.
render
(
state
);
state1
.
update
();
state2
.
update
();
canvas
.
render
(
state
,
state2
,
state1
);
gameOver
=
state
.
gameOver
;
gameOver
=
state
.
gameOver
;
//
//
long
delay
=
(
1000
/
FPS
)
-
(
System
.
currentTimeMillis
()
-
start
);
long
delay
=
(
1000
/
FPS
)
-
(
System
.
currentTimeMillis
()
-
start
);
if
(
delay
>
0
)
if
(
delay
>
0
)
Thread
.
sleep
(
delay
);
Thread
.
sleep
(
delay
);
}
catch
(
InterruptedException
ex
)
{
}
catch
(
InterruptedException
|
IOException
ex
)
{
}
}
}
}
canvas
.
render
(
state
);
try
{
canvas
.
render
(
state
,
state1
,
state2
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
}
}
}
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