游戏按键问题
小弟做了个游戏,在操作精灵时 如同时按下两个方向健 精灵就斜着走 这个问题应怎样解决,各位大哥帮帮忙。
我的代码如下:
package hello;
import
java.io.IOException;
import java.io.InputStream;
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import javax.microedition.midlet.MIDlet;
import java.util.Random;
import javax.microedition.lcdui.game.*;
/**
*
* @author wjs5-8
* @version
*/
public class Midlet extends MIDlet implements CommandListener
{
private Display display;
private deycanvas maincanvas;
private Command exitCommand=new Command( "退出 ",Command.EXIT,1);
public void startApp() {
if(display==null)
{display=Display.getDisplay(this);
maincanvas=new deycanvas();
maincanvas.addCommand(exitCommand);
maincanvas.setCommandListener(this);
new Thread(maincanvas).start();
display.setCurrent(maincanvas);
}
}
public void pauseApp() {
}
public void destroyApp(boolean unconditional) {
}
public void commandAction(Command cmd,Displayable displayable){
if(cmd==exitCommand)
{
destroyApp(false);
notifyDestroyed();
}
}
}
class deycanvas extends GameCanvas implements Runnable{
public int action;
public boolean leftPressed,righrPressed,stop,upPressed,downPressed;
private int width;//屏幕宽度
private int height;//屏幕高
private int x,y,vx,vy;
public static final int BLUE = 0x000000ff;
public Graphics g;
private Sprite spriteTank;
private Sprite diren;
private Sprite spr;
private Sprite spl;
private Sprite spu;
private Sprite spd;
private boolean zhuangtai=false;
deycanvas()
{ super(true);
g=getGraphics();