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