1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83
|
package gameplay;
import java.awt.DisplayMode;
import java.awt.Graphics2D;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import utils.ScreenManager;
public class Game implements KeyListener {
private static final DisplayMode POSSIBLE_MODES[] = {
new DisplayMode(1680, 1050, 32, 0), new DisplayMode(1680, 1050, 24, 0),
new DisplayMode(800, 600, 32, 0), new DisplayMode(800, 600, 24, 0),
new DisplayMode(800, 600, 16, 0), new DisplayMode(640, 480, 32, 0),
new DisplayMode(640, 480, 24, 0), new DisplayMode(640, 480, 16, 0)
};
private ScreenManager _Screen;
public static void main(String args[]) {
Game game = new Game();
game.run();
}
public void run() {
_Screen = new ScreenManager();
try {
DisplayMode displayMode = _Screen.findFirstCompatibleMode(POSSIBLE_MODES);
_Screen.setFullScreen(displayMode);
Loop();
} finally {
_Screen.restoreScreen();
}
}
public void Loop() {
long startTime = System.currentTimeMillis();
long currTime = startTime;
while(true) {
long elapsedTime = System.currentTimeMillis() - currTime;
currTime += elapsedTime;
// update game
Update(elapsedTime);
ObjectManager.getInstance().Update(elapsedTime);
// draw and update the screen
Graphics2D g = _Screen.getGraphics();
ObjectManager.getInstance().Draw(g);
g.dispose();
_Screen.Update();
// take a nap
try {
Thread.sleep(20);
} catch (InterruptedException ex) {
}
}
}
public void Update(long elapsedTime) {
}
@Override
public void keyPressed(KeyEvent e) {
// TODO Auto-generated method stub
}
@Override
public void keyReleased(KeyEvent e) {
// TODO Auto-generated method stub
}
@Override
public void keyTyped(KeyEvent e) {
// TODO Auto-generated method stub
}
} |
Partager