2014-02-08 3 views
0

저는 현재 LWJGL을 사용하여 약간의 게임을 만들고 있습니다. 게임 루프, 인스턴스 등을 포함하는 Game 클래스가 있습니다. (x 및 y 좌표에 대한) 생성자를 포함하는 Player 클래스, 계산을위한 논리 방법, 키 누름 등 ... 그리고 화면에서 플레이어를 그리는 렌더 방법. 어떤 이유에서 UP 키 (Key.UP)를 누르면 플레이어가 바닥으로 점프하고 바닥으로 올라갑니다 (뒤집어서 위로 뛰다가 바닥으로 떨어지는 것 대신에). 문제가 무엇인지 말할 수 있다면 정말 고맙겠습니다.LWJGL 아래로 점프

Game.java :

import static org.lwjgl.opengl.GL11.*; 

import java.io.IOException; 

import org.lwjgl.LWJGLException; 
import org.lwjgl.input.Keyboard; 
import org.lwjgl.opengl.Display; 
import org.lwjgl.opengl.DisplayMode; 
import org.newdawn.slick.opengl.Texture; 
import org.newdawn.slick.opengl.TextureLoader; 
import org.newdawn.slick.util.ResourceLoader; 


public class Game { 

    static Texture bgTexture; 

    static Player player; 

    public static void main(String[] args) throws LWJGLException, IOException { 
     // Initialize 
     Display.setDisplayMode(new DisplayMode(640, 480)); 
     Display.create(); 

     glEnable(GL_TEXTURE_2D); 
     glClearColor(0.0f, 0.0f, 0.0f, 0.0f); 
     glEnable(GL_BLEND); 
     glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); 
     glViewport(0, 0, 640, 480); 
     glMatrixMode(GL_PROJECTION); 
     glLoadIdentity(); 
     glOrtho(0, 640, 480, 0, 1, -1); 
     glMatrixMode(GL_MODELVIEW); 

     bgTexture = TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream("res/background.png")); 

     player = new Player(50, 200 - 64); 

     while (!Display.isCloseRequested()) { 
      glClear(GL_COLOR_BUFFER_BIT); 

      drawBackground(); 
      player.render(); 

      Display.update(); 
      Display.sync(60); 

      if (Keyboard.isKeyDown(Keyboard.KEY_ESCAPE)) { 
       Display.destroy(); 
       System.exit(0); 
      } 
     } 
    } 

    public static void drawBackground() { 
     bgTexture.bind(); 

     glBegin(GL_QUADS); 
     glTexCoord2f(0, 0); 
     glVertex2f(0, 0); 
     glTexCoord2f(1, 0); 
     glVertex2f(bgTexture.getTextureWidth(), 0); 
     glTexCoord2f(1, 1); 
     glVertex2f(bgTexture.getTextureWidth(), bgTexture.getTextureHeight()); 
     glTexCoord2f(0, 1); 
     glVertex2f(0, bgTexture.getTextureHeight()); 
     glEnd(); 
    } 

} 

Player.java

import static org.lwjgl.opengl.GL11.*; 

import java.io.IOException; 

import org.lwjgl.input.Keyboard; 
import org.newdawn.slick.opengl.Texture; 
import org.newdawn.slick.opengl.TextureLoader; 
import org.newdawn.slick.util.ResourceLoader; 


public class Player { 

    public double x, y, xspeed, yspeed; 

    private Texture pTexture; 

    public Player(double x, double y) throws IOException { 
     this.x = x; 
     this.y = y; 
     pTexture = TextureLoader.getTexture("PNG", ResourceLoader.getResourceAsStream("res/player.png")); 
    } 

    public void logic() { 
     x += xspeed; 
     y += yspeed; 

     yspeed -= 0.4; 

     // Collision detection 
     if (y <= 480 - 64) { 
      y = 480 - 64; 
      yspeed = 0; 

      if (!Keyboard.isKeyDown(Keyboard.KEY_RIGHT) && xspeed > 0) xspeed = xspeed * 0.7; 
      if (!Keyboard.isKeyDown(Keyboard.KEY_LEFT) && xspeed < 0) xspeed = xspeed * 0.7; 
      if (Keyboard.isKeyDown(Keyboard.KEY_UP)) yspeed = 8; 
     } 

     // Moving 
     if (Keyboard.isKeyDown(Keyboard.KEY_RIGHT)) xspeed = 4; 
     if (Keyboard.isKeyDown(Keyboard.KEY_LEFT)) xspeed = -4; 
    } 

    public void render() { 
     logic(); 

     glPushMatrix(); 
     pTexture.bind(); 
     glTranslated(x, y, 0); 

     glBegin(GL_QUADS); 
     glTexCoord2d(0, 0); 
     glVertex2d(0, 0); 
     glTexCoord2d(1, 0); 
     glVertex2d(pTexture.getTextureWidth(), 0); 
     glTexCoord2d(1, 1); 
     glVertex2d(pTexture.getTextureWidth(), pTexture.getTextureHeight()); 
     glTexCoord2d(0, 1); 
     glVertex2d(0, pTexture.getTextureHeight()); 
     glEnd(); 

     glPopMatrix(); 
    } 

} 

너무 감사합니다.

답변

0

glOrtho(0, 640, 480, 0, 1, -1);을 호출하면 화면 하단에 480, 상단에는 0이 설정됩니다. 대신 glOrtho(0, 640, 0, 480, 1, -1);을 사용하면 y 값이 클수록 화면상의 더 높은 지점을 의미하게됩니다. 이는 내가 생각하기를 원하는 것입니다.