Archived
0

feature(foxy) Персонаж умеет бегать

This commit is contained in:
2013-10-09 15:09:14 +04:00
parent 230e893e22
commit 142816a06a
3 changed files with 49 additions and 10 deletions

View File

@@ -6,6 +6,7 @@ public class Foxy {
private Sprite tex_idle, tex_run; private Sprite tex_idle, tex_run;
private Sprite current_texture; private Sprite current_texture;
private int x, y; private int x, y;
private int state;
private boolean inverse = false; private boolean inverse = false;
public Foxy(){ public Foxy(){
@@ -19,22 +20,48 @@ public class Foxy {
inverse = value; inverse = value;
} }
public boolean getInverse(){
return inverse;
}
/** /**
* Состояние персонажа.<br/> * Состояние персонажа.<br/>
* 0 - idle - стоит на месте * 0 - idle - стоит на месте
* 1 - run - бежит * 1 - run - бежит
*/ */
public void setState(int value){ public void setState(int value){
state = value;
if(value == 0){ if(value == 0){
current_texture = tex_idle; current_texture = tex_idle;
} else if(value == 1){ } else if(value == 1){
current_texture = tex_run; 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(){ public void render(){
Sprite.Coords frame = current_texture.getFrame(); Sprite.Coords frame = current_texture.getFrame();
final int K = 2; final int K = 4;
GL11.glColor3f(1f, 1f, 1f); GL11.glColor3f(1f, 1f, 1f);
current_texture.bind(); current_texture.bind();
@@ -43,28 +70,28 @@ public class Foxy {
if(inverse){ if(inverse){
GL11.glTexCoord2f(current_texture.floatX(frame.x2), current_texture.floatY(frame.y1)); GL11.glTexCoord2f(current_texture.floatX(frame.x2), current_texture.floatY(frame.y1));
GL11.glVertex2f(0, 0); GL11.glVertex2f(x, 0);
GL11.glTexCoord2f(current_texture.floatX(frame.x1), current_texture.floatY(frame.y1)); GL11.glTexCoord2f(current_texture.floatX(frame.x1), current_texture.floatY(frame.y1));
GL11.glVertex2f(current_texture.getWidthSprite()*K, 0); GL11.glVertex2f(x + current_texture.getWidthSprite()*K, 0);
GL11.glTexCoord2f(current_texture.floatX(frame.x1), current_texture.floatY(frame.y2)); GL11.glTexCoord2f(current_texture.floatX(frame.x1), current_texture.floatY(frame.y2));
GL11.glVertex2f(current_texture.getWidthSprite()*K, current_texture.getHeightSprite()*K); GL11.glVertex2f(x + current_texture.getWidthSprite()*K, current_texture.getHeightSprite()*K);
GL11.glTexCoord2f(current_texture.floatX(frame.x2), current_texture.floatY(frame.y2)); GL11.glTexCoord2f(current_texture.floatX(frame.x2), current_texture.floatY(frame.y2));
GL11.glVertex2f(0, current_texture.getHeightSprite()*K); GL11.glVertex2f(x, current_texture.getHeightSprite()*K);
} else { } else {
GL11.glTexCoord2f(current_texture.floatX(frame.x1), current_texture.floatY(frame.y1)); GL11.glTexCoord2f(current_texture.floatX(frame.x1), current_texture.floatY(frame.y1));
GL11.glVertex2f(0, 0); GL11.glVertex2f(x, 0);
GL11.glTexCoord2f(current_texture.floatX(frame.x2), current_texture.floatY(frame.y1)); GL11.glTexCoord2f(current_texture.floatX(frame.x2), current_texture.floatY(frame.y1));
GL11.glVertex2f(current_texture.getWidthSprite()*K, 0); GL11.glVertex2f(x + current_texture.getWidthSprite()*K, 0);
GL11.glTexCoord2f(current_texture.floatX(frame.x2), current_texture.floatY(frame.y2)); GL11.glTexCoord2f(current_texture.floatX(frame.x2), current_texture.floatY(frame.y2));
GL11.glVertex2f(current_texture.getWidthSprite()*K, current_texture.getHeightSprite()*K); GL11.glVertex2f(x + current_texture.getWidthSprite()*K, current_texture.getHeightSprite()*K);
GL11.glTexCoord2f(current_texture.floatX(frame.x1), current_texture.floatY(frame.y2)); GL11.glTexCoord2f(current_texture.floatX(frame.x1), current_texture.floatY(frame.y2));
GL11.glVertex2f(0, current_texture.getHeightSprite()*K); GL11.glVertex2f(x, current_texture.getHeightSprite()*K);
} }
GL11.glEnd(); GL11.glEnd();

View File

@@ -52,6 +52,14 @@ public class Main {
} }
} }
final int speed = 5 * 4;
if(foxy.getState() == 1){
if(foxy.getInverse()){
foxy.setX(foxy.getX() - speed);
} else {
foxy.setX(foxy.getX() + speed);
}
}
foxy.render(); foxy.render();
} }
@@ -65,7 +73,7 @@ public class Main {
GL11.glClear(GL11.GL_COLOR_BUFFER_BIT); GL11.glClear(GL11.GL_COLOR_BUFFER_BIT);
render(); render();
Display.update(); Display.update();
Display.sync(12); Display.sync(15);
} }
Display.destroy(); Display.destroy();

View File

@@ -47,6 +47,10 @@ public class Sprite extends Texture {
return frame[current_frame]; return frame[current_frame];
} }
public void setFrame(int value){
current_frame = value;
}
public void nextFrame(){ public void nextFrame(){
if(current_frame == (max_frames-1)){ if(current_frame == (max_frames-1)){
current_frame = 0; current_frame = 0;