fixed mouse select

This commit is contained in:
Ziver Koc 2007-04-04 17:32:54 +00:00
parent 88d92f1b96
commit 4627101025
2 changed files with 20 additions and 8 deletions

View file

@ -1,25 +1,33 @@
package ei.game.input; package ei.game.input;
import java.util.ArrayList;
import ei.engine.LWJGLGameWindow; import ei.engine.LWJGLGameWindow;
import ei.engine.input.MouseInput; import ei.engine.input.MouseInput;
import ei.engine.math.Vector2i;
import ei.engine.scene.Sprite; import ei.engine.scene.Sprite;
import ei.game.scene.GameEntity;
import ei.game.scene.Map; import ei.game.scene.Map;
public class InGameMouseInput extends MouseInput{ public class InGameMouseInput extends MouseInput{
private static final int CAMERA_MOVE_BORDER = 40; private static final int CAMERA_MOVE_BORDER = 40;
private static final float CAMERA_MOVE_SPEED = 6.0f; private static final float CAMERA_MOVE_SPEED = 6.0f;
private ArrayList<GameEntity> selected;
private Map map; private Map map;
public InGameMouseInput(Map map) { public InGameMouseInput(Map map) {
super("InGameMouseInput","data/cursor/cursor.png"); super("InGameMouseInput","data/cursor/cursor.png");
this.map = map; this.map = map;
this.selected = new ArrayList<GameEntity>();
//inits the mouse texture
Sprite s = getSprite(); Sprite s = getSprite();
s.getTexture().setTextureWidth(50); s.getTexture().setTextureWidth(50);
s.getTexture().setTextureHeight(50); s.getTexture().setTextureHeight(50);
s.getTexture().setWidth(50); s.getTexture().setWidth(50);
s.getTexture().setHeight(50); s.getTexture().setHeight(50);
} }
@Override @Override
@ -46,10 +54,14 @@ public class InGameMouseInput extends MouseInput{
@Override @Override
public void mouseDown(int event,int x, int y) { public void mouseDown(int event,int x, int y) {
System.out.println("DOWN("+event+"): "+x+"-"+y+map); System.out.println("DOWN("+event+"): "+x+"-"+y+map);
System.out.println(map.getPosByPixel( Vector2i pos = map.getPosByPixel(
LWJGLGameWindow.getCamera().getLocation().getX()+x, LWJGLGameWindow.getCamera().getLocation().getX()+x,
LWJGLGameWindow.getCamera().getLocation().getY()+y)); LWJGLGameWindow.getCamera().getLocation().getY()+y);
if(!map.isPosEmpty(pos.getX(), pos.getY())){
selected.clear();
System.out.println(pos.getX()+", "+pos.getY());
selected.add(map.getPos(pos.getX(), pos.getY()));
}
} }
@Override @Override

View file

@ -29,8 +29,8 @@ public class Map {
s.setLocation(new Vector3f(i*POS_SIZE,j*POS_SIZE,0)); s.setLocation(new Vector3f(i*POS_SIZE,j*POS_SIZE,0));
s.getTexture().setTextureWidth(POS_SIZE+1.2f); s.getTexture().setTextureWidth(POS_SIZE+1.2f);
s.getTexture().setTextureHeight(POS_SIZE+1.2f); s.getTexture().setTextureHeight(POS_SIZE+1.2f);
s.getTexture().setWidth(POS_SIZE+1); s.getTexture().setWidth(POS_SIZE);
s.getTexture().setHeight(POS_SIZE+1); s.getTexture().setHeight(POS_SIZE);
mapNode.add(s); mapNode.add(s);
} }
} }
@ -45,8 +45,8 @@ public class Map {
} }
public Vector2i getPixelByPos(int x, int y){ public Vector2i getPixelByPos(int x, int y){
x = POS_SIZE*x; x = (int)(POS_SIZE*x*1.2f);
y = POS_SIZE*y; y = (int)(POS_SIZE*y*1.2f);
return new Vector2i((int)x,(int)y); return new Vector2i((int)x,(int)y);
} }