LWJGL Rectangle gets wider further down

93 views Asked by At

In my simple game of pong, whenever the user slider moves down it also gets fatter. Sorry if it's obvious, here's the code.

         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();

        }
}

I use a Rectangle class to hold the data, and then glrectf with the points to draw the rectangle. Feel free to correct any other mistakes/ bad code.

1

There are 1 answers

0
Ben Hack On BEST ANSWER

Ok, it was a silly mistake I am surprised no-one could spot- I put getX() instead of getY().