feature(foxy) Поворот текстуры по направлению движения персонажа
This commit is contained in:
@@ -5,12 +5,17 @@ import org.lwjgl.opengl.GL11;
|
||||
public class Foxy {
|
||||
private Sprite texture;
|
||||
private int x, y;
|
||||
private boolean inverse = false;
|
||||
|
||||
public Foxy(){
|
||||
texture = new Sprite(Foxy.class.getResourceAsStream("/ru/dmitriymx/game/foxy2.png"), 38, 33);
|
||||
x = y = 0;
|
||||
}
|
||||
|
||||
public void setInverse(boolean value){
|
||||
inverse = value;
|
||||
}
|
||||
|
||||
public void render(){
|
||||
Sprite.Coords frame = texture.getFrame();
|
||||
final int K = 2;
|
||||
@@ -20,17 +25,31 @@ public class Foxy {
|
||||
|
||||
GL11.glBegin(GL11.GL_QUADS);
|
||||
|
||||
GL11.glTexCoord2f(texture.floatX(frame.x1),texture.floatY(frame.y1));
|
||||
GL11.glVertex2f(0, 0);
|
||||
if(inverse){
|
||||
GL11.glTexCoord2f(texture.floatX(frame.x2),texture.floatY(frame.y1));
|
||||
GL11.glVertex2f(0, 0);
|
||||
|
||||
GL11.glTexCoord2f(texture.floatX(frame.x2),texture.floatY(frame.y1));
|
||||
GL11.glVertex2f(texture.getWidthSprite()*K, 0);
|
||||
GL11.glTexCoord2f(texture.floatX(frame.x1),texture.floatY(frame.y1));
|
||||
GL11.glVertex2f(texture.getWidthSprite()*K, 0);
|
||||
|
||||
GL11.glTexCoord2f(texture.floatX(frame.x2),texture.floatY(frame.y2));
|
||||
GL11.glVertex2f(texture.getWidthSprite()*K, texture.getHeightSprite()*K);
|
||||
GL11.glTexCoord2f(texture.floatX(frame.x1),texture.floatY(frame.y2));
|
||||
GL11.glVertex2f(texture.getWidthSprite()*K, texture.getHeightSprite()*K);
|
||||
|
||||
GL11.glTexCoord2f(texture.floatX(frame.x1),texture.floatY(frame.y2));
|
||||
GL11.glVertex2f(0, texture.getHeightSprite()*K);
|
||||
GL11.glTexCoord2f(texture.floatX(frame.x2),texture.floatY(frame.y2));
|
||||
GL11.glVertex2f(0, texture.getHeightSprite()*K);
|
||||
} else {
|
||||
GL11.glTexCoord2f(texture.floatX(frame.x1),texture.floatY(frame.y1));
|
||||
GL11.glVertex2f(0, 0);
|
||||
|
||||
GL11.glTexCoord2f(texture.floatX(frame.x2),texture.floatY(frame.y1));
|
||||
GL11.glVertex2f(texture.getWidthSprite()*K, 0);
|
||||
|
||||
GL11.glTexCoord2f(texture.floatX(frame.x2),texture.floatY(frame.y2));
|
||||
GL11.glVertex2f(texture.getWidthSprite()*K, texture.getHeightSprite()*K);
|
||||
|
||||
GL11.glTexCoord2f(texture.floatX(frame.x1),texture.floatY(frame.y2));
|
||||
GL11.glVertex2f(0, texture.getHeightSprite()*K);
|
||||
}
|
||||
|
||||
GL11.glEnd();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user