LOLZ
This commit is contained in:
parent
02316b71b3
commit
a8f465ac6b
4 changed files with 92 additions and 25 deletions
|
|
@ -41,7 +41,9 @@ public class Particles extends Entity{
|
|||
private static float colors[][][]= // Rainbow Of Colors
|
||||
{
|
||||
{{1.0f,0.5f,0.5f},{1.0f,1.0f,0.5f}},
|
||||
{{1.0f,1.0f,0.5f},{1.0f,0.5f,0.5f}}
|
||||
{{1.0f,0.0f,0.5f},{0.0f,1.0f,0.5f}},
|
||||
{{0.0f,1.0f,0.5f},{0.0f,0.0f,1.0f}},
|
||||
{{1.0f,0.0f,1.0f},{1.0f,0.0f,0.0f}}
|
||||
};
|
||||
|
||||
private int maxParticles = 1000;
|
||||
|
|
|
|||
|
|
@ -6,6 +6,8 @@ import org.lwjgl.opengl.GL11;
|
|||
import ei.engine.LWJGLGameWindow;
|
||||
import ei.engine.math.Vector2f;
|
||||
import ei.engine.math.Vector3f;
|
||||
import ei.engine.scene.Entity;
|
||||
import ei.engine.scene.Node;
|
||||
import ei.engine.scene.Sprite;
|
||||
|
||||
/**
|
||||
|
|
@ -23,12 +25,14 @@ public abstract class MouseInput extends Input{
|
|||
private static int cursorY;
|
||||
// The texute for the mouse
|
||||
private Sprite cursor;
|
||||
private Node mouseNode;
|
||||
|
||||
public MouseInput(String name) {
|
||||
super(name);
|
||||
// init mouse: this will hide the native cursor (see drawCursor())
|
||||
Mouse.setGrabbed(false);
|
||||
|
||||
mouseNode = new Node("MouseInputNode");
|
||||
|
||||
// set initial cursor pos to center screen
|
||||
cursorX = (int) LWJGLGameWindow.getWidth() / 2;
|
||||
cursorY = (int) LWJGLGameWindow.getHeight() / 2;
|
||||
|
|
@ -39,6 +43,8 @@ public abstract class MouseInput extends Input{
|
|||
// init mouse: this will hide the native cursor (see drawCursor())
|
||||
Mouse.setGrabbed(true);
|
||||
cursor = new Sprite(name+" spatial",texture);
|
||||
mouseNode = new Node("MouseInputNode");
|
||||
|
||||
// set initial cursor pos to center screen
|
||||
cursorX = (int) LWJGLGameWindow.getWidth() / 2;
|
||||
cursorY = (int) LWJGLGameWindow.getHeight() / 2;
|
||||
|
|
@ -52,11 +58,21 @@ public abstract class MouseInput extends Input{
|
|||
public Sprite getSprite(){
|
||||
return cursor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the sprite of th mouse
|
||||
*
|
||||
* @return The sprite of the mouse
|
||||
*/
|
||||
public Node getNode(){
|
||||
return mouseNode;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the mous texture if texture set
|
||||
*/
|
||||
public void render() {
|
||||
mouseNode.render();
|
||||
if(cursor != null){
|
||||
GL11.glPushMatrix();
|
||||
Vector3f v = LWJGLGameWindow.getCamera().getLocation();
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import ei.game.gamestate.LoadingState;
|
|||
import ei.game.gamestate.SplashState;
|
||||
|
||||
public class EI extends LWJGLGameWindow{
|
||||
public static final boolean debug = true;
|
||||
public static final boolean debug = false;
|
||||
|
||||
public static void main(String[] args){
|
||||
new EI();
|
||||
|
|
|
|||
|
|
@ -6,7 +6,10 @@ import ei.engine.LWJGLGameWindow;
|
|||
import ei.engine.input.MouseInput;
|
||||
import ei.engine.math.Vector2f;
|
||||
import ei.engine.math.Vector2i;
|
||||
import ei.engine.math.Vector4f;
|
||||
import ei.engine.scene.Box;
|
||||
import ei.engine.scene.Sprite;
|
||||
import ei.engine.texture.Texture;
|
||||
import ei.engine.util.MultiPrintStream;
|
||||
import ei.game.scene.GameEntity;
|
||||
import ei.game.scene.Map;
|
||||
|
|
@ -16,6 +19,8 @@ public class InGameMouseInput extends MouseInput{
|
|||
private static final float CAMERA_MOVE_SPEED = 6.0f;
|
||||
|
||||
private ArrayList<GameEntity> selected;
|
||||
private Vector2f leftKlickPos;
|
||||
private Box markingBox;
|
||||
|
||||
private Map map;
|
||||
|
||||
|
|
@ -27,6 +32,10 @@ public class InGameMouseInput extends MouseInput{
|
|||
//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
|
||||
|
|
@ -47,43 +56,83 @@ public class InGameMouseInput extends MouseInput{
|
|||
if(y > LWJGLGameWindow.getHeight()-CAMERA_MOVE_BORDER){
|
||||
LWJGLGameWindow.getCamera().getLocation().add(0,CAMERA_MOVE_SPEED,0);
|
||||
}
|
||||
|
||||
// The
|
||||
if(leftKlickPos != null){
|
||||
System.out.println("leftclick 2");
|
||||
markingBox.setSize(new Vector2f(
|
||||
Math.abs(leftKlickPos.getX()-(LWJGLGameWindow.getCamera().getLocation().getX()+x)),
|
||||
Math.abs(leftKlickPos.getY()-(LWJGLGameWindow.getCamera().getLocation().getY()+y))));
|
||||
getNode().add(markingBox);
|
||||
}
|
||||
}
|
||||
|
||||
@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()+y);
|
||||
|
||||
//selecting unit.
|
||||
if(event==RIGHT_MOUSE_BUTTON) {
|
||||
for(int i=0; i<selected.size(); i++) {
|
||||
selected.get(i).attack(new Vector2i(pos.getX(), pos.getY()));
|
||||
}
|
||||
}
|
||||
else if(!map.isPosEmpty(pos.getX(), pos.getY())){
|
||||
if(event==LEFT_MOUSE_BUTTON){
|
||||
//map.printAllUnits();
|
||||
for(int i=0; i<selected.size(); i++) {
|
||||
selected.get(i).setSelected(false);
|
||||
}
|
||||
selected.clear();
|
||||
MultiPrintStream.out.println("Selecting: "+pos.getX()+", "+pos.getY());
|
||||
selected.add(map.getPos(pos.getX(), pos.getY()));
|
||||
map.getPos(pos.getX(), pos.getY()).setSelected(true);
|
||||
|
||||
}
|
||||
else{ //unit action.
|
||||
MultiPrintStream.out.println("Moving: "+pos.getX()+", "+pos.getY());
|
||||
for(int i=0; i<selected.size() ;i++){
|
||||
selected.get(i).move(pos.getX(),pos.getY());
|
||||
if(leftKlickPos == null){
|
||||
System.out.println("leftclick 1");
|
||||
leftKlickPos = new Vector2f(x,y);
|
||||
markingBox.setLocation(leftKlickPos);
|
||||
}
|
||||
}
|
||||
//unit action.
|
||||
else if(event==RIGHT_MOUSE_BUTTON) {
|
||||
if(!map.isPosEmpty(pos.getX(), pos.getY())){
|
||||
for(int i=0; i<selected.size(); i++) {
|
||||
selected.get(i).attack(new Vector2i(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);
|
||||
Vector2i pos = Map.getPosByPixel(
|
||||
LWJGLGameWindow.getCamera().getLocation().getX()+x,
|
||||
LWJGLGameWindow.getCamera().getLocation().getY()+y);
|
||||
|
||||
if(leftKlickPos != null){
|
||||
deselectAllUnits();
|
||||
selectUnits(Map.getPosByPixel(leftKlickPos.getX(), leftKlickPos.getY()),pos);
|
||||
leftKlickPos = null;
|
||||
getNode().remove(markingBox);
|
||||
}
|
||||
}
|
||||
|
||||
public void selectUnits(Vector2i startPos, Vector2i stopPos){
|
||||
MultiPrintStream.out.println("Selecting: "+startPos.getX()+", "+startPos.getY()+" to "+stopPos.getX()+", "+stopPos.getY());
|
||||
for(int i=Math.min(startPos.getX(), stopPos.getX()); i<Math.max(startPos.getX(), stopPos.getX()) ;i++){
|
||||
for(int j=Math.min(startPos.getY(), stopPos.getY()); j<Math.max(startPos.getY(), stopPos.getY()) ;j++){
|
||||
if(!map.isPosEmpty(i, j)){
|
||||
selected.add(map.getPos(i, j));
|
||||
map.getPos(i, j).setSelected(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deselects all the units
|
||||
*
|
||||
*/
|
||||
public void deselectAllUnits(){
|
||||
for(int i=0; i<selected.size(); i++) {
|
||||
selected.get(i).setSelected(false);
|
||||
}
|
||||
selected.clear();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue