文件名称:J2ME中实现人走地图走功能
文件大小:95KB
文件格式:RAR
更新时间:2014-01-29 08:57:50
J2ME
import java.io.IOException; import javax.microedition.lcdui.Graphics; import javax.microedition.lcdui.Image; import javax.microedition.lcdui.game.GameCanvas; import javax.microedition.lcdui.game.LayerManager; import javax.microedition.lcdui.game.Sprite; import javax.microedition.lcdui.game.TiledLayer; public class WalkGameCanvas_18 extends GameCanvas implements Runnable{ private Graphics g; private Image i1,i2; private Sprite splayer; private LayerManager lm; private int [][]map; private int []right=new int[]{3,4,5}; private int []left=new int[]{9,10,11}; private int []up=new int[]{0,1,2}; private int []down=new int[]{6,7,8}; private TiledLayer t; private int viewX,y,x,viewY; private int keyState; private boolean rightFlag; private boolean leftFlag; private boolean upFlag; private boolean downFlag; WalkGameCanvas_18(){ super(true); g=this.getGraphics(); try{ i1=Image.createImage("/item01.png"); i2=Image.createImage("/walk.png"); }catch(IOException e){ e.printStackTrace(); } t=new TiledLayer(20,18,i1,16,16); map=new int[][]{ { 11, 12, 11, 12, 11, 12, 11, 12, 11, 12, 11, 12, 11, 12, 11, 12, 11, 12, 11, 12 }, { 16, 22, 16, 17, 1, 2, 16, 17, 16, 17, 16, 17, 16, 17, 16, 17, 16, 22, 16, 17 }, { 11, 12, 11, 12, 6, 7, 11, 12, 11, 12, 3, 4, 5, 12, 11, 12, 11, 12, 11, 12 }, { 16, 22, 16, 17, 16, 17, 16, 17, 16, 17, 8, 9, 10, 17, 16, 17, 16, 22, 16, 17 }, { 11, 12, 11, 12, 11, 12, 11, 12, 11, 12, 11, 12, 11, 12, 11, 12, 11, 12, 11, 12 }, { 16, 22, 16, 17, 16, 17, 16, 17, 16, 17, 16, 17, 16, 17, 16, 17, 16, 22, 16, 17 }, { 11, 12, 11, 12, 11, 12, 11, 12, 11, 12, 11, 12, 11, 12, 11, 12, 11, 12, 11, 12 }, { 16, 22, 16, 17, 16, 17, 16, 17, 16, 17, 13, 14, 15, 17, 16, 17, 16, 22, 16, 17 }, { 11, 12, 11, 12, 11, 12, 11, 12, 11, 12, 18, 19, 20, 12, 11, 12, 11, 12, 11, 12 }, { 16, 22, 16, 17, 21, 21, 21, 22, 22, 21, 21, 17, 24, 25, 16, 17, 16, 22, 16, 17 }, { 11, 12, 11, 12, 21, 21, 23, 21, 21, 21, 21, 12, 11, 12, 11, 12, 11, 12, 11, 12 }, { 16, 22, 16, 17, 26, 27, 28, 29, 30, 17, 16, 17, 16, 17, 16, 17, 16, 22, 16, 17 }, { 11, 12, 11, 12, 11, 12, 11, 12, 11, 12, 11, 12, 11, 12, 11, 12, 11, 12, 11, 12 }, { 16, 22, 16, 17, 16, 17, 16, 17, 16, 17, 33, 34, 16, 17, 16, 17, 16, 22, 16, 17 }, { 11, 12, 11, 12, 11, 12, 11, 12, 11, 12, 35, 36, 11, 12, 11, 12, 11, 12, 11, 12 }, { 16, 22, 16, 17, 16, 17, 16, 17, 16, 17, 16, 17, 16, 17, 16, 17, 16, 22, 16, 17 }, { 11, 12, 11, 12, 11, 12, 11, 12, 11, 12, 11, 12, 11, 12, 11, 12, 11, 12, 11, 12 }, { 16, 22, 16, 17, 16, 17, 16, 31, 32, 17, 16, 17, 16, 17, 16, 17, 16, 22, 16, 17 } }; for(int i=0;i<18;i++) for(int j=0;j<20;j++) t.setCell(j, i, map[i][j]); splayer=new Sprite(i2,i2.getWidth()/12,i2.getHeight()); lm=new LayerManager(); lm.append(splayer); lm.append(t); new Thread(this).start(); }
【文件预览】:
Prj2_18
----.project(539B)
----bin()
--------WalkGameMIDlet_18.class(999B)
--------WalkGameCanvas_18.class(7KB)
--------walk.png(2KB)
--------item01.png(17KB)
----.settings()
--------org.eclipse.jdt.core.prefs(208B)
----deployed()
--------Prj2_18.jar(23KB)
--------Prj2_18.jad(265B)
----Prj2_18.jad(241B)
----.eclipseme.tmp()
--------emulation()
--------verified()
----src()
--------WalkGameMIDlet_18.java(699B)
--------WalkGameCanvas_18.java(7KB)
----.eclipseme(242B)
----res()
--------walk.png(2KB)
--------Thumbs.db(8KB)
--------item01.png(17KB)
----.classpath(242B)