Added mouse over
This commit is contained in:
parent
22965dbdd1
commit
c6ba0ea532
6 changed files with 129 additions and 87 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ public class InGameMouseInput extends MouseInput{
|
|||
private static final float CAMERA_MOVE_SPEED = 6.0f;
|
||||
|
||||
private ArrayList<GameEntity> selected;
|
||||
private GameEntity oldMouseOver;
|
||||
private Vector2f leftKlickPos;
|
||||
private Box markingBox;
|
||||
|
||||
|
|
@ -56,6 +57,11 @@ public class InGameMouseInput extends MouseInput{
|
|||
LWJGLGameWindow.getCamera().getLocation().add(0,CAMERA_MOVE_SPEED,0);
|
||||
}
|
||||
|
||||
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;
|
||||
|
|
@ -80,6 +86,14 @@ public class InGameMouseInput extends MouseInput{
|
|||
leftKlickPos.getX()-markingBox.getSize().getX()/2,
|
||||
leftKlickPos.getY()-markingBox.getSize().getY()/2));
|
||||
}
|
||||
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -87,7 +101,7 @@ public class InGameMouseInput extends MouseInput{
|
|||
Vector2i pos = Map.getPosByPixel(
|
||||
LWJGLGameWindow.getCamera().getLocation().getX()+x,
|
||||
LWJGLGameWindow.getCamera().getLocation().getY()+y);
|
||||
|
||||
if(map.posExist(pos.getX(), pos.getY())){
|
||||
//selecting unit.
|
||||
if(event==LEFT_MOUSE_BUTTON){
|
||||
//map.printAllUnits();
|
||||
|
|
@ -114,6 +128,7 @@ public class InGameMouseInput extends MouseInput{
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void mouseUp(int event,int x, int y) {
|
||||
|
|
@ -121,6 +136,7 @@ public class InGameMouseInput extends MouseInput{
|
|||
LWJGLGameWindow.getCamera().getLocation().getX()+x,
|
||||
LWJGLGameWindow.getCamera().getLocation().getY()+y);
|
||||
|
||||
if(map.posExist(pos.getX(), pos.getY())){
|
||||
if(leftKlickPos != null){
|
||||
deselectAllUnits();
|
||||
selectUnits(Map.getPosByPixel(leftKlickPos.getX(), leftKlickPos.getY()),pos);
|
||||
|
|
@ -128,6 +144,7 @@ public class InGameMouseInput extends MouseInput{
|
|||
getNode().remove(markingBox);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Selecting all the units between the two positions
|
||||
|
|
|
|||
|
|
@ -1,17 +1,14 @@
|
|||
package ei.game.scene;
|
||||
|
||||
import ei.engine.math.Vector2f;
|
||||
import ei.engine.math.Vector2i;
|
||||
import ei.engine.scene.Entity;
|
||||
|
||||
public abstract class GameEntity{
|
||||
private int max_life;
|
||||
private int life;
|
||||
private boolean selected;
|
||||
|
||||
public GameEntity(int l){
|
||||
setLife(l);
|
||||
this.selected = false;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -54,20 +51,18 @@ public abstract class GameEntity{
|
|||
max_life = l;
|
||||
}
|
||||
|
||||
/**
|
||||
* If the unit is selected.
|
||||
* @return true if selected.
|
||||
*/
|
||||
public boolean isSelected() {
|
||||
return selected;
|
||||
}
|
||||
/**
|
||||
* Sets a unit to be selected or not.
|
||||
* @param b true or false.
|
||||
*/
|
||||
public void setSelected(boolean b) {
|
||||
this.selected = b;
|
||||
}
|
||||
public abstract void setSelected(boolean b);
|
||||
|
||||
/**
|
||||
* Set if the mouse is over the unit or not
|
||||
* @param b If the mouse is over the unit or not
|
||||
*/
|
||||
public abstract void setMouseOver(boolean b);
|
||||
|
||||
protected abstract SelectBox getSelection();
|
||||
|
||||
public void move(int x, int y) {
|
||||
|
|
|
|||
|
|
@ -3,7 +3,6 @@ package ei.game.scene;
|
|||
import ei.engine.math.Vector2f;
|
||||
import ei.engine.math.Vector2i;
|
||||
import ei.engine.math.Vector3f;
|
||||
import ei.engine.scene.Box;
|
||||
import ei.engine.scene.Node;
|
||||
import ei.engine.scene.Sprite;
|
||||
|
||||
|
|
@ -76,14 +75,24 @@ public class Map {
|
|||
* @return True if empty else false
|
||||
*/
|
||||
public boolean isPosEmpty(int x, int y){
|
||||
if(x < 0 || y < 0 || x >= 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
|
||||
*
|
||||
|
|
|
|||
|
|
@ -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
|
||||
*
|
||||
|
|
|
|||
|
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue