système pour contrôler le rendu de sprite de taille differente
# Pour l'instant toutes les sprites d'un même état doivent être de la même taille
This commit is contained in:
parent
ee8473e344
commit
5c48a88be4
@ -160,8 +160,9 @@ public class Engine {
|
||||
String path2 = "textures/awesomeface.png";
|
||||
|
||||
ObjectGl zangief = new ObjectGl(0f,60f,80f,10f, path, null);
|
||||
zangief.setTextureWrap(58,0,62,84, ObjectGl.STICK_TOP);
|
||||
engine.add_objectGl(zangief);
|
||||
// zangief.translate(new Vector3f(-600.0f,100,10.0f));
|
||||
zangief.translate(new Vector3f(-5000.0f,0.0f,10.0f));
|
||||
|
||||
ObjectGl smiley2 = new ObjectGl(0.0f,500.0f,500.0f, 1f, path2, null);
|
||||
engine.add_objectGl(smiley2);
|
||||
@ -176,8 +177,7 @@ public class Engine {
|
||||
lastFrame = System.currentTimeMillis();
|
||||
// Game logic should fit here
|
||||
|
||||
zangief.setTextureWrap(58,0,62,84);
|
||||
gamepadInput(zangief, speed);
|
||||
// gamepadInput(zangief, speed);
|
||||
input(zangief, speed);
|
||||
// input(smiley2, speed);
|
||||
|
||||
@ -226,9 +226,9 @@ public class Engine {
|
||||
if ( (gamepadAxes.get(2) < -0.1 || gamepadAxes.get(2) > 0.1) ) { // de droite à gauche //joystick gauche
|
||||
token.translate(new Vector3f (5*speed * gamepadAxes.get(2), 0.0f, 0.0f));
|
||||
if ( gamepadAxes.get(2) < -0.1 ){
|
||||
token.setTextureWrap(121,0,57,80);
|
||||
token.setTextureWrap(121,0,57,80, ObjectGl.DEFAULT);
|
||||
}else if (gamepadAxes.get(2) > 0.1) {
|
||||
token.setTextureWrap(178,0,62,82);
|
||||
token.setTextureWrap(178,0,62,82, ObjectGl.DEFAULT);
|
||||
}
|
||||
}
|
||||
|
||||
@ -266,19 +266,27 @@ public class Engine {
|
||||
}
|
||||
|
||||
public static void input(ObjectGl token, int speed) {
|
||||
if (Input.isKeyDown(GLFW.GLFW_KEY_W)) {
|
||||
token.scale(new Vector3f (1.01f, 1.01f, 0.0f));
|
||||
boolean keyPressed = false;
|
||||
if (Input.isKeyDown(GLFW.GLFW_KEY_S)) {
|
||||
token.setTextureWrap(161,260,56,59, ObjectGl.STICK_BOTTOM);
|
||||
keyPressed = true;
|
||||
} else if (Input.isKeyDown(GLFW.GLFW_KEY_W)) {
|
||||
// token.translate(new Vector3f (0.0f, speed * 5.0f, 0.0f));
|
||||
keyPressed = true;
|
||||
}
|
||||
if (Input.isKeyDown(GLFW.GLFW_KEY_A)) {
|
||||
token.translate(new Vector3f (speed *-5.0f, 0.0f, 0.0f));
|
||||
token.setTextureWrap(121,0,57,80);
|
||||
// token.setTextureWrap(121,0,57,80, ObjectGl.STICK_TOP);
|
||||
token.setTextureWrap(121,0,57,82, ObjectGl.STICK_TOP);
|
||||
keyPressed = true;
|
||||
}
|
||||
if (Input.isKeyDown(GLFW.GLFW_KEY_S)) {
|
||||
token.setTextureWrap(161,260,56,59);
|
||||
}
|
||||
if (Input.isKeyDown(GLFW.GLFW_KEY_D)) {
|
||||
else if (Input.isKeyDown(GLFW.GLFW_KEY_D)) {
|
||||
token.translate(new Vector3f (speed * 5.0f, 0.0f, 0.0f));
|
||||
token.setTextureWrap(178,0,62,82);
|
||||
// token.setTextureWrap(178,0,62,82, ObjectGl.STICK_TOP);
|
||||
token.setTextureWrap(178,0,62,82, ObjectGl.STICK_TOP);
|
||||
keyPressed = true;
|
||||
}
|
||||
// if (!keyPressed) token.setTextureWrap(58,0,62,84, ObjectGl.STICK_TOP);
|
||||
if (!keyPressed) token.setTextureWrap(58,0,62,82, ObjectGl.STICK_TOP);
|
||||
}
|
||||
}
|
||||
|
@ -8,6 +8,13 @@ import engine.math.*;
|
||||
*/
|
||||
public class ObjectGl {
|
||||
|
||||
/**
|
||||
* STATE CONST DECLARATION
|
||||
*/
|
||||
public static final int DEFAULT = 0, STICK_BOTTOM = 1, STICK_TOP = 2;
|
||||
|
||||
private int stick_state;
|
||||
|
||||
protected VertexArray vertexArray;
|
||||
protected Shader shader;
|
||||
protected Matrix4f transform;
|
||||
@ -58,16 +65,17 @@ public class ObjectGl {
|
||||
this.scalingFactor = size;
|
||||
this.transform = Matrix4f.identity();
|
||||
this.scale(new Vector3f(size, size,1f));
|
||||
this.stick_state = DEFAULT;
|
||||
|
||||
// use different shader for each set of option
|
||||
if (tex == null && color == null){
|
||||
this.shader = new Shader("shaders/ObjectGl/vert.glsl","shaders/ObjectGl/frag.glsl");
|
||||
} else if (tex == null){
|
||||
this.shader = new Shader("shaders/ObjectGlColor/vert.glsl","shaders/ObjectGlColor/frag.glsl"); // TODO
|
||||
this.shader = new Shader("shaders/ObjectGlColor/vert.glsl","shaders/ObjectGlColor/frag.glsl");
|
||||
} else if (color == null){
|
||||
this.shader = new Shader("shaders/ObjectGlTex/vert.glsl","shaders/ObjectGlTex/frag.glsl");
|
||||
} else {
|
||||
this.shader = new Shader("shaders/ObjectGlTexColor/vert.glsl","shaders/ObjectGlTexColor/frag.glsl"); // TODO
|
||||
this.shader = new Shader("shaders/ObjectGlTexColor/vert.glsl","shaders/ObjectGlTexColor/frag.glsl");
|
||||
}
|
||||
}
|
||||
|
||||
@ -138,8 +146,21 @@ public class ObjectGl {
|
||||
* @param w the length of the wrapping on the horizontal axis
|
||||
* @param h the length of the wrapping on the vertical axis
|
||||
*/
|
||||
public void setTextureWrap(float x, float y, float w, float h){
|
||||
public void setTextureWrap(float x, float y, float w, float h, int sticky){
|
||||
// TODO set sticky property + precision issue
|
||||
if (this.stick_state != sticky){ // Check if we're using a new dimension
|
||||
if (sticky == STICK_BOTTOM){
|
||||
this.stick_state = STICK_BOTTOM;
|
||||
this.translate(new Vector3f(0.0f, (h - this.height)*this.scalingFactor, 0.0f));
|
||||
} else if (sticky == STICK_TOP){
|
||||
this.stick_state = STICK_TOP;
|
||||
this.translate(new Vector3f(0.0f, (h - this.height)*this.scalingFactor, 0.0f));
|
||||
} else {
|
||||
this.stick_state = DEFAULT;
|
||||
}
|
||||
}
|
||||
this.height = h;
|
||||
this.width = w;
|
||||
this.vertexArray.swapVertexBufferObject(Primitive.createRectangle(this.zPos, w, h));
|
||||
int texWidth = this.texture.getWidth();
|
||||
int texHeight = this.texture.getHeight();
|
||||
|
Loading…
x
Reference in New Issue
Block a user