我 st忙执行2个估算框架(链接——2号,随后是链接——1号),然后将<代码>d加以修改。 它只是执行一个估算框架(链接_frame_2_face_right.png)。
Here s the code:
import java.awt.Point;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import acm.graphics.GImage;
import acm.graphics.GPoint;
import acm.program.GraphicsProgram;
public class LinkGame extends GraphicsProgram {
public void run(){
setSize(APPLICATION_WIDTH, APPLICATION_HEIGHT);
addLink();
addKeyListeners();
addMouseListeners();
}
private void addLink(){
linkCharacter = new GImage("link sprites/link_frame_1_face_right.png");
add(linkCharacter,link_Location_XCoord,link_Location_YCoord);
}
public void keyPressed(KeyEvent e){
char linkMoveRightKey = e.getKeyChar();
if(linkMoveRightKey == d ){
// y should not change so goku moves in a straight line
link_Location_YCoord = 0;
linkCharacter.move(link_Location_XCoord,link_Location_YCoord);
set_Link_Anim_Frame_2_face_left();
}
}
public void set_Link_Anim_Frame_2_face_left(){
linkCharacter.setImage("link sprites/link_frame_2_face_right.png");
}
public void set_Link_Anim_Frame_1_face_left(){
linkCharacter.setImage("link sprites/link_frame_1_face_right.png");
}
private GImage linkCharacter;
private int link_Location_XCoord = 50;
private int link_Location_YCoord = 50 ;
private final int APPLICATION_WIDTH = 600;
private final int APPLICATION_HEIGHT = 600;
}