游戏界面代码

  • 格式:txt
  • 大小:5.64 KB
  • 文档页数:2
import javax.microedition.lcdui.game.GameCanvas;
import javax.microedition.lcdui.game.Sprite;
import javax.microedition.midlet.MIDlet;
import javax.microedition.midlet.MIDletStateChangeException;
{
ex.printStackTrace();
}
new Thread(this).start();
}
public void run() {
while(RUN)
{
if(dir){
dolaimg.move(2,0);
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Display;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
{
private Image img;
private Image img2;
private Image img3;
private int x;
private int y;
//private Graphics gra;
public MyCanvas(){
// TODO 自动生成方法存根
}
protected void startApp() throws MIDletStateChangeException {
dis=Display.getDisplay(this);
ad.setTitle("多啦A梦穿越时空之鲁滨逊游记");
case Canvas.LEFT:x-=4;break;
case Canvas.RIGHT:x+=4;break;
}
if(x<=0){x+=4;
}
if(x>=162){x-=4;
}
if(y<=0){
y+=4;
img6=Image.createImage("/anniua.png");
dolaimg=new Sprite(img,img.getWidth()/4,img.getHeight()/4);
daxiong=new Sprite(img2,img2.getWidth()/4,img2.getHeight()/4);
dis.setCurrent(ad);
try{
Thread.currentThread().sleep(24900);
dis.setCurrent(mc);
}catch(Exቤተ መጻሕፍቲ ባይዱeption ex){}
}
protected void pauseApp() {}
}
if(y>=148){
y-=4;
}
public class lmenu extends MIDlet {
private Adream1 ad=new Adream1();
private MyCanvas mc=new MyCanvas();
private Display dis;
protected void destroyApp(boolean arg0) throws MIDletStateChangeException {
g.drawImage(img2,2,1,Graphics.LEFT|Graphics.TOP);
g.drawImage(img,100,65,Graphics.LEFT|Graphics.TOP);
g.drawImage(img3,x,y,Graphics.LEFT|Graphics.TOP);
dolaimg.setFrameSequence(seq);
daxiong.setFrameSequence(seq);
lubx.setFrameSequence(seq3);
anniu.setFrameSequence(seq2);
gra=this.getGraphics();
}
protected void keyPressed(int keycode){
int action=this.getGameAction(keycode);
switch(action){
case Canvas.UP: y-=4;break;
case Canvas.DOWN:y+=4;break;
img2=Image.createImage("/daxiong.png");
img3=Image.createImage("/lubx.png");
img4=Image.createImage("/door.png");
img5=Image.createImage("/mymenu.png");
dolaimg.nextFrame();
dolaimg.paint(gra);
lubx.nextFrame();
lubx.paint(gra);
door.setFrame(1);
door.paint(gra);
}
else
{
private Sprite door;
private Sprite mymenu;
private Sprite anniu;
private Graphics gra;
private boolean RUN=true;
private boolean dir=true;
private int sum;
public Adream1()
{
super(true);
try{
img=Image.createImage("/dolaimg.png");
mymenu.paint(gra);
anniu.paint(gra);
anniu.nextFrame();
door.setFrame(2);
door.paint(gra);
daxiong.nextFrame();
}
catch(Exception ex){}
}
public void paint(Graphics g){
g.setColor(101,178,237);
g.fillRect(0, 0, this.getWidth(),this.getHeight());
daxiong.paint(gra);
dolaimg.nextFrame();
dolaimg.paint(gra);
lubx.nextFrame();
lubx.paint(gra);
}
this.flushGraphics();
gra.setColor(255,255,255);
daxiong.move(2,0);
lubx.move(2,0);
door.setFrame(0);
door.paint(gra);
anniu.nextFrame();
daxiong.nextFrame();
daxiong.paint(gra);
gra.setColor(101,178,237);
gra.fillRect(0, 0, this.getWidth(),this.getHeight());
daxiong.move(1,0);
lubx.move(-2,-2);
door.move(1,0);
mymenu.move(50,100);
dolaimg.move(50,116);
daxiong.move(25,116);
lubx.move(2,120);
door.move(145,95);
}catch(Exception ex)
try{
y=84;
x=50;
img=Image.createImage("/anniu2.png");
img2=Image.createImage("/mymenu.png");
img3=Image.createImage("/choose.png");
gra.fillRect(0, 0, this.getWidth(),this.getHeight());
if(door.collidesWith(lubx, true)){
dir=false;
sum=35;
}
else{
sum--;
if(sum==0){
RUN=false;
}
}
try{
Thread.currentThread().sleep(200);
}
catch(Exception ex){}
}
}
}
class MyCanvas extends Canvas
mymenu.defineReferencePixel(0, 0);
mymenu.setRefPixelPosition(2,-17);
anniu.defineReferencePixel(0, 0);

下载文档原格式

  / 2