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
7362786b
Commit
7362786b
authored
4 years ago
by
nargessalehi98
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Handle exception.
parent
83fc6ec7
master
No related merge requests found
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
9 additions
and
15 deletions
+9
-15
GameLoop.java
src/GameLoop.java
+9
-15
No files found.
src/GameLoop.java
View file @
7362786b
/*** In The Name of Allah ***/
/*** In The Name of Allah ***/
import
java.awt.*
;
import
java.io.IOException
;
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.
* Note that to make this work, none of the 2 methods
* Note that to make this work, none of the 2 methods
* in the while loop (update() and render()) should be
* in the while loop (update() and render()) should be
* long running! Both must execute very quickly, without
* long running! Both must execute very quickly, without
* any waiting and blocking!
* any waiting and blocking!
*
*
<p>
* Detailed discussion on different game loop design
* Detailed discussion on different game loop design
* patterns is available in the following link:
* patterns is available in the following link:
*
http://gameprogrammingpatterns.com/game-loop.html
* http://gameprogrammingpatterns.com/game-loop.html
*
*
* @author Seyed Mohammad Ghaffarian
* @author Seyed Mohammad Ghaffarian
*/
*/
...
@@ -33,6 +31,7 @@ public class GameLoop implements Runnable {
...
@@ -33,6 +31,7 @@ public class GameLoop implements Runnable {
//private GameState state2;
//private GameState state2;
//private GameState pcState;
//private GameState pcState;
public
GameLoop
(
GameFrame
frame
)
{
public
GameLoop
(
GameFrame
frame
)
{
canvas
=
frame
;
canvas
=
frame
;
}
}
...
@@ -59,7 +58,7 @@ public class GameLoop implements Runnable {
...
@@ -59,7 +58,7 @@ public class GameLoop implements Runnable {
@Override
@Override
public
void
run
()
{
public
void
run
()
{
boolean
gameOver
=
false
;
boolean
gameOver
=
false
;
while
(!
gameOver
)
{
while
(!
gameOver
)
{
try
{
try
{
long
start
=
System
.
currentTimeMillis
();
long
start
=
System
.
currentTimeMillis
();
//
//
...
@@ -75,14 +74,9 @@ public class GameLoop implements Runnable {
...
@@ -75,14 +74,9 @@ public class GameLoop implements Runnable {
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
(
Exception
ee
)
{
}
catch
(
InterruptedException
ex
)
{
ee
.
printStackTrace
();
}
}
}
}
try
{
canvas
.
render
(
state
);
canvas
.
render
(
state
);
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
}
}
}
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