This is a big commit. Added mouse cursors and a load bar. Started whit the game. and many many other things
This commit is contained in:
parent
448fca2fdf
commit
4e7722fedb
34 changed files with 597 additions and 95 deletions
|
|
@ -1,9 +1,11 @@
|
|||
package ei.engine.input;
|
||||
|
||||
import org.lwjgl.input.Mouse;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import ei.engine.LWJGLGameWindow;
|
||||
import ei.engine.math.Vector2f;
|
||||
import ei.engine.math.Vector3f;
|
||||
import ei.engine.scene.Sprite;
|
||||
|
||||
/**
|
||||
|
|
@ -12,6 +14,9 @@ import ei.engine.scene.Sprite;
|
|||
*
|
||||
*/
|
||||
public abstract class MouseInput extends Input{
|
||||
public static final int LEFT_MOUSE_BUTTON = 0;
|
||||
public static final int RIGHT_MOUSE_BUTTON = 1;
|
||||
public static final int MIDDLE_MOUSE_BUTTON = 2;
|
||||
// The x pos of the mouse
|
||||
private static int cursorX;
|
||||
// The y pos of the mouse
|
||||
|
|
@ -22,19 +27,42 @@ public abstract class MouseInput extends Input{
|
|||
public MouseInput(String name) {
|
||||
super(name);
|
||||
// init mouse: this will hide the native cursor (see drawCursor())
|
||||
Mouse.setGrabbed(true);
|
||||
Mouse.setGrabbed(false);
|
||||
|
||||
// set initial cursor pos to center screen
|
||||
cursorX = (int) LWJGLGameWindow.getWidth() / 2;
|
||||
cursorY = (int) LWJGLGameWindow.getHeight() / 2;
|
||||
}
|
||||
|
||||
public MouseInput(String name,String texture){
|
||||
super(name);
|
||||
// init mouse: this will hide the native cursor (see drawCursor())
|
||||
Mouse.setGrabbed(true);
|
||||
cursor = new Sprite(name+" spatial",texture);
|
||||
// set initial cursor pos to center screen
|
||||
cursorX = (int) LWJGLGameWindow.getWidth() / 2;
|
||||
cursorY = (int) LWJGLGameWindow.getHeight() / 2;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the sprite of th mouse
|
||||
*
|
||||
* @return The sprite of the mouse
|
||||
*/
|
||||
public Sprite getSprite(){
|
||||
return cursor;
|
||||
}
|
||||
|
||||
/**
|
||||
* Renders the mous texture if texture set
|
||||
*/
|
||||
public void render() {
|
||||
if(cursor != null){
|
||||
cursor.render();
|
||||
GL11.glPushMatrix();
|
||||
Vector3f v = LWJGLGameWindow.getCamera().getLocation();
|
||||
GL11.glTranslatef(v.getX(),v.getY(), v.getZ());
|
||||
cursor.render();
|
||||
GL11.glPopMatrix();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -61,36 +89,37 @@ public abstract class MouseInput extends Input{
|
|||
else if (cursorY > LWJGLGameWindow.getHeight()) {
|
||||
cursorY = LWJGLGameWindow.getHeight();
|
||||
}
|
||||
mouseMove(cursorX,cursorY);
|
||||
}
|
||||
mouseUpdate(cursorX,cursorY,mouseDW);
|
||||
|
||||
while ( Mouse.next() ) {
|
||||
if(Mouse.getEventButton() == 0 && Mouse.getEventButtonState() == true) {
|
||||
mouseDown(cursorX, cursorY);
|
||||
if(Mouse.getEventButton() >= 0 && Mouse.getEventButtonState() == true) {
|
||||
mouseDown(Mouse.getEventButton(),cursorX, cursorY);
|
||||
}
|
||||
if(Mouse.getEventButton() == 0 && Mouse.getEventButtonState() == false) {
|
||||
mouseUp(cursorX, cursorY);
|
||||
if(Mouse.getEventButton() >= 0 && Mouse.getEventButtonState() == false) {
|
||||
mouseUp(Mouse.getEventButton(),cursorX, cursorY);
|
||||
}
|
||||
}
|
||||
|
||||
if(cursor != null){
|
||||
cursor.setLocation(new Vector2f(cursorX, cursorY));
|
||||
cursor.setLocation(new Vector2f(cursorX,
|
||||
LWJGLGameWindow.getHeight()-cursorY));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called by update() when mouse moves
|
||||
*/
|
||||
public abstract void mouseMove(int x, int y);
|
||||
public abstract void mouseUpdate(int x, int y, int w);
|
||||
|
||||
/**
|
||||
* Called by update() when mouse button is pressed
|
||||
*/
|
||||
public abstract void mouseDown(int x, int y);
|
||||
public abstract void mouseDown(int event,int x, int y);
|
||||
|
||||
/**
|
||||
* Called by update() when mouse button is released
|
||||
*/
|
||||
public abstract void mouseUp(int x, int y);
|
||||
public abstract void mouseUp(int event,int x, int y);
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue