diff --git a/src/ei/engine/LWJGLGameWindow.java b/src/ei/engine/LWJGLGameWindow.java index 2f203f5..8924401 100644 --- a/src/ei/engine/LWJGLGameWindow.java +++ b/src/ei/engine/LWJGLGameWindow.java @@ -89,6 +89,7 @@ public class LWJGLGameWindow { // enable textures since we're going to use these for our sprites GL11.glEnable(GL11.GL_TEXTURE_2D); + // Enable Smooth Shading GL11.glShadeModel(GL11.GL_SMOOTH); // disable the OpenGL depth test since we're rendering 2D graphics GL11.glDisable(GL11.GL_DEPTH_TEST); @@ -96,8 +97,6 @@ public class LWJGLGameWindow { //GL11.glDepthFunc(GL11.GL_LEQUAL); // The Type Of Depth Testing To Do // 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.0f); // Depth Buffer Setup diff --git a/src/ei/game/input/InGameMouseInput.java b/src/ei/game/input/InGameMouseInput.java index 963757e..c3fb8c7 100644 --- a/src/ei/game/input/InGameMouseInput.java +++ b/src/ei/game/input/InGameMouseInput.java @@ -16,27 +16,28 @@ import ei.game.scene.Map; public class InGameMouseInput extends MouseInput{ private static final int CAMERA_MOVE_BORDER = 40; private static final float CAMERA_MOVE_SPEED = 6.0f; - + private ArrayList selected; + private GameEntity oldMouseOver; private Vector2f leftKlickPos; private Box markingBox; - + private Map map; - + public InGameMouseInput(Map map) { super("InGameMouseInput","data/cursor/cursor.png"); this.map = map; this.selected = new ArrayList(); - + //inits the mouse texture Sprite s = getSprite(); s.setSize(new Vector2f(38,50)); - + Texture tex = new Texture(); tex.setColor(new Vector4f(0.5f, 1.0f, 0.5f,1)); markingBox = new Box("MarkingBob", tex); } - + @Override public void mouseUpdate(int x, int y, int w) { // mov cam to the left @@ -55,61 +56,75 @@ public class InGameMouseInput extends MouseInput{ if(y > LWJGLGameWindow.getHeight()-CAMERA_MOVE_BORDER){ LWJGLGameWindow.getCamera().getLocation().add(0,CAMERA_MOVE_SPEED,0); } - - // The marking box is sized and positioned - if(leftKlickPos != null){ - float markingSizeX = 0; - float markingSizeY = 0; - - if(leftKlickPos.getX() > (LWJGLGameWindow.getCamera().getLocation().getX()+x)){ - markingSizeX = Math.abs(leftKlickPos.getX()-(LWJGLGameWindow.getCamera().getLocation().getX()+x)); + + Vector2i pos = Map.getPosByPixel( + LWJGLGameWindow.getCamera().getLocation().getX()+x, + LWJGLGameWindow.getCamera().getLocation().getY()+y); + + if(map.posExist(pos.getX(), pos.getY())){ + // The marking box is sized and positioned + if(leftKlickPos != null){ + float markingSizeX = 0; + float markingSizeY = 0; + + if(leftKlickPos.getX() > (LWJGLGameWindow.getCamera().getLocation().getX()+x)){ + markingSizeX = Math.abs(leftKlickPos.getX()-(LWJGLGameWindow.getCamera().getLocation().getX()+x)); + } + else{ + markingSizeX = -Math.abs(leftKlickPos.getX()-(LWJGLGameWindow.getCamera().getLocation().getX()+x)); + } + + if(leftKlickPos.getY() > (LWJGLGameWindow.getCamera().getLocation().getY()+y)){ + markingSizeY = Math.abs(leftKlickPos.getY()-(LWJGLGameWindow.getCamera().getLocation().getY()+y)); + } + else{ + markingSizeY = -Math.abs(leftKlickPos.getY()-(LWJGLGameWindow.getCamera().getLocation().getY()+y)); + } + + markingBox.setSize(new Vector2f(markingSizeX+getSprite().getSize().getX()/2,markingSizeY+getSprite().getSize().getY()/2)); + markingBox.setLocation(new Vector2f( + leftKlickPos.getX()-markingBox.getSize().getX()/2, + leftKlickPos.getY()-markingBox.getSize().getY()/2)); } - else{ - markingSizeX = -Math.abs(leftKlickPos.getX()-(LWJGLGameWindow.getCamera().getLocation().getX()+x)); + + // Make unit mouseover select + if(!map.isPosEmpty(pos.getX(), pos.getY())){ + if(oldMouseOver != null)oldMouseOver.setMouseOver(false); + oldMouseOver = map.getPos(pos.getX(), pos.getY()); + oldMouseOver.setMouseOver(true); } - - if(leftKlickPos.getY() > (LWJGLGameWindow.getCamera().getLocation().getY()+y)){ - markingSizeY = Math.abs(leftKlickPos.getY()-(LWJGLGameWindow.getCamera().getLocation().getY()+y)); - } - else{ - markingSizeY = -Math.abs(leftKlickPos.getY()-(LWJGLGameWindow.getCamera().getLocation().getY()+y)); - } - - markingBox.setSize(new Vector2f(markingSizeX+getSprite().getSize().getX()/2,markingSizeY+getSprite().getSize().getY()/2)); - markingBox.setLocation(new Vector2f( - leftKlickPos.getX()-markingBox.getSize().getX()/2, - leftKlickPos.getY()-markingBox.getSize().getY()/2)); } } - + @Override public void mouseDown(int event,int x, int y) { Vector2i pos = Map.getPosByPixel( LWJGLGameWindow.getCamera().getLocation().getX()+x, LWJGLGameWindow.getCamera().getLocation().getY()+y); - - //selecting unit. - if(event==LEFT_MOUSE_BUTTON){ - //map.printAllUnits(); - if(leftKlickPos == null){ - leftKlickPos = new Vector2f( - LWJGLGameWindow.getCamera().getLocation().getX()+x, - LWJGLGameWindow.getCamera().getLocation().getY()+y); - markingBox.setSize(new Vector2f(0,0)); - getNode().add(markingBox); - } - } - //unit action. - else if(event==RIGHT_MOUSE_BUTTON) { - if(!map.isPosEmpty(pos.getX(), pos.getY())){ - for(int i=0; i= width || y >= hight) - return false; - if(map[x][y] == null){ + if(posExist(x,y) && map[x][y] == null){ return true; } return false; } + /** + * Returns true if the given pos exists on the map + * @param x The x pos + * @param y The y pos + * @return True if the given pos exists on the map + */ + public boolean posExist(int x, int y){ + if(x < 0 || y < 0 || x >= width || y >= hight) + return false; + return true; + } + /** * Returns the object at the pos * diff --git a/src/ei/game/scene/SelectBox.java b/src/ei/game/scene/SelectBox.java index 2451009..91880ee 100644 --- a/src/ei/game/scene/SelectBox.java +++ b/src/ei/game/scene/SelectBox.java @@ -9,6 +9,7 @@ import ei.engine.texture.Texture; public class SelectBox { private Node selectNode; + private Node mouseOverNode; private Sprite value; private int max; private float width; @@ -25,6 +26,7 @@ public class SelectBox { this.max = max; this.width = x; selectNode = new Node("SelectionNode"); + mouseOverNode = new Node("MouseOverNode"); Texture tex = new Texture(); tex.setColor(new Vector4f(0.5f, 1.0f, 0.5f,1)); @@ -36,11 +38,13 @@ public class SelectBox { value.setSize(new Vector2f(x,height)); value.setLocation(new Vector2f(0,-x/2+height/2)); selectNode.add(value); + mouseOverNode.add(value); Box bar = new Box("bar",tex); bar.setSize(new Vector2f(x,height)); bar.setLocation(new Vector2f(0,-x/2+height/2)); selectNode.add(bar); + mouseOverNode.add(bar); Box select = new Box("select",tex); select.setSize(new Vector2f(x,y)); @@ -54,10 +58,20 @@ public class SelectBox { * * @return The node of the selection */ - public Node getNode(){ + public Node getSelectNode(){ return selectNode; } + + /** + * Returns the node of the selection + * + * @return The node of the selection + */ + public Node getMouseOverNode(){ + return mouseOverNode; + } + /** * Sets the value of the health bar * diff --git a/src/ei/game/scene/units/Unit.java b/src/ei/game/scene/units/Unit.java index 36f12f1..3942ba6 100644 --- a/src/ei/game/scene/units/Unit.java +++ b/src/ei/game/scene/units/Unit.java @@ -45,12 +45,20 @@ public abstract class Unit extends GameEntity{ } public void setSelected(boolean b) { - super.setSelected(b); if(b) { - unitNode.add(getSelection().getNode()); + unitNode.add(getSelection().getSelectNode()); } else{ - unitNode.remove(getSelection().getNode()); + unitNode.remove(getSelection().getSelectNode()); + } + } + + public void setMouseOver(boolean b) { + if(b) { + unitNode.add(getSelection().getMouseOverNode()); + } + else{ + unitNode.remove(getSelection().getMouseOverNode()); } }