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,6 +25,19 @@ public class Foxy {
|
||||
|
||||
GL11.glBegin(GL11.GL_QUADS);
|
||||
|
||||
if(inverse){
|
||||
GL11.glTexCoord2f(texture.floatX(frame.x2),texture.floatY(frame.y1));
|
||||
GL11.glVertex2f(0, 0);
|
||||
|
||||
GL11.glTexCoord2f(texture.floatX(frame.x1),texture.floatY(frame.y1));
|
||||
GL11.glVertex2f(texture.getWidthSprite()*K, 0);
|
||||
|
||||
GL11.glTexCoord2f(texture.floatX(frame.x1),texture.floatY(frame.y2));
|
||||
GL11.glVertex2f(texture.getWidthSprite()*K, 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);
|
||||
|
||||
@@ -31,6 +49,7 @@ public class Foxy {
|
||||
|
||||
GL11.glTexCoord2f(texture.floatX(frame.x1),texture.floatY(frame.y2));
|
||||
GL11.glVertex2f(0, texture.getHeightSprite()*K);
|
||||
}
|
||||
|
||||
GL11.glEnd();
|
||||
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package ru.dmitriymx.game;
|
||||
|
||||
import org.lwjgl.LWJGLException;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
import org.lwjgl.opengl.Display;
|
||||
import org.lwjgl.opengl.DisplayMode;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
@@ -33,6 +34,14 @@ public class Main {
|
||||
}
|
||||
|
||||
private void render(){
|
||||
while(Keyboard.next()){
|
||||
if(Keyboard.getEventKey() == Keyboard.KEY_LEFT){
|
||||
foxy.setInverse(true);
|
||||
} else if (Keyboard.getEventKey() == Keyboard.KEY_RIGHT){
|
||||
foxy.setInverse(false);
|
||||
}
|
||||
}
|
||||
|
||||
foxy.render();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user