diff --git a/src/data/cursor.png b/src/data/cursor.png new file mode 100644 index 0000000..e528dea Binary files /dev/null and b/src/data/cursor.png differ diff --git a/src/data/enemy.png b/src/data/enemy.png new file mode 100644 index 0000000..b08e1f7 Binary files /dev/null and b/src/data/enemy.png differ diff --git a/src/data/loadbar.png b/src/data/loadbar.png new file mode 100644 index 0000000..076f8bb Binary files /dev/null and b/src/data/loadbar.png differ diff --git a/src/data/loadbar_back.png b/src/data/loadbar_back.png new file mode 100644 index 0000000..4672810 Binary files /dev/null and b/src/data/loadbar_back.png differ diff --git a/src/data/loadbar_front.png b/src/data/loadbar_front.png new file mode 100644 index 0000000..9a3f809 Binary files /dev/null and b/src/data/loadbar_front.png differ diff --git a/src/data/map/sand.jpg b/src/data/map/sand.jpg new file mode 100644 index 0000000..ed8a6d8 Binary files /dev/null and b/src/data/map/sand.jpg differ diff --git a/src/ei/engine/LWJGLGameWindow.java b/src/ei/engine/LWJGLGameWindow.java index d2c846a..d308c3e 100644 --- a/src/ei/engine/LWJGLGameWindow.java +++ b/src/ei/engine/LWJGLGameWindow.java @@ -86,13 +86,18 @@ public class LWJGLGameWindow { // Create the display window Display.create(); - + // enable textures since we're going to use these for our sprites GL11.glEnable(GL11.GL_TEXTURE_2D); + GL11.glShadeModel(GL11.GL_SMOOTH); + // disable the OpenGL depth test since we're rendering 2D graphics + GL11.glDisable(GL11.GL_DEPTH_TEST); + // disable lights (we do not nead them) + GL11.glDisable(GL11.GL_LIGHTING); // Enable Smooth Shading GL11.glShadeModel(GL11.GL_SMOOTH); // Black Background - GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.5f); + GL11.glClearColor(0.0f, 0.0f, 0.0f, 0.0f); // Depth Buffer Setup GL11.glClearDepth(1.0f); @@ -105,18 +110,16 @@ public class LWJGLGameWindow { // Select The Modelview Matrix (controls model orientation) GL11.glMatrixMode(GL11.GL_MODELVIEW); - GL11.glLoadIdentity(); - // disable the OpenGL depth test since we're rendering 2D graphics - GL11.glDisable(GL11.GL_DEPTH_TEST); + //Enable Blending GL11.glEnable(GL11.GL_BLEND); - //Type Of Blending To Perform - GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE); + GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA); // Enable vsync if we can (due to how OpenGL works, it cannot be guarenteed to always work) Display.setVSyncEnabled(true); + // The last steps timer = new FpsTimer(); diff --git a/src/ei/engine/effects/Particles.java b/src/ei/engine/effects/Particles.java index c8bfe00..316e7f2 100644 --- a/src/ei/engine/effects/Particles.java +++ b/src/ei/engine/effects/Particles.java @@ -8,6 +8,8 @@ package ei.engine.effects; * Visit Our Sites At www.tiptup.com and nehe.gamedev.net */ +import java.awt.Rectangle; + import org.lwjgl.opengl.GL11; import ei.engine.scene.Entity; @@ -155,6 +157,8 @@ public class Particles extends Entity{ texture.bindGL(); + GL11.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE); + for(int i=0;i LWJGLGameWindow.getHeight()) { cursorY = LWJGLGameWindow.getHeight(); } - mouseMove(cursorX,cursorY); } + mouseUpdate(cursorX,cursorY,mouseDW); while ( Mouse.next() ) { - if(Mouse.getEventButton() == 0 && Mouse.getEventButtonState() == true) { - mouseDown(cursorX, cursorY); + if(Mouse.getEventButton() >= 0 && Mouse.getEventButtonState() == true) { + mouseDown(Mouse.getEventButton(),cursorX, cursorY); } - if(Mouse.getEventButton() == 0 && Mouse.getEventButtonState() == false) { - mouseUp(cursorX, cursorY); + if(Mouse.getEventButton() >= 0 && Mouse.getEventButtonState() == false) { + mouseUp(Mouse.getEventButton(),cursorX, cursorY); } } if(cursor != null){ - cursor.setLocation(new Vector2f(cursorX, cursorY)); + cursor.setLocation(new Vector2f(cursorX, + LWJGLGameWindow.getHeight()-cursorY)); } } /** * Called by update() when mouse moves */ - public abstract void mouseMove(int x, int y); + public abstract void mouseUpdate(int x, int y, int w); /** * Called by update() when mouse button is pressed */ - public abstract void mouseDown(int x, int y); + public abstract void mouseDown(int event,int x, int y); /** * Called by update() when mouse button is released */ - public abstract void mouseUp(int x, int y); + public abstract void mouseUp(int event,int x, int y); } diff --git a/src/ei/engine/scene/AnimatedSprite.java b/src/ei/engine/scene/AnimatedSprite.java index 050ce78..f61291e 100644 --- a/src/ei/engine/scene/AnimatedSprite.java +++ b/src/ei/engine/scene/AnimatedSprite.java @@ -1,5 +1,6 @@ package ei.engine.scene; +import java.awt.Rectangle; import java.util.HashMap; import org.lwjgl.opengl.GL11; @@ -113,17 +114,14 @@ public class AnimatedSprite extends Entity { // store the current model matrix GL11.glPushMatrix(); - //Sets the scale of the sprite - super.setScaleGL(); //Sets the location super.setTranslationGL(); //the rotation - super.setRotationGL(); - //and sets back the rotation so that the rotation pivot is the center of the sprite - super.setTranslationGL( - -textures.get(currentAnimation)[textureId].getImageWidth()/2, - -textures.get(currentAnimation)[textureId].getImageHeight()/2, - 0); + super.setRotationGL( + textures.get(currentAnimation)[textureId].getImageWidth()/2, + textures.get(currentAnimation)[textureId].getImageHeight()/2); + //Sets the scale of the sprite + super.setScaleGL(); // bind to the appropriate texture for this sprite textures.get(currentAnimation)[textureId].bindGL(); @@ -160,4 +158,15 @@ public class AnimatedSprite extends Entity { } } } + + /** + * Returns the bound of this class + */ + public Rectangle getBound() { + return new Rectangle( + (int)getLocation().getX(), + (int)getLocation().getY(), + textures.get(currentAnimation)[textureId].getImageWidth(), + textures.get(currentAnimation)[textureId].getImageHeight()); + } } \ No newline at end of file diff --git a/src/ei/engine/scene/Entity.java b/src/ei/engine/scene/Entity.java index bf6b680..d49a7c4 100644 --- a/src/ei/engine/scene/Entity.java +++ b/src/ei/engine/scene/Entity.java @@ -3,6 +3,8 @@ */ package ei.engine.scene; +import java.awt.Rectangle; + import org.lwjgl.opengl.GL11; import ei.engine.math.Vector2f; @@ -118,18 +120,6 @@ public abstract class Entity { GL11.glTranslatef(location.getX(), location.getY(), location.getZ()); } - /** - * Sets the location of the entity in opengl - * - * @param x The value to add x - * @param y The value to add y - * @param z The value to add z - */ - protected void setTranslationGL(float x, float y, float z){ - // translate to the right location and prepare to draw - GL11.glTranslatef(x,y, z); - } - protected void setScaleGL(){ // translate to the right location and prepare to draw GL11.glScalef(size.getX(), size.getY(), size.getZ()); @@ -138,21 +128,33 @@ public abstract class Entity { /** * Sets the rotation of the entity in opengl * before rendering. + * + * @param rx The x coordinate of the center of rotation + * @param ry The y coordinate of the center of rotation */ - protected void setRotationGL(){ + protected void setRotationGL(float rx, float ry){ + //GL11.glTranslatef(rx,ry, location.getZ()); // rotating the entity GL11.glRotatef(rotation.getX(), 1.0f, 0.0f, 0.0f); // Rotate On The X Axis GL11.glRotatef(rotation.getY(), 0.0f, 1.0f, 0.0f); // Rotate On The Y Axis GL11.glRotatef(rotation.getZ(), 0.0f, 0.0f, 1.0f); // Rotate On The Z Axis + GL11.glTranslatef(-rx,-ry, location.getZ()); + } + + + public boolean intersects(Entity e){ + return getBound().intersects(e.getBound()); } /** - * the render method should be implemented for every entity + * the render method can be implemented for every entity */ - public abstract void render(); + public void render(){} /** * the update method can be implemented for every entity */ public void update(){} + + public abstract Rectangle getBound(); } diff --git a/src/ei/engine/scene/Sprite.java b/src/ei/engine/scene/Sprite.java index fb6287f..665213a 100644 --- a/src/ei/engine/scene/Sprite.java +++ b/src/ei/engine/scene/Sprite.java @@ -1,5 +1,7 @@ package ei.engine.scene; +import java.awt.Rectangle; + import org.lwjgl.opengl.GL11; import ei.engine.texture.Texture; @@ -74,10 +76,14 @@ public class Sprite extends Entity { return texture.getImageHeight(); } - protected void bindTexture(){ - + /** + * Returns the texture + * @return The texture + */ + public Texture getTexture(){ + return texture; } - + /** * Draw the sprite */ @@ -85,14 +91,12 @@ public class Sprite extends Entity { // store the current model matrix GL11.glPushMatrix(); - //Sets the scale of the sprite - super.setScaleGL(); //Sets the location super.setTranslationGL(); //the rotation - super.setRotationGL(); - //and sets back the rotation so that the rotation pivot is the center of the sprite - super.setTranslationGL(-texture.getImageWidth()/2,-texture.getImageHeight()/2,0); + super.setRotationGL(texture.getImageWidth()/2,texture.getImageHeight()/2); + //Sets the scale of the sprite + super.setScaleGL(); // bind to the appropriate texture for this sprite texture.bindGL(); @@ -120,4 +124,15 @@ public class Sprite extends Entity { GL11.glPopMatrix(); } + /** + * Returns the bound of this class + */ + public Rectangle getBound() { + return new Rectangle( + (int)getLocation().getX(), + (int)getLocation().getY(), + texture.getImageWidth(), + texture.getImageHeight()); + } + } \ No newline at end of file diff --git a/src/ei/engine/sound/Sound.java b/src/ei/engine/sound/Sound.java index 46e8103..a77a7b1 100644 --- a/src/ei/engine/sound/Sound.java +++ b/src/ei/engine/sound/Sound.java @@ -1,12 +1,14 @@ package ei.engine.sound; +import java.awt.Rectangle; + import ei.engine.math.Vector3f; import ei.engine.scene.Entity; /** * A sound that can be played through OpenAL * - * @author Kevin Glass + * @author Ziver Koc */ public class Sound extends Entity{ private static int soundId = 1; @@ -91,9 +93,14 @@ public class Sound extends Entity{ return velocity; } - /** - * unimplamented method - * + /** + * Returns the bound of this class */ - public void render() {} + public Rectangle getBound() { + return new Rectangle( + (int)getLocation().getX(), + (int)getLocation().getY(), + 10, 10); + } + } diff --git a/src/ei/engine/sound/SoundManager.java b/src/ei/engine/sound/SoundManager.java index f2661c6..d6f8a18 100644 --- a/src/ei/engine/sound/SoundManager.java +++ b/src/ei/engine/sound/SoundManager.java @@ -14,7 +14,6 @@ import ei.engine.util.MultiPrintStream; /** * Responsible for holding and playing the sounds used in the game. * - * @author Kevin Glass * @author Ziver Koc */ public class SoundManager { diff --git a/src/ei/engine/state/GameState.java b/src/ei/engine/state/GameState.java index 4068f5c..8fd75e6 100644 --- a/src/ei/engine/state/GameState.java +++ b/src/ei/engine/state/GameState.java @@ -1,11 +1,24 @@ package ei.engine.state; +import ei.engine.input.InputHandler; + public abstract class GameState { private String name; + private InputHandler input; private boolean enabled = false; public GameState(String name){ this.name = name; + input = new InputHandler(); + } + + /** + * Returns the input handler of this state + * + * @return The input handler + */ + public InputHandler getInput(){ + return input; } /** @@ -30,6 +43,24 @@ public abstract class GameState { return name; } + /** + * Updates the State + * + */ + public void stateUpdate(){ + input.update(); + update(); + } + + /** + * Renders the state + * + */ + public void stateRender(){ + render(); + input.render(); + } + public abstract void update(); public abstract void render(); diff --git a/src/ei/engine/state/GameStateManager.java b/src/ei/engine/state/GameStateManager.java index 9cbc1fb..47d4f45 100644 --- a/src/ei/engine/state/GameStateManager.java +++ b/src/ei/engine/state/GameStateManager.java @@ -111,7 +111,7 @@ public class GameStateManager { public void update(){ for(int i=0; i loadTextures; + private Queue loadSounds; + // The name of the next state to activate after loading + private String nextState; + + // Temp things for the loadingbar + private int status; + private Sprite bar; + private Sprite loadBar; + private Sprite background; + + /** + * Creates a loadingstate + * @param name The name of the state + */ + public LoadingState(String name,String nextState) { + super(name); + this.nextState = nextState; + status = 0; + loadTextures = new LinkedList(); + loadSounds = new LinkedList(); + bar = new Sprite("Bar","data/loadbar_front.png"); + bar.setLocation(new Vector3f( + (LWJGLGameWindow.getWidth()/2), + (LWJGLGameWindow.getHeight()/2),0.0f)); + loadBar = new Sprite("LoadingBar","data/loadbar.png"); + loadBar.setLocation(new Vector3f( + (LWJGLGameWindow.getWidth()/2)-loadBar.getWidth(), + (LWJGLGameWindow.getHeight()/2)+3,0.0f)); + background = new Sprite("Bar","data/loadbar_back.png"); + background.setLocation(new Vector3f( + (LWJGLGameWindow.getWidth()/2), + (LWJGLGameWindow.getHeight()/2),0.0f)); + } + + /** + * Add a texture to be loaded + * @param url + */ + public void addTexture(String url){ + loadTextures.add(url); + } + + /** + * Add a sound to be loaded + * @param url + */ + public void addSound(String url){ + loadSounds.add(url); + } + + /** + * Loads the things + */ + public void update() { + if(!loadTextures.isEmpty()){ + TextureLoader.getTextureLoaderInstance().getTexture(loadTextures.poll()); + status++; + } + else if(!loadSounds.isEmpty()){ + SoundLoader.getInstnace().loadSound(loadSounds.poll()); + status++; + } + else{ + status++; + if(status >= 100){ + //deactivate this state and activate the next one + GameStateManager.getInstance().removeState(this); + GameStateManager.getInstance().setActive(nextState); + } + + } + background.update(); + loadBar.update(); + bar.update(); + } + + /** + * Render the load bar + */ + public void render() { + // Calculate the procentage + float procent = (float)status/100;//(loadTextures.size()+loadSounds.size()); + System.out.println("lol: "+procent); + loadBar.setLocation(new Vector3f( + (LWJGLGameWindow.getWidth()/2)-loadBar.getWidth()+(loadBar.getWidth()*procent), + (LWJGLGameWindow.getHeight()/2)+6,0.0f)); + //render the bar + background.render(); + loadBar.render(); + bar.render(); + } + +} diff --git a/src/ei/game/input/InGameKeyboardInput.java b/src/ei/game/input/InGameKeyboardInput.java new file mode 100644 index 0000000..b38f881 --- /dev/null +++ b/src/ei/game/input/InGameKeyboardInput.java @@ -0,0 +1,5 @@ +package ei.game.input; + +public class InGameKeyboardInput { + +} diff --git a/src/ei/game/input/InGameMouseInput.java b/src/ei/game/input/InGameMouseInput.java new file mode 100644 index 0000000..d887ba3 --- /dev/null +++ b/src/ei/game/input/InGameMouseInput.java @@ -0,0 +1,54 @@ +package ei.game.input; + +import ei.engine.LWJGLGameWindow; +import ei.engine.input.MouseInput; +import ei.engine.scene.Sprite; + +public class InGameMouseInput extends MouseInput{ + private static final int CAMERA_MOVE_BORDER = 40; + private static final float CAMERA_MOVE_SPEED = 6.0f; + + public InGameMouseInput() { + super("InGameMouseInput","data/cursor.png"); + Sprite s = getSprite(); + s.getTexture().setTextureWidth(50); + s.getTexture().setTextureHeight(50); + s.getTexture().setWidth(50); + s.getTexture().setHeight(50); + + } + + @Override + public void mouseUpdate(int x, int y, int w) { + // mov cam to the left + if(x < CAMERA_MOVE_BORDER){ + LWJGLGameWindow.getCamera().getLocation().add(-CAMERA_MOVE_SPEED,0,0); + } + // mov cam to the right + if(x > LWJGLGameWindow.getWidth()-CAMERA_MOVE_BORDER){ + LWJGLGameWindow.getCamera().getLocation().add(CAMERA_MOVE_SPEED,0,0); + } + // mov cam upp + if(y < CAMERA_MOVE_BORDER){ + LWJGLGameWindow.getCamera().getLocation().add(0,CAMERA_MOVE_SPEED,0); + } + // mov cam down + if(y > LWJGLGameWindow.getHeight()-CAMERA_MOVE_BORDER){ + LWJGLGameWindow.getCamera().getLocation().add(0,-CAMERA_MOVE_SPEED,0); + } + //System.out.println(x+"-"+y); + } + + @Override + public void mouseDown(int event,int x, int y) { + System.out.println("DOWN("+event+"): "+x+"-"+y); + + } + + @Override + public void mouseUp(int event,int x, int y) { + System.out.println("UP("+event+"): "+x+"-"+y); + + } + +} diff --git a/src/ei/game/player/Human.java b/src/ei/game/player/Human.java new file mode 100644 index 0000000..ae9040b --- /dev/null +++ b/src/ei/game/player/Human.java @@ -0,0 +1,5 @@ +package ei.game.player; + +public class Human { + +} diff --git a/src/ei/game/scene/GameEntity.java b/src/ei/game/scene/GameEntity.java new file mode 100644 index 0000000..3db5670 --- /dev/null +++ b/src/ei/game/scene/GameEntity.java @@ -0,0 +1,26 @@ +package ei.game.scene; + +public abstract class GameEntity{ + private int life; + + public GameEntity(int l){ + life = l; + } + + /** + * Returns the life + * + * @return The life + */ + public int getLife(){ + return life; + } + + /** + * Set the life + * @param l The life to set to + */ + public void setLife(int l){ + life = l; + } +} diff --git a/src/ei/game/scene/Map.java b/src/ei/game/scene/Map.java new file mode 100644 index 0000000..3ec4ca0 --- /dev/null +++ b/src/ei/game/scene/Map.java @@ -0,0 +1,92 @@ +package ei.game.scene; + +import ei.engine.math.Vector3f; +import ei.engine.scene.Node; +import ei.engine.scene.Sprite; + +public class Map { + private static final int POS_SIZE = 50; + private int width; + private int hight; + private GameEntity[][] map; + private Node mapNode; + + public Map(int w, int h){ + this.width = w; + this.hight = h; + init(); + } + + private void init(){ + map = new GameEntity[width][hight]; + + // init textures + mapNode = new Node("MapNode"); + for(int i=0; i availableUnits; + private ArrayList buildQueue; + + public Building(int l) { + super(l); + // TODO Auto-generated constructor stub + } + +} diff --git a/src/ei/game/scene/units/Unit.java b/src/ei/game/scene/units/Unit.java new file mode 100644 index 0000000..9cab81f --- /dev/null +++ b/src/ei/game/scene/units/Unit.java @@ -0,0 +1,12 @@ +package ei.game.scene.units; + +import ei.game.scene.GameEntity; + +public abstract class Unit extends GameEntity{ + + public Unit(int l) { + super(l); + // TODO Auto-generated constructor stub + } + +} diff --git a/src/ei/game/scene/weapons/Weapon.java b/src/ei/game/scene/weapons/Weapon.java new file mode 100644 index 0000000..e33ca27 --- /dev/null +++ b/src/ei/game/scene/weapons/Weapon.java @@ -0,0 +1,5 @@ +package ei.game.scene.weapons; + +public abstract class Weapon { + +}