2007-03-29 23:21:00 +00:00
|
|
|
package ei.game.input;
|
|
|
|
|
|
2007-04-04 17:32:54 +00:00
|
|
|
import java.util.ArrayList;
|
|
|
|
|
|
2007-03-29 23:21:00 +00:00
|
|
|
import ei.engine.LWJGLGameWindow;
|
|
|
|
|
import ei.engine.input.MouseInput;
|
2007-04-15 18:52:42 +00:00
|
|
|
import ei.engine.math.Vector2f;
|
2007-04-04 17:32:54 +00:00
|
|
|
import ei.engine.math.Vector2i;
|
2007-03-29 23:21:00 +00:00
|
|
|
import ei.engine.scene.Sprite;
|
2007-04-04 18:28:59 +00:00
|
|
|
import ei.engine.util.MultiPrintStream;
|
2007-04-04 17:32:54 +00:00
|
|
|
import ei.game.scene.GameEntity;
|
2007-04-04 15:20:53 +00:00
|
|
|
import ei.game.scene.Map;
|
2007-03-29 23:21:00 +00:00
|
|
|
|
|
|
|
|
public class InGameMouseInput extends MouseInput{
|
|
|
|
|
private static final int CAMERA_MOVE_BORDER = 40;
|
|
|
|
|
private static final float CAMERA_MOVE_SPEED = 6.0f;
|
|
|
|
|
|
2007-04-04 17:32:54 +00:00
|
|
|
private ArrayList<GameEntity> selected;
|
|
|
|
|
|
2007-04-04 15:20:53 +00:00
|
|
|
private Map map;
|
|
|
|
|
|
|
|
|
|
public InGameMouseInput(Map map) {
|
|
|
|
|
super("InGameMouseInput","data/cursor/cursor.png");
|
|
|
|
|
this.map = map;
|
2007-04-04 17:32:54 +00:00
|
|
|
this.selected = new ArrayList<GameEntity>();
|
|
|
|
|
|
|
|
|
|
//inits the mouse texture
|
2007-03-29 23:21:00 +00:00
|
|
|
Sprite s = getSprite();
|
2007-04-15 18:52:42 +00:00
|
|
|
s.setSize(new Vector2f(38,50));
|
2007-03-29 23:21:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@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){
|
2007-04-15 19:27:36 +00:00
|
|
|
LWJGLGameWindow.getCamera().getLocation().add(0,-CAMERA_MOVE_SPEED,0);
|
2007-03-29 23:21:00 +00:00
|
|
|
}
|
|
|
|
|
// mov cam down
|
|
|
|
|
if(y > LWJGLGameWindow.getHeight()-CAMERA_MOVE_BORDER){
|
2007-04-15 19:27:36 +00:00
|
|
|
LWJGLGameWindow.getCamera().getLocation().add(0,CAMERA_MOVE_SPEED,0);
|
2007-03-29 23:21:00 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void mouseDown(int event,int x, int y) {
|
2007-04-04 18:13:38 +00:00
|
|
|
System.out.println("DOWN("+event+"): "+x+"-"+y);
|
2007-04-18 09:04:08 +00:00
|
|
|
Vector2i pos = Map.getPosByPixel(
|
2007-04-04 16:00:09 +00:00
|
|
|
LWJGLGameWindow.getCamera().getLocation().getX()+x,
|
2007-04-15 19:27:36 +00:00
|
|
|
LWJGLGameWindow.getCamera().getLocation().getY()+y);
|
2007-04-16 11:34:57 +00:00
|
|
|
//selecting unit.
|
2007-04-04 17:32:54 +00:00
|
|
|
if(!map.isPosEmpty(pos.getX(), pos.getY())){
|
2007-04-04 18:28:59 +00:00
|
|
|
//map.printAllUnits();
|
2007-04-16 11:34:57 +00:00
|
|
|
for(int i=0; i<selected.size(); i++) {
|
|
|
|
|
selected.get(i).setSelected(false);
|
|
|
|
|
}
|
2007-04-04 17:32:54 +00:00
|
|
|
selected.clear();
|
2007-04-04 18:28:59 +00:00
|
|
|
MultiPrintStream.out.println("Selecting: "+pos.getX()+", "+pos.getY());
|
2007-04-04 17:32:54 +00:00
|
|
|
selected.add(map.getPos(pos.getX(), pos.getY()));
|
2007-04-16 11:34:57 +00:00
|
|
|
map.getPos(pos.getX(), pos.getY()).setSelected(true);
|
|
|
|
|
|
2007-04-04 17:32:54 +00:00
|
|
|
}
|
2007-04-16 11:34:57 +00:00
|
|
|
else{ //unit action.
|
2007-04-04 18:28:59 +00:00
|
|
|
MultiPrintStream.out.println("Moving: "+pos.getX()+", "+pos.getY());
|
2007-04-04 17:47:18 +00:00
|
|
|
for(int i=0; i<selected.size() ;i++){
|
2007-04-04 18:13:38 +00:00
|
|
|
selected.get(i).move(pos.getX(),pos.getY());
|
2007-04-04 17:47:18 +00:00
|
|
|
}
|
|
|
|
|
}
|
2007-03-29 23:21:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void mouseUp(int event,int x, int y) {
|
|
|
|
|
System.out.println("UP("+event+"): "+x+"-"+y);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|