1 /***************************************************************************
2 * Copyright (C) 2010 by the Alterverse team *
3 * email: rynkruger@gmail.com *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 3 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, see: *
17 * <http://www.gnu.org/licenses/>. *
18 ***************************************************************************/
20 package org
.alterverse
.game
;
22 import org
.lwjgl
.input
.Keyboard
;
23 import org
.lwjgl
.opengl
.Display
;
24 import org
.alterverse
.control
.*;
25 import org
.alterverse
.speech
.*;
27 public class GameEngine
{
33 int [] defaultKeys
= {Keyboard
.CHAR_NONE
,
46 Keyboard
.KEY_APOSTROPHE
,
52 Keyboard
.KEY_BACKSLASH
,
55 Keyboard
.KEY_CIRCUMFLEX
,
95 Keyboard
.KEY_LBRACKET
,
96 Keyboard
.KEY_LCONTROL
,
103 Keyboard
.KEY_MULTIPLY
,
106 Keyboard
.KEY_NOCONVERT
,
108 Keyboard
.KEY_NUMLOCK
,
109 Keyboard
.KEY_NUMPAD0
,
110 Keyboard
.KEY_NUMPAD1
,
111 Keyboard
.KEY_NUMPAD2
,
112 Keyboard
.KEY_NUMPAD3
,
113 Keyboard
.KEY_NUMPAD4
,
114 Keyboard
.KEY_NUMPAD5
,
115 Keyboard
.KEY_NUMPAD6
,
116 Keyboard
.KEY_NUMPAD7
,
117 Keyboard
.KEY_NUMPAD8
,
118 Keyboard
.KEY_NUMPAD9
,
119 Keyboard
.KEY_NUMPADCOMMA
,
120 Keyboard
.KEY_NUMPADENTER
,
121 Keyboard
.KEY_NUMPADEQUALS
,
130 Keyboard
.KEY_RBRACKET
,
131 Keyboard
.KEY_RCONTROL
,
139 Keyboard
.KEY_SEMICOLON
,
144 Keyboard
.KEY_SUBTRACT
,
149 Keyboard
.KEY_UNDERLINE
,
150 Keyboard
.KEY_UNLABELED
,
159 public GameEngine(GameContext gc
) {
162 public GameEngine(GameContext context
, int fps
) {
166 tts
=SpeechSystem
.getEngine();
170 Display
.setFullscreen(true);
172 } catch(Exception x
) {
175 kh
= new KeyboardHandler(defaultKeys
, gc
);
176 // int [] lk = {Keyboard.KEY_LEFT, Keyboard.KEY_RIGHT,Keyboard.KEY_SPACE};
177 // kh=new KeyboardHandler(lk,gc);
178 System
.out
.println(kh
.getKeyboardListener());
182 // The main loop is here
184 while (!Display
.isCloseRequested()&&running
) {
185 long cycleTime
= System
.currentTimeMillis();
190 int remaning
= (int)cycleTime
+1000/fps
-(int)System
.currentTimeMillis();
192 Thread
.sleep(Math
.max(remaning
,5));
193 Display
.processMessages();
194 } catch(Exception x
) {
204 } catch(Exception x
) {
205 // nothing will really help now
209 public void setContext(GameContext context
) {
214 public GameContext
getContext() {