79 lines
2.3 KiB
Java
79 lines
2.3 KiB
Java
package ei.game.input;
|
|
|
|
import java.util.ArrayList;
|
|
|
|
import ei.engine.LWJGLGameWindow;
|
|
import ei.engine.input.MouseInput;
|
|
import ei.engine.math.Vector2i;
|
|
import ei.engine.scene.Sprite;
|
|
import ei.engine.util.MultiPrintStream;
|
|
import ei.game.scene.GameEntity;
|
|
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<GameEntity> selected;
|
|
|
|
private Map map;
|
|
|
|
public InGameMouseInput(Map map) {
|
|
super("InGameMouseInput","data/cursor/cursor.png");
|
|
this.map = map;
|
|
this.selected = new ArrayList<GameEntity>();
|
|
|
|
//inits the mouse texture
|
|
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);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void mouseDown(int event,int x, int y) {
|
|
System.out.println("DOWN("+event+"): "+x+"-"+y);
|
|
Vector2i pos = map.getPosByPixel(
|
|
LWJGLGameWindow.getCamera().getLocation().getX()+x,
|
|
LWJGLGameWindow.getCamera().getLocation().getY()+(LWJGLGameWindow.getHeight()-y));
|
|
if(!map.isPosEmpty(pos.getX(), pos.getY())){
|
|
//map.printAllUnits();
|
|
selected.clear();
|
|
MultiPrintStream.out.println("Selecting: "+pos.getX()+", "+pos.getY());
|
|
selected.add(map.getPos(pos.getX(), pos.getY()));
|
|
}
|
|
else{
|
|
MultiPrintStream.out.println("Moving: "+pos.getX()+", "+pos.getY());
|
|
for(int i=0; i<selected.size() ;i++){
|
|
selected.get(i).move(pos.getX(),pos.getY());
|
|
}
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void mouseUp(int event,int x, int y) {
|
|
System.out.println("UP("+event+"): "+x+"-"+y);
|
|
}
|
|
|
|
}
|