在我简单的乒乓游戏中,每当用户滑块向下移动时,它也会变得更胖。对不起,如果很明显,这是代码。
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绘制矩形。随意更正任何其他错误/错误的代码。
答案 0 :(得分:0)
好的,这是一个愚蠢的错误我很惊讶没有人可以发现 - 我把getX()而不是getY()。