diff --git a/.classpath b/.classpath new file mode 100644 index 0000000..9e43972 --- /dev/null +++ b/.classpath @@ -0,0 +1,9 @@ + + + + + + + + + diff --git a/.project b/.project new file mode 100644 index 0000000..24223ce --- /dev/null +++ b/.project @@ -0,0 +1,17 @@ + + + EI + + + + + + org.eclipse.jdt.core.javabuilder + + + + + + org.eclipse.jdt.core.javanature + + diff --git a/lib/jinput.jar b/lib/jinput.jar new file mode 100644 index 0000000..0b5a158 Binary files /dev/null and b/lib/jinput.jar differ diff --git a/lib/lwjgl.jar b/lib/lwjgl.jar new file mode 100644 index 0000000..190f9c1 Binary files /dev/null and b/lib/lwjgl.jar differ diff --git a/lib/lwjgl_util.jar b/lib/lwjgl_util.jar new file mode 100644 index 0000000..423c994 Binary files /dev/null and b/lib/lwjgl_util.jar differ diff --git a/lib/native/linux/libjinput-linux.so b/lib/native/linux/libjinput-linux.so new file mode 100644 index 0000000..e4a983f Binary files /dev/null and b/lib/native/linux/libjinput-linux.so differ diff --git a/lib/native/linux/liblwjgl.so b/lib/native/linux/liblwjgl.so new file mode 100644 index 0000000..89a6935 Binary files /dev/null and b/lib/native/linux/liblwjgl.so differ diff --git a/lib/native/linux/liblwjgl64.so b/lib/native/linux/liblwjgl64.so new file mode 100644 index 0000000..26fe623 Binary files /dev/null and b/lib/native/linux/liblwjgl64.so differ diff --git a/lib/native/linux/libopenal.so b/lib/native/linux/libopenal.so new file mode 100644 index 0000000..31d24ed Binary files /dev/null and b/lib/native/linux/libopenal.so differ diff --git a/lib/native/macosx/libjinput-osx.jnilib b/lib/native/macosx/libjinput-osx.jnilib new file mode 100644 index 0000000..58eea1f Binary files /dev/null and b/lib/native/macosx/libjinput-osx.jnilib differ diff --git a/lib/native/macosx/liblwjgl.jnilib b/lib/native/macosx/liblwjgl.jnilib new file mode 100644 index 0000000..0df1c8f Binary files /dev/null and b/lib/native/macosx/liblwjgl.jnilib differ diff --git a/lib/native/macosx/openal.dylib b/lib/native/macosx/openal.dylib new file mode 100644 index 0000000..cb8e458 Binary files /dev/null and b/lib/native/macosx/openal.dylib differ diff --git a/lib/native/win32/OpenAL32.dll b/lib/native/win32/OpenAL32.dll new file mode 100644 index 0000000..3fe0d89 Binary files /dev/null and b/lib/native/win32/OpenAL32.dll differ diff --git a/lib/native/win32/jinput-dx8.dll b/lib/native/win32/jinput-dx8.dll new file mode 100644 index 0000000..038401b Binary files /dev/null and b/lib/native/win32/jinput-dx8.dll differ diff --git a/lib/native/win32/jinput-raw.dll b/lib/native/win32/jinput-raw.dll new file mode 100644 index 0000000..043783a Binary files /dev/null and b/lib/native/win32/jinput-raw.dll differ diff --git a/lib/native/win32/lwjgl.dll b/lib/native/win32/lwjgl.dll new file mode 100644 index 0000000..84b9a97 Binary files /dev/null and b/lib/native/win32/lwjgl.dll differ diff --git a/lwjgl.dll b/lwjgl.dll new file mode 100644 index 0000000..84b9a97 Binary files /dev/null and b/lwjgl.dll differ diff --git a/raw/media/units/ei_tank.max b/raw/media/units/ei_tank.max new file mode 100644 index 0000000..07295f7 Binary files /dev/null and b/raw/media/units/ei_tank.max differ diff --git a/raw/media/units/tank.png b/raw/media/units/tank.png new file mode 100644 index 0000000..01b5a93 Binary files /dev/null and b/raw/media/units/tank.png differ diff --git a/src/ei/engine/LWJGLGameWindow.java b/src/ei/engine/LWJGLGameWindow.java new file mode 100644 index 0000000..a31af86 --- /dev/null +++ b/src/ei/engine/LWJGLGameWindow.java @@ -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(){ + + } + +} diff --git a/src/ei/engine/state/GameState.java b/src/ei/engine/state/GameState.java new file mode 100644 index 0000000..7ae8f1a --- /dev/null +++ b/src/ei/engine/state/GameState.java @@ -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(); +} diff --git a/src/ei/engine/state/GameStateManager.java b/src/ei/engine/state/GameStateManager.java new file mode 100644 index 0000000..73b5de8 --- /dev/null +++ b/src/ei/engine/state/GameStateManager.java @@ -0,0 +1,131 @@ +package ei.engine.state; + +import java.util.ArrayList; + +public class GameStateManager { + private static GameStateManager instance; + private ArrayList gameStates; + + private GameStateManager(){ + gameStates = new ArrayList(); + } + + /** + * 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