feature(foxy) По нажатию клавиши, изменяется состояние бег-простой
This commit is contained in:
@@ -3,56 +3,72 @@ package ru.dmitriymx.game;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
public class Foxy {
|
||||
private Sprite texture;
|
||||
private Sprite tex_idle, tex_run;
|
||||
private Sprite current_texture;
|
||||
private int x, y;
|
||||
private boolean inverse = false;
|
||||
|
||||
public Foxy(){
|
||||
texture = new Sprite(Foxy.class.getResourceAsStream("/ru/dmitriymx/game/foxy2.png"), 38, 33);
|
||||
tex_idle = new Sprite(Foxy.class.getResourceAsStream("/ru/dmitriymx/game/foxy2.png"), 38, 33);
|
||||
tex_run = new Sprite(Foxy.class.getResourceAsStream("/ru/dmitriymx/game/foxy4.png"), 44, 32);
|
||||
x = y = 0;
|
||||
setState(0);
|
||||
}
|
||||
|
||||
public void setInverse(boolean value){
|
||||
inverse = value;
|
||||
}
|
||||
|
||||
/**
|
||||
* Состояние персонажа.<br/>
|
||||
* 0 - idle - стоит на месте
|
||||
* 1 - run - бежит
|
||||
*/
|
||||
public void setState(int value){
|
||||
if(value == 0){
|
||||
current_texture = tex_idle;
|
||||
} else if(value == 1){
|
||||
current_texture = tex_run;
|
||||
}
|
||||
}
|
||||
|
||||
public void render(){
|
||||
Sprite.Coords frame = texture.getFrame();
|
||||
Sprite.Coords frame = current_texture.getFrame();
|
||||
final int K = 2;
|
||||
|
||||
GL11.glColor3f(1f, 1f, 1f);
|
||||
texture.bind();
|
||||
current_texture.bind();
|
||||
|
||||
GL11.glBegin(GL11.GL_QUADS);
|
||||
|
||||
if(inverse){
|
||||
GL11.glTexCoord2f(texture.floatX(frame.x2),texture.floatY(frame.y1));
|
||||
GL11.glTexCoord2f(current_texture.floatX(frame.x2), current_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(current_texture.floatX(frame.x1), current_texture.floatY(frame.y1));
|
||||
GL11.glVertex2f(current_texture.getWidthSprite()*K, 0);
|
||||
|
||||
GL11.glTexCoord2f(texture.floatX(frame.x1),texture.floatY(frame.y2));
|
||||
GL11.glVertex2f(texture.getWidthSprite()*K, texture.getHeightSprite()*K);
|
||||
GL11.glTexCoord2f(current_texture.floatX(frame.x1), current_texture.floatY(frame.y2));
|
||||
GL11.glVertex2f(current_texture.getWidthSprite()*K, current_texture.getHeightSprite()*K);
|
||||
|
||||
GL11.glTexCoord2f(texture.floatX(frame.x2),texture.floatY(frame.y2));
|
||||
GL11.glVertex2f(0, texture.getHeightSprite()*K);
|
||||
GL11.glTexCoord2f(current_texture.floatX(frame.x2), current_texture.floatY(frame.y2));
|
||||
GL11.glVertex2f(0, current_texture.getHeightSprite()*K);
|
||||
} else {
|
||||
GL11.glTexCoord2f(texture.floatX(frame.x1),texture.floatY(frame.y1));
|
||||
GL11.glTexCoord2f(current_texture.floatX(frame.x1), current_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(current_texture.floatX(frame.x2), current_texture.floatY(frame.y1));
|
||||
GL11.glVertex2f(current_texture.getWidthSprite()*K, 0);
|
||||
|
||||
GL11.glTexCoord2f(texture.floatX(frame.x2),texture.floatY(frame.y2));
|
||||
GL11.glVertex2f(texture.getWidthSprite()*K, texture.getHeightSprite()*K);
|
||||
GL11.glTexCoord2f(current_texture.floatX(frame.x2), current_texture.floatY(frame.y2));
|
||||
GL11.glVertex2f(current_texture.getWidthSprite()*K, current_texture.getHeightSprite()*K);
|
||||
|
||||
GL11.glTexCoord2f(texture.floatX(frame.x1),texture.floatY(frame.y2));
|
||||
GL11.glVertex2f(0, texture.getHeightSprite()*K);
|
||||
GL11.glTexCoord2f(current_texture.floatX(frame.x1), current_texture.floatY(frame.y2));
|
||||
GL11.glVertex2f(0, current_texture.getHeightSprite()*K);
|
||||
}
|
||||
|
||||
GL11.glEnd();
|
||||
|
||||
texture.nextFrame();
|
||||
current_texture.nextFrame();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user