欧美三区_成人在线免费观看视频_欧美极品少妇xxxxⅹ免费视频_a级毛片免费播放_鲁一鲁中文字幕久久_亚洲一级特黄

3個RPG練習,最后一個是卡馬克卷軸

系統 1827 0
    
import javax.microedition.lcdui.Canvas;
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 AppCanvas extends GameCanvas implements Runnable{

	private Graphics g;
	private Image roleImg,groundImg;
	private TiledLayer barrierLayer,groundLayer;
	private Sprite hero;
	private LayerManager layerManager;
	private int WORLD_WIDTH,WORLD_HEIGHT;//地圖寬高
	private int[] view = new int[4];//可視窗口大小
	private static final int X = 0;
	private static final int Y = 1;
	private static final int WIDTH = 2;
	private static final int HEIGHT = 3;
	private static int STEP = 12;
	
	private int direction = -1;
	private int CELL_WIDTH=24,CELL_HEIGHT=35;
	protected AppCanvas() {
		super(true);
		// TODO Auto-generated constructor stub
		setFullScreenMode(true);
		g=this.getGraphics();
		roleImg=Tools.getImage("/hero.png");
		groundImg=Tools.getImage("/map.png");
		layerManager=new LayerManager();
		hero = new Sprite(roleImg, 24, 29);
		barrierLayer = new TiledLayer(12, 12, groundImg, CELL_WIDTH, CELL_HEIGHT);
		groundLayer = new TiledLayer(12, 12, groundImg, CELL_WIDTH, CELL_HEIGHT);
		hero.defineCollisionRectangle(4,4,hero.getWidth()-8,hero.getHeight()-8);
		hero.setPosition(CELL_WIDTH*2, CELL_HEIGHT*6);
		
		Tools.fillCells(groundLayer, Consts.groundLayer_cells);
		Tools.fillCells(barrierLayer, Consts.barrierLayer_cells);
		
		//獲得地圖大小
		WORLD_WIDTH=groundLayer.getWidth();
		WORLD_HEIGHT=groundLayer.getHeight();
		
		//添加到圖層
		layerManager.append(hero);
		layerManager.append(barrierLayer);
		layerManager.append(groundLayer);
		view[X] = 0;
		view[Y] = 0;
		view[WIDTH] = 240;//getWidth();//240
		view[HEIGHT] = 320;//getHeight();//320
		layerManager.setViewWindow(view[X], view[Y], view[WIDTH], view[HEIGHT]);
		
		new Thread(this).start();
	}

	public void run() {
		// TODO Auto-generated method stub
		while (true){
			long start=System.currentTimeMillis();
			input();
			draw(g);
			long end=System.currentTimeMillis();
			if(end-start<100){
				try {
					Thread.sleep(100-(end-start));
				} catch (InterruptedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
			}
		}
		
	}
	public void draw(Graphics g){
		layerManager.paint(g, 0, 0);
		this.flushGraphics();
	}
	public void input() {
		int keyState=getKeyStates();
		if ((keyState & DOWN_PRESSED) != 0) {
			if (direction != DOWN_PRESSED) {
				direction = DOWN_PRESSED;
				hero.setFrameSequence(new int[] { 6, 7, 8 });
			} else {
				hero.nextFrame();
			}
			if (hero.getY() + hero.getHeight() < WORLD_HEIGHT)
				hero.move(0, STEP);
			else
				hero.setPosition(hero.getX(), WORLD_HEIGHT - hero.getHeight());
		} else if ((keyState & UP_PRESSED) != 0) {
			if (direction != UP_PRESSED) {
				direction = UP_PRESSED;
				hero.setFrameSequence(new int[] { 0, 1, 2 });
			} else {
				hero.nextFrame();
			}
			if (hero.getY() - STEP >= 0)
				hero.move(0, -STEP);
			else
				hero.setPosition(hero.getX(), 0);
		} else if ((keyState & LEFT_PRESSED) != 0) {
			if (direction != LEFT_PRESSED) {
				direction = LEFT_PRESSED;
				hero.setFrameSequence(new int[] { 9, 10, 11 });
			} else {
				hero.nextFrame();
			}
			if (hero.getX() - STEP >= 0)
				hero.move(-STEP, 0);
			else
				hero.setPosition(0, hero.getY());
		} else if ((keyState & RIGHT_PRESSED) != 0) {
			if (direction != RIGHT_PRESSED) {
				direction = RIGHT_PRESSED;
				hero.setFrameSequence(new int[] { 3, 4, 5 });
			} else {
				hero.nextFrame();
			}
			if (hero.getX() + hero.getWidth() < WORLD_WIDTH)
				hero.move(STEP, 0);
			else
				hero.setPosition(WORLD_WIDTH - hero.getWidth(), hero.getY());
		}
		checkCollision(direction);
		// Next scroll the view if needed
		//地圖滾動
		if (hero.getX() < view[X] +view[WIDTH]/2){//左,+ hero.getWidth()
			int dx = view[X] +view[WIDTH]/2 - hero.getX() ;
			if (view[X] - dx >= 0){
				view[X] -= dx;
			}
		}else if(hero.getX() > view[X]  + view[WIDTH]/2){//右- hero.getWidth()
			int dx = hero.getX()- view[X]  - view[WIDTH]/2;
			if(view[X] + view[WIDTH] <= WORLD_WIDTH){
				view[X] += dx;
			}
		}

		if (hero.getY() < view[Y] + view[HEIGHT]/2){ // scoll up,+hero.getHeight()
			int dy = view[Y] + view[HEIGHT]/2 - hero.getY();
			if (view[Y] - dy >= 0){
				view[Y] -= dy;
			}
		}else if(hero.getY()> view[Y] + view[HEIGHT]/2){ // scroll down
			int dy =hero.getY() - view[Y] - view[HEIGHT]/2;
			if(view[Y] + view[HEIGHT] <= WORLD_HEIGHT){
				view[Y] += dy;
			}
		}

		layerManager.setViewWindow(view[X],view[Y],view[WIDTH],view[HEIGHT]);
	}

	private void checkCollision(int direction) {
		if (hero.collidesWith(barrierLayer, false)) {
			switch (direction) {
			case LEFT_PRESSED:
				hero.move(STEP, 0);
				break;
			case RIGHT_PRESSED:
				hero.move(-STEP, 0);
				break;
			case UP_PRESSED:
				hero.move(0, STEP);
				break;
			case DOWN_PRESSED:
				hero.move(0, -STEP);
				break;
			}
			positionAtWorld();
			//障礙物的值
			byte arrayValue=Consts.barrierLayer_cells[indexY*barrierLayer.getColumns()+indexX];
			System.out.println("arrayValue="+arrayValue);
			switch (arrayValue) {
			case 5:
			case 14:
			case 15:
			case 16:
			case 17:
			case 19:
				//根據障礙物的值一一處理事件
				break;
			}
		}
	}
	//障礙物在地圖上的列,行坐標索引(根據人物當前位置和方向推算)
	private int indexX,indexY;//角色碰撞的障礙物在地圖上的列,行坐標索引
	private void positionAtWorld() {
		int x=hero.getX()/CELL_WIDTH;//24,這樣不精確,不能整除的話可能要+1
		int y=hero.getY()/CELL_HEIGHT;//35
		System.out.println("x========"+x);
		System.out.println("y========"+y);
		switch (direction) {
		case UP_PRESSED:// 上
			indexX = x;
			indexY = y - 1;
			break;
		case DOWN_PRESSED:// 下
			indexX = x;
			indexY = y + 1;
			break;
		case LEFT_PRESSED:// 左
			indexX = x - 1;
			indexY = y;
			break;
		case RIGHT_PRESSED:// 右
			indexX = x + 1;
			indexY = y;
			break;
		}
	}
	
}

  


    
import java.io.IOException;

import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.game.TiledLayer;


public class Tools {

	public static Image getImage(String name){
		Image image=null;
		try {
			image=Image.createImage(name);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return image;
	}
	
	public static final boolean isCollideWith(int ax,int ay,int aw,int ah,int bx,int by,int bw,int bh){
		if(ay-by>bh||ax-bx>bw||by-ay>ah||bx-ax>aw){
			return false;
		}
		return true;
	}
	
	public static void fillCells(TiledLayer tl,byte[][] map){
		//二維數組
		for(int i=0;i<tl.getColumns();i++)
			for(int j=0;j<tl.getRows();j++)
				tl.setCell(i, j, map[j][i]);
	}
	
	public static void fillCells(TiledLayer tl,byte[] map){
		//一維數組
		for(int i=0;i<map.length;i++){
			int col=i%tl.getColumns();
			int row=(i-col)/tl.getColumns();
			tl.setCell(col,row,map[i]);
		}
	}
	
}

  


    

public class Consts {

	//鍵值 Nokia,SE機型
	  public final static int KEY_UP = -1;
	  public final static int KEY_DOWN = -2;
	  public final static int KEY_LEFT = -3;
	  public final static int KEY_RIGHT = -4;
	  public final static int KEY_LS = -6;
	  public final static int KEY_RS = -7;
	  public final static int KEY_OK = -5;
	  public final static int KEY_BACK = -11;
	  
	  public final static byte KEY_0 = 48;
	  public final static byte KEY_1 = 49;
	  public final static byte KEY_2 = 50;
	  public final static byte KEY_3 = 51;
	  public final static byte KEY_4 = 52;
	  public final static byte KEY_5 = 53;
	  public final static byte KEY_6 = 54;
	  public final static byte KEY_7 = 55;
	  public final static byte KEY_8 = 56;
	  public final static byte KEY_9 = 57;
	  public final static byte KEY_STAR = 42;
	  public final static byte KEY_SHARP = 35;
	  
	  
	  public static byte[] groundLayer_cells = new byte[] {   
			  1, 1, 2, 3, 3, 3, 4, 3, 3, 3, 3, 3,
			  3, 3, 6, 3, 3, 7, 8,3, 3, 3, 3, 3,
			  3, 3, 6, 3, 3, 3, 3, 8,3, 3, 3, 3,
			  3, 3, 6, 3, 3, 3, 3, 7, 8, 9,3, 3,
			  3, 3, 6, 3, 3, 3, 3, 3, 7, 3,3, 3,
			  3, 3, 6, 3, 3, 3, 3, 3, 3, 3,3, 3,
			  11,11,10,11,11,11,11,11,11,11,3, 3,
			  3, 3, 6, 3, 3, 18, 3, 7, 3, 3,3, 3,
			  3, 3, 12, 1, 1, 1, 1, 13, 3, 3,3, 3,
			  3, 3, 3, 3, 3, 3, 3, 18, 3, 3,3, 3,
			  3, 3, 3, 3, 3, 3, 3, 18, 3, 3,3, 3,
			  3, 3, 3, 3, 3, 3, 3, 18, 3, 3,3, 3
			  };
	  public static byte[] barrierLayer_cells = new byte[] {
			   0, 0, 0, 14, 0, 0, 8, 5, 5, 5,5, 5,
			   0, 15, 0, 0, 0, 0, 0, 8, 5, 5,5, 5,
			   0, 0, 0, 15, 0, 0, 14, 8, 9, 5,5, 5,
			   0, 19, 0, 0, 15, 0, 14, 0, 8, 9,5, 5,
			   0, 0, 0, 20, 0, 14, 0, 0, 8, 9,5, 5,
			   0, 0, 0, 16, 14, 16, 0, 0, 0, 0,5, 5,
			   0, 0, 0, 0, 0, 0, 0, 0, 0, 0,5, 5,
			   15, 0, 0, 16, 0, 0, 0, 0, 0, 0,5, 5,
			   19, 15, 0, 0, 0, 0, 0, 0, 17, 0,5, 5,
			   0, 15, 16, 0, 0, 15, 0, 0, 0, 0,5, 5,
			   0, 15, 16, 0, 0, 15, 0, 0, 0, 0,0, 0,
			   0, 15, 16, 0, 0, 15, 0, 0, 0, 0,0, 0
			   };
	  
}

  


3個RPG練習,最后一個是卡馬克卷軸

3個RPG練習,最后一個是卡馬克卷軸

3個RPG練習,最后一個是卡馬克卷軸

3個RPG練習,最后一個是卡馬克卷軸


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 先锋资源久久 | 久久综合狠狠综合久久 | 色婷婷精品视频 | 久久亚洲一级毛片 | 亚洲成人一区二区三区 | 婷婷综合缴情亚洲五月伊 | 成人欧美一级毛片免费观看 | 一级毛片,一级毛片 | 久久综合九色综合欧美9v777 | 免费黄色在线观看 | 日本综合在线 | 精品国产一区二区三区香蕉沈先生 | 欧美视频第一区 | 亚洲欧美韩国日产综合在线 | 国产欧美日韩精品一区 | 免费看那种视频 | 一级黄色片武则天 | 国产精品亚洲片在线va | 精品国产视频 | 欧美久久xxxxxx影院 | 国产精品高清在线观看 | 精品自拍视频 | 久草在线在线观看 | 丝袜天堂 | 亚洲欧美日韩精品中文乱码 | 羞羞的网址 | 欧美视频区 | 99精品视频在线观看re | 日本老妇乱子伦中文视频 | 人人射人人爱 | 国产福利视频一区二区 | 久久av高清| 欧美成人性性 | 美国三级日本三级久久99 | 大看蕉a在线观看 | 国产欧美日韩亚洲精品区2345 | 成人在线观看av | 国产一区二区丁香婷婷 | 亚洲欧美激情精品一区二区 | 欧美日韩在线看 | 龙珠z国语版在线观看 |