packagecom.swift;importjava.awt.Point;importjava.awt.event.KeyEvent;importcom.rupeng.game.GameCore;public class PlayWithKey implementsRunnable{public static voidmain(String[] args) {
GameCore.start(newPlayWithKey());
}
@Overridepublic voidrun() {
GameCore.setGameSize(800, 345);
GameCore.setGameTitle("用键盘操控精灵移动的小游戏");
GameCore.loadBgView("bg.jpg");int spriteGirl=0;
GameCore.createSprite(spriteGirl,"guizi");
GameCore.playSpriteAnimate(spriteGirl,"run", true);
GameCore.setSpritePosition(spriteGirl,140, 190);for(;;) {int codeNum=GameCore.getPressedKeyCode();
System.out.println(codeNum);
Point position=GameCore.getSpritePosition(spriteGirl);
System.out.println(position.x+" "+position.y);if(codeNum==KeyEvent.VK_UP||codeNum==KeyEvent.VK_W) {if(position.y>135) {
System.out.println("up");
GameCore.setSpritePosition(spriteGirl, position.x,--position.y);
GameCore.pause(11);
}
}if(codeNum==KeyEvent.VK_DOWN||codeNum==KeyEvent.VK_S) {if(position.y<190) {
System.out.println("down");
GameCore.setSpritePosition(spriteGirl, position.x,++position.y);
GameCore.pause(11);
}
}if(codeNum==KeyEvent.VK_LEFT||codeNum==KeyEvent.VK_A) {
System.out.println("left");
GameCore.setSpriteFlipX(spriteGirl,true);
GameCore.setSpritePosition(spriteGirl,--position.x, position.y);
GameCore.pause(2);
}if(codeNum==KeyEvent.VK_RIGHT||codeNum==KeyEvent.VK_D) {
System.out.println("right");
GameCore.setSpriteFlipX(spriteGirl,false);
GameCore.setSpritePosition(spriteGirl,++position.x,position.y);
GameCore.pause(1);
}
}//GameCore.pause(10000);
}
}