LWJGL矩形越往下越宽



在我的简单乒乓球游戏中,每当用户滑块向下移动时,它也会变得更胖。很抱歉,如果很明显,这是代码。

         int motionup = 0;
         int moionright = -2;
         Rectangle bouncer1 = new Rectangle(0,0,10,100);
         Rectangle bouncer2 = new Rectangle(WINDOWWIDTH - 10, 0, 10, 100);
         Rectangle ball = new Rectangle(WINDOWWIDTH / 2, WINDOWHIGHT / 2, 10 , 10);
        public void timeHandle(){
                switch(state){
                case Game:
                        bouncer1.setY(bouncer1.getY() + motionup);
                        bouncer1.translate(0, motionup);
                        //bouncer1.setWidth(10);
                        motionup = 0;
                        break;
                }
        }
        public void keyHandle(){
                switch(state){
                case Game:
                        if(Keyboard.isKeyDown(Keyboard.KEY_ESCAPE)){
                                state = Stater.Menu;
                                this.esc = true;
                        } else if(isKeyDown(KEY_DOWN) && bouncer1.getY() != WINDOWHIGHT - bouncer1.getHeight()){
                                if(true){
                                        motionup += 1;
                                }
                        } else if(isKeyDown(KEY_UP) && bouncer1.getY() != 0){
                                motionup -= 1;
                        }
                        break;
                }
        }
        public void render(){
                switch(state){
                case Game:
                        float b1Y = bouncer1.getY();
                        float b1X = bouncer1.getX();
                        float b2Y = bouncer2.getY();
                        float b2X = bouncer2.getX();
                        glColor3f(0f, 0f, 1.0f);
                        glRectf(0f, 0f, WINDOWWIDTH, WINDOWHIGHT);
                        glColor3f(1f, 1f, 1f);
                        glRectf(b1Y, b1Y, b1X + bouncer1.getWidth(), b1Y + bouncer1.getHeight());
                        glRectf(b2X, b2Y, b2X + bouncer2.getWidth(), b2Y + bouncer2.getHeight());
                        glRectf(ball.getX(), ball.getY(), ball.getX() + ball.getWidth(), ball.getY() + ball.getHeight());
                        break;
                }
        }
                    public static void main(String[] args) {
                Pong a = new Pong();
                a.LWJGLhelloa();
        }
}

我使用Rectangle类来保存数据,然后用glrectf和点来绘制矩形。请随时更正任何其他错误/错误代码。

好吧,这是一个愚蠢的错误,我很惊讶没有人能发现——我放了getX()而不是getY()。

相关内容

  • 没有找到相关文章

最新更新