Initial import.
This commit is contained in:
parent
5f299890cb
commit
330607c72b
23 changed files with 338 additions and 0 deletions
9
.classpath
Normal file
9
.classpath
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
|
||||
<classpathentry kind="lib" path="lib/lwjgl.jar"/>
|
||||
<classpathentry kind="lib" path="lib/jinput.jar"/>
|
||||
<classpathentry kind="lib" path="lib/lwjgl_util.jar"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
||||
17
.project
Normal file
17
.project
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>EI</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
BIN
lib/jinput.jar
Normal file
BIN
lib/jinput.jar
Normal file
Binary file not shown.
BIN
lib/lwjgl.jar
Normal file
BIN
lib/lwjgl.jar
Normal file
Binary file not shown.
BIN
lib/lwjgl_util.jar
Normal file
BIN
lib/lwjgl_util.jar
Normal file
Binary file not shown.
BIN
lib/native/linux/libjinput-linux.so
Normal file
BIN
lib/native/linux/libjinput-linux.so
Normal file
Binary file not shown.
BIN
lib/native/linux/liblwjgl.so
Normal file
BIN
lib/native/linux/liblwjgl.so
Normal file
Binary file not shown.
BIN
lib/native/linux/liblwjgl64.so
Normal file
BIN
lib/native/linux/liblwjgl64.so
Normal file
Binary file not shown.
BIN
lib/native/linux/libopenal.so
Normal file
BIN
lib/native/linux/libopenal.so
Normal file
Binary file not shown.
BIN
lib/native/macosx/libjinput-osx.jnilib
Normal file
BIN
lib/native/macosx/libjinput-osx.jnilib
Normal file
Binary file not shown.
BIN
lib/native/macosx/liblwjgl.jnilib
Normal file
BIN
lib/native/macosx/liblwjgl.jnilib
Normal file
Binary file not shown.
BIN
lib/native/macosx/openal.dylib
Normal file
BIN
lib/native/macosx/openal.dylib
Normal file
Binary file not shown.
BIN
lib/native/win32/OpenAL32.dll
Normal file
BIN
lib/native/win32/OpenAL32.dll
Normal file
Binary file not shown.
BIN
lib/native/win32/jinput-dx8.dll
Normal file
BIN
lib/native/win32/jinput-dx8.dll
Normal file
Binary file not shown.
BIN
lib/native/win32/jinput-raw.dll
Normal file
BIN
lib/native/win32/jinput-raw.dll
Normal file
Binary file not shown.
BIN
lib/native/win32/lwjgl.dll
Normal file
BIN
lib/native/win32/lwjgl.dll
Normal file
Binary file not shown.
BIN
lwjgl.dll
Normal file
BIN
lwjgl.dll
Normal file
Binary file not shown.
BIN
raw/media/units/ei_tank.max
Normal file
BIN
raw/media/units/ei_tank.max
Normal file
Binary file not shown.
BIN
raw/media/units/tank.png
Normal file
BIN
raw/media/units/tank.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 217 KiB |
144
src/ei/engine/LWJGLGameWindow.java
Normal file
144
src/ei/engine/LWJGLGameWindow.java
Normal file
|
|
@ -0,0 +1,144 @@
|
|||
package ei.engine;
|
||||
|
||||
import org.lwjgl.Sys;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
import org.lwjgl.input.Mouse;
|
||||
import org.lwjgl.opengl.Display;
|
||||
import org.lwjgl.opengl.DisplayMode;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
public class LWJGLGameWindow {
|
||||
private boolean exit = false;
|
||||
private int width;
|
||||
private int height;
|
||||
private int fps;
|
||||
private boolean fullscreen;
|
||||
private String title;
|
||||
|
||||
public LWJGLGameWindow(String title){
|
||||
this(800, 600, 60, false, title);
|
||||
}
|
||||
|
||||
public LWJGLGameWindow(int width, int height, int fps, boolean fullscreen, String title){
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.fps = fps;
|
||||
this.fullscreen = fullscreen;
|
||||
this.title = title;
|
||||
|
||||
try {
|
||||
initDisplay();
|
||||
run();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace(System.err);
|
||||
Sys.alert(title, "An error occured and the game will exit.");
|
||||
} finally {
|
||||
cleanup();
|
||||
}
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Initialise the game
|
||||
* @throws Exception if init fails
|
||||
*/
|
||||
private void initDisplay() throws Exception {
|
||||
DisplayMode dm = new DisplayMode(width, height);
|
||||
Display.setDisplayMode(dm);
|
||||
|
||||
Display.setTitle(title);
|
||||
Display.setFullscreen(fullscreen);
|
||||
|
||||
// grab the mouse, dont want that hideous cursor when we're playing!
|
||||
Mouse.setGrabbed(true);
|
||||
|
||||
// enable textures since we're going to use these for our sprites
|
||||
GL11.glEnable(GL11.GL_TEXTURE_2D);
|
||||
|
||||
// disable the OpenGL depth test since we're rendering 2D graphics
|
||||
GL11.glDisable(GL11.GL_DEPTH_TEST);
|
||||
GL11.glMatrixMode(GL11.GL_PROJECTION);
|
||||
GL11.glLoadIdentity();
|
||||
|
||||
// Enable vsync if we can (due to how OpenGL works, it cannot be guarenteed to always work)
|
||||
Display.setVSyncEnabled(true);
|
||||
|
||||
// Create the display window
|
||||
Display.create();
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs the game (the "main loop")
|
||||
*/
|
||||
private void run() {
|
||||
while (!exit) {
|
||||
// Always call Window.update(), all the time - it does some behind the
|
||||
// scenes work, and also displays the rendered output
|
||||
Display.update();
|
||||
|
||||
// Check for close requests
|
||||
if (Display.isCloseRequested()) {
|
||||
exit = true;
|
||||
}
|
||||
|
||||
// The window is in the foreground, so we should play the game
|
||||
else if (Display.isActive()) {
|
||||
update();
|
||||
mainRender();
|
||||
Display.sync(fps);
|
||||
}
|
||||
|
||||
// The window is not in the foreground, so we can allow other stuff to run and
|
||||
// infrequently update
|
||||
else {
|
||||
try {
|
||||
Thread.sleep(100);
|
||||
} catch (InterruptedException e) {}
|
||||
update();
|
||||
|
||||
// Only bother rendering if the window is visible or dirty
|
||||
if (Display.isVisible() || Display.isDirty()) {
|
||||
mainRender();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Do any game-specific cleanup
|
||||
*/
|
||||
protected void cleanup() {
|
||||
// Close the window
|
||||
Display.destroy();
|
||||
}
|
||||
|
||||
/**
|
||||
* Do all calculations, handle input, etc.
|
||||
*/
|
||||
protected void update() {
|
||||
// Example input handler: we'll check for the ESC key and finish the game instantly when it's pressed
|
||||
if (Keyboard.isKeyDown(Keyboard.KEY_ESCAPE)) {
|
||||
exit = true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the current frame
|
||||
*/
|
||||
private void mainRender() {
|
||||
// clear the screen
|
||||
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);
|
||||
GL11.glMatrixMode(GL11.GL_MODELVIEW);
|
||||
GL11.glLoadIdentity();
|
||||
|
||||
render();
|
||||
|
||||
Display.update();
|
||||
}
|
||||
|
||||
protected void render(){
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
32
src/ei/engine/state/GameState.java
Normal file
32
src/ei/engine/state/GameState.java
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
package ei.engine.state;
|
||||
|
||||
abstract class GameState {
|
||||
private String name;
|
||||
private boolean enabled = false;
|
||||
|
||||
/**
|
||||
* set if this State is enabled
|
||||
* @param b
|
||||
*/
|
||||
public void setEnabled(boolean b){
|
||||
enabled = b;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the status of the GameState
|
||||
*/
|
||||
public boolean isEnabled(){
|
||||
return enabled;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the name of the GameState
|
||||
*/
|
||||
public String getName(){
|
||||
return name;
|
||||
}
|
||||
|
||||
abstract void update();
|
||||
|
||||
abstract void render();
|
||||
}
|
||||
131
src/ei/engine/state/GameStateManager.java
Normal file
131
src/ei/engine/state/GameStateManager.java
Normal file
|
|
@ -0,0 +1,131 @@
|
|||
package ei.engine.state;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
public class GameStateManager {
|
||||
private static GameStateManager instance;
|
||||
private ArrayList<GameState> gameStates;
|
||||
|
||||
private GameStateManager(){
|
||||
gameStates = new ArrayList<GameState>();
|
||||
}
|
||||
|
||||
/**
|
||||
* Add A GameState to the GameStateManager
|
||||
* @param g The GameState to add
|
||||
* @return true if successful else false
|
||||
*/
|
||||
public boolean addState(GameState g){
|
||||
if(!gameStates.contains(g)){
|
||||
gameStates.add(g);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a GameState from the GameStateManager
|
||||
* @param g The state to remove
|
||||
* @return true if successful else false
|
||||
*/
|
||||
public boolean removeState(GameState g){
|
||||
if(gameStates.contains(g)){
|
||||
gameStates.remove(g);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes a GameState by its name
|
||||
* @param name the name of the GameState to remove
|
||||
* @return true if successful else false
|
||||
*/
|
||||
public boolean removeStateByName(String name){
|
||||
int i = getId(name);
|
||||
if(i >= 0){
|
||||
gameStates.remove(i);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the GameState in GameStateManager whit the given name
|
||||
* @param name the name of the GameState
|
||||
* @return the GameState by the name else null
|
||||
*/
|
||||
public GameState getState(String name){
|
||||
int i = getId(name);
|
||||
if(i >= 0){
|
||||
gameStates.get(i);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Activates a GameState by the name
|
||||
* @param name the name of the GameState
|
||||
* @return true if successful else false
|
||||
*/
|
||||
public boolean setActive(String name){
|
||||
GameState g = getState(name);
|
||||
if(g != null){
|
||||
g.setEnabled(true);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deactivates a GameState by the name
|
||||
* @param name the name of the GameState
|
||||
* @return true if successful else false
|
||||
*/
|
||||
public boolean setDeActive(String name){
|
||||
GameState g = getState(name);
|
||||
if(g != null){
|
||||
g.setEnabled(false);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private int getId(String name){
|
||||
for(int i=0; i<gameStates.size() ;i++){
|
||||
if(gameStates.get(i).getName().equals(name)){
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* updates all the active GameStates
|
||||
*/
|
||||
public void update(){
|
||||
for(int i=0; i<gameStates.size() ;i++){
|
||||
if(gameStates.get(i).isEnabled()){
|
||||
gameStates.get(i).update();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* renders all the active GameStates
|
||||
*/
|
||||
public void render(){
|
||||
for(int i=0; i<gameStates.size() ;i++){
|
||||
if(gameStates.get(i).isEnabled()){
|
||||
gameStates.get(i).render();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static GameStateManager getInstance(){
|
||||
if(instance == null){
|
||||
instance = new GameStateManager();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
}
|
||||
5
src/ei/game/EI.java
Normal file
5
src/ei/game/EI.java
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
package ei.game;
|
||||
|
||||
public class EI {
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue