这是我的代码:
import java.applet.AudioClip;
import java.awt.Color;
import java.awt.Font;
import java.awt.event.KeyEvent;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import acm.graphics.GLabel;
import acm.program.GraphicsProgram;
import javax.imageio.ImageIO;
import acm.util.MediaTools;
public class FlappyBird extends GraphicsProgram {
public Background background; //background image
public UpTube uptube; //one of the pipes
public DownTube downtube; //other pipe
public Bird bird;
//image for the bird
public static final int APPLICATION_WIDTH = 882;
public static final int APPLICATION_HEIGHT = 772;
public void run(){
addKeyListeners();
background = new Background();
add(background);
uptube = new UpTube();
add(uptube);
downtube = new DownTube();
add(downtube);
bird = new Bird();
add(bird);
public void jump(){
for(int i =0;i<5;i++){
bird.move(3,-7);
pause(100);
}
for(int i =0;i<15;i++){
bird.move(5, -4);
pause(100);
}
for(int i =0;i<15;i++){
bird.move(7,0);
pause(100);
}
for(int i =0;i<15;i++){
bird.move(5,7);
pause(100);
}
for(int i =0;i<15;i++){
bird.move(3,-7);
pause(100);
}
}
public void keyPressed(KeyEvent e){
if(e.getKeyCode() == KeyEvent.VK_SPACE){
jump();
但是,当我运行它并按下空格键时,它不会显示鸟的个人动作,它只是在pause(100)
每个for
语句结束后将鸟传送到结束位置。我如何让它在我每次移动它时更新鸟的位置?