package ru.dmitriymx.game; import org.lwjgl.opengl.GL11; public class Foxy { private Sprite tex_idle, tex_run; private Sprite current_texture; private int x, y; private int state; private boolean inverse = false; public Foxy(){ 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; } public boolean getInverse(){ return inverse; } /** * Состояние персонажа.
* 0 - idle - стоит на месте * 1 - run - бежит */ public void setState(int value){ state = value; if(value == 0){ current_texture = tex_idle; } else if(value == 1){ current_texture = tex_run; } current_texture.setFrame(0); } public void setX(int value){ x = value; } public int getX(){ return x; } public void setY(int value){ y = value; } public int getY(){ return y; } public int getState(){ return state; } public void render(){ Sprite.Coords frame = current_texture.getFrame(); final int K = 4; GL11.glColor3f(1f, 1f, 1f); current_texture.bind(); GL11.glBegin(GL11.GL_QUADS); if(inverse){ GL11.glTexCoord2f(current_texture.floatX(frame.x2), current_texture.floatY(frame.y1)); GL11.glVertex2f(x, y); GL11.glTexCoord2f(current_texture.floatX(frame.x1), current_texture.floatY(frame.y1)); GL11.glVertex2f(x + current_texture.getWidthSprite()*K, y); GL11.glTexCoord2f(current_texture.floatX(frame.x1), current_texture.floatY(frame.y2)); GL11.glVertex2f(x + current_texture.getWidthSprite()*K, y + current_texture.getHeightSprite()*K); GL11.glTexCoord2f(current_texture.floatX(frame.x2), current_texture.floatY(frame.y2)); GL11.glVertex2f(x, y + current_texture.getHeightSprite()*K); } else { GL11.glTexCoord2f(current_texture.floatX(frame.x1), current_texture.floatY(frame.y1)); GL11.glVertex2f(x, y); GL11.glTexCoord2f(current_texture.floatX(frame.x2), current_texture.floatY(frame.y1)); GL11.glVertex2f(x + current_texture.getWidthSprite()*K, y); GL11.glTexCoord2f(current_texture.floatX(frame.x2), current_texture.floatY(frame.y2)); GL11.glVertex2f(x + current_texture.getWidthSprite()*K, y + current_texture.getHeightSprite()*K); GL11.glTexCoord2f(current_texture.floatX(frame.x1), current_texture.floatY(frame.y2)); GL11.glVertex2f(x, y + current_texture.getHeightSprite()*K); } GL11.glEnd(); current_texture.nextFrame(); } }