꽤 기초적인 platformer 게임 인 &을 설정했다. 지금 모든 설정이 끝났다.나는 점프의 일관성에 문제가있다.
모든 것이 점핑 외의 다른 모든 기능을 완벽하게 수행합니다. 매우 불규칙한 점프 길이가 발생합니다. 그것들은 매우 짧은 것부터 매우 긴 것까지 다양합니다.
Slick2D, JWJGL 또는 델타 정수로 익숙하지 않습니다. 제발 도와주세요! 당신은 델타하여 점프 속도를 확장 할 필요가
package game;
import org.lwjgl.input.Mouse;
import org.newdawn.slick.*;
import org.newdawn.slick.state.*;
public class LevelOne extends BasicGameState{
Animation walkingLeft, walkingRight, still;
int[] duration = {200,200,200};
Image p;
Image map;
public String mouse = "Mouse not detected";
public String gpos = "null";
public int health = 1000;
float CharX = 0;
float CharY = 0;
float PosX = CharX + 100;
float PosY = CharY + 300;
boolean jumping = false;
float verticalSpeed = 0.0f;
public LevelOne(int state){
}
public void init(GameContainer gc, StateBasedGame sbg)throws SlickException{
p = new Image("res/char.png");
map = new Image("res/map.png");
Image[] Left = {p.getSubImage(0,32,32,32), p.getSubImage(32,32,32,32), p.getSubImage(64,32,32,32)};
Image[] Right = {p.getSubImage(0,64,32,32), p.getSubImage(0,64,32,32), p.getSubImage(0,64,32,32)};
walkingLeft = new Animation(Left, duration, false);
walkingRight = new Animation(Right, duration, false);
still = walkingLeft;
}
public void render(GameContainer gc, StateBasedGame sbg, Graphics g)throws SlickException{
g.setColor(Color.magenta);
g.drawString("Developers Build", 650, 100);
g.setColor(Color.white);
g.drawString(mouse, 650, 150);
g.drawString(gpos,650, 200); //Developers Build Sidebar thing
g.drawString("Class: ", 650, 250);
g.drawString("" + this.getClass(), 670, 270);
g.drawString("State: " + this.getID(), 650, 300);
g.drawString("Stage: Charlie", 650, 350);
g.drawRect(620, 70, 400, 320);
map.draw(CharX, CharY); //Floor
g.setColor(Color.white);
if(health < 500){
g.setColor(Color.red);
}
g.drawString("Health: " + health, 10, 50);
g.setColor(Color.white); //Health & Level
g.drawString("Level: 1", 10, 70);
still.draw(PosX, PosY); //Draw Character
}
public void update(GameContainer gc, StateBasedGame sbg, int delta) throws SlickException{
Input input = gc.getInput();
int MouseX = Mouse.getX();
int MouseY = Mouse.getY();
mouse = "JPos: " + MouseX + " , " + MouseY;
gpos = "GPos: " + MouseX + " , " + (460 - MouseY);
if(input.isKeyDown(Input.KEY_D)){
still = walkingRight;
CharX -= delta * .2f;
}
if(input.isKeyDown(Input.KEY_A)){
still = walkingLeft;
CharX += delta * .2f;
if(CharX > 100){
CharX -= delta *.2f;
}
}
if (input.isKeyPressed(Input.KEY_W) && !jumping) {
verticalSpeed = -1f * delta;//negative value indicates an upward movement
jumping = true;
}
if (jumping) {
verticalSpeed += .0099f * delta;//change this value to alter gravity strength
}
if(PosY > 300){
jumping = false;
verticalSpeed = 0;
PosY = 300;
}
PosY += verticalSpeed;
if(health == 0){
CharX = 0;
health = 1000;
}
}
public int getID(){
return 2;
}
}
고마워요! 그게 내 문제를 해결! –
내 대답은 아마도 당신이 정말로 원하는 것일 것입니다. 이것은 프레임 속도의 변화를 잘 처리하지 못합니다. 속도를 조절하는 데 FPS를 사용하지 않으면 게임이 다른 PC에서 더 느리게 또는 더 빠르게 실행됩니다. –
아니, 당신은 속도의 개념을 이해하지 못합니다. 속도는 0에서 시간 단계로 시간을 통합하여 사용되어야합니다 (여기는 델타 바로 여기). 이것은 단순히 속도 v에서의 운동량이 델타 v *와 같기 때문에 각 프레임을 위치에 추가해야하는 것입니다 : position + = velocity * step. –