📄 maptool.java
字号:
/*
* MapTool.java
*
* Created on 2006年5月30日, 上午10:28
*
* To change this template, choose Tools | Options and locate the template under
* the Source Creation and Management node. Right-click the template and choose
* Open. You can then make changes to the template in the Source Editor.
*/
import java.io.*;
import javax.microedition.lcdui.*;
/**
*
* @author Administrator
*/
public class MapTool {
/** Creates a new instance of MapTool */
public MapTool() {
}
// static int map[]=null;
// static byte bgmap[]=null;
// static byte monsterNum;//妖怪数
// static byte mapW;//列
// static byte mapH;//行
// static byte tileW;//行宽
// static byte tileH;//行高
//
// static int viewx;
// static int viewy;
//
static final int screenWidth=176;
static final int screenHeight=208;
//
// static Image[] maptiles=null;
//初始化关卡方法
// public static void gateInit(int gate){
// switch (gate){
// case 1:
// setMapData("/Resource/gate1.yb3");
// maptiles=new Image[23];
// for (int i=0;i<23;i++){
// //maptiles[i]=Tools.loadImage("/Resource/Map/"+(i+1)+".png");
// }
// setBgMapData("/Resource/gate1.yb4");
// break;
// case 2:
// break;
// case 3:
// break;
// }
// }
//public void getMap
// public static void setMapData(String mapName){
// DataInputStream dis;
// try {
// dis = new DataInputStream(new MapTool().getClass().getResourceAsStream(mapName));
// monsterNum=dis.readByte();
// mapH=dis.readByte();
// mapW=dis.readByte();
// tileH=dis.readByte();
// tileW=dis.readByte();
// map=new int[mapW*mapH];
// for(int i=0;i<mapW*mapH;i++){
// map[i]=dis.readInt();
// }
// dis.close();
// }catch(Exception e){
// System.out.println(e);
// }
//
// }
// public static void setBgMapData(String mapName){
// DataInputStream dis;
// try {
// dis = new DataInputStream(new MapTool().getClass().getResourceAsStream(mapName));
// int maph=dis.readByte();
// int mapw=dis.readByte();
// int tileh=dis.readByte();
// int tilew=dis.readByte();
// bgmap=new byte[mapw*maph];
// for(int i=0;i<mapw*maph;i++){
// bgmap[i]=dis.readByte();
// }
// dis.close();
// }catch(Exception e){
// System.out.println(e);
// }
//
// }
//判断是否是碰撞点
//参数:碰撞点索引
// public static boolean isCollideP(int aIdx){
// int tmp=map[aIdx];
// if(tmp<0) return true;
// return false;
// }
// public static boolean isCollideP(int ax,int ay){
// return isCollideP(ax+ay*mapW);
// }
//设置碰撞点
//参数:碰撞点索引,是否可以碰撞
// public static void setCollideP(int aIdx,boolean b){
// if (b){
// map[aIdx]=map[aIdx] | 0x80000000;
// } else
// map[aIdx]=map[aIdx] & 0x7FFFFFFF;
// }
// public static void setCollideP(int ax,int ay,boolean b){
// setCollideP(ax+ay*mapW,b);
// }
//取得翻转信息
//参数:索引
// public static byte getTurnP(int aIdx){
// int tmp=map[aIdx] & 0x70000000;
// tmp=tmp>>28;
// return (byte)tmp;
// }
// public static byte getTurnP(int ax, int ay){
// return getTurnP(ax+ay*mapW);
// }
//设置翻转点信息
//参数:索引,碰撞信息
// public static void setTurnP(int aIdx,byte aTurn){
// int tmp=(int)aTurn;
// tmp=tmp & 0x00000007;
// tmp=tmp << 28;
// map[aIdx]=map[aIdx] & 0x8FFFFFFF;
// map[aIdx]=map[aIdx] | tmp;
// }
// public static void setTurnP(int ax, int ay, byte aTurn){
// setTurnP(ax+ay*mapW,aTurn);
// }
//取得事件信息
//参数:地图索引
// public static byte getEventP(int aIdx){
// int tmp=map[aIdx] & 0x0F800000;
// tmp=tmp >> 23;
// return (byte)tmp;
// }
// public static byte getEventP(int ax, int ay){
// return getEventP(ax+ay*mapW);
// }
//设置事件信息
//参数:地图索引,事件
// public static void setEventP(int aIdx,byte aEvent){
// int tmp=(int)aEvent;
// tmp=tmp & 0x0000001F;
// tmp=tmp<<23;
// map[aIdx]=map[aIdx] & 0xF07FFFFF;
// map[aIdx]=map[aIdx] | tmp;
// }
// public static void setEventP(int ax, int ay, byte aEvent){
// setEventP(ax+ay*mapW,aEvent);
// }
//取得贴砖类型
//参数:地图索引
// public static byte getTileP(int aIdx){
// int tmp=map[aIdx] & 0x007F0000;
// tmp=tmp>>16;
// return (byte)tmp;
// }
// public static byte getTileP(int ax,int ay){
// return getTileP(ax+ay*mapW);
// }
// public static void setTileP(int aIdx,int aTile){
// int tmp=(int)aTile;
// tmp=tmp & 0x0000007F;
// tmp=tmp << 16;
// map[aIdx]=map[aIdx] & 0xFF80FFFF;
// map[aIdx]=map[aIdx] | tmp;
// }
// public static void setTileP(int ax, int ay , int aTile){
// setTileP(ax+ay*mapW,aTile);
// }
//取得怪物类型
//参数:地图索引
// public static int getMonsterTypeP(int aIdx){
// int tmp=map[aIdx] & 0x0000FF00;
// tmp=tmp >> 8;
// return tmp;
// }
// public static int getMonsterTypeP(int ax, int ay){
// return getMonsterTypeP(ax+ay*mapW);
// }
// public static void setMonsterTypeP(int aIdx,int aMonsterType){
// aMonsterType=aMonsterType << 8;
// aMonsterType=aMonsterType & 0x0000FF00;
// map[aIdx]=map[aIdx] | aMonsterType;
// }
// public static void setMonsterTypeP(int ax, int ay, int aMonsterType){
// setMonsterTypeP(ax+ay*mapW,aMonsterType);
// }
//取得物品类型
//参数:物品索引
// public static int getResTypeP(int aIdx){
// int tmp=map[aIdx] & 0x000000FF;
// return tmp;
// }
// public static int getResTypeP(int ax, int ay){
// return getResTypeP(ax+ay*mapW);
// }
// public static void setResTypeP(int aIdx,int aResType){
// aResType=aResType & 0x000000FF;
// map[aIdx]=map[aIdx] & 0xFFFFFF00;
// map[aIdx]=map[aIdx] | aResType;
// }
// public static void setResTypeP(int ax, int ay, int aResType){
// setResTypeP(ax+ay*mapW,aResType);
// }
///背影层
// public static byte getBgTileP(int aIdx){
// byte tmp=(byte)(bgmap[aIdx] & 0x3F);
// return tmp;
// }
// public static byte getBgTileP(int ax,int ay){
// return getBgTileP(ax+ay*mapW);
// }
// public static byte getBgTurnP(int aIdx){
// byte tmp=(byte)((bgmap[aIdx] & 0xC0) >> 6);
// return tmp;
// }
// public static byte getBgTurnP(int ax,int ay){
// return getBgTurnP(ax+ay*mapW);
// }
/**
* 得到图片的具体某些部分
*/
// public final static Image getImageRegion(Image source, int x, int y, int width, int height) {
// // create a placeholder for our resulting image region
// Image result = Image.createImage(width, height);
//
// if (x + width > source.getWidth() || y + height > source.getHeight())
// System.out.println("Warning: attempting extract using (" +
// x + "," + y + "," + width + "," + height + ") when image is " +
// "(" + source.getWidth() + "," + source.getHeight() + ")");
//
// // draw the image, offset by the region starting position
// result.getGraphics().drawImage(source, -x, -y,Graphics.LEFT|Graphics.TOP);
// return result;
// }
/**
* 得到图片以帧为单位的一个数据图片
*@parameter sourceImage:图片源.sourceX:图片源X方向的起始坐标.sourceY:图片源Y方向的起始坐标
*framesWide:水平方向共有几帧.framesHigh:垂直方向共有几帧.frameWidth:单帧的宽度.frameHeight:单帧的高度
*/
// public final static Image[] extractFrames(Image sourceImage, int sourceX,
// int sourceY,
// int framesWide, int framesHigh,
// int frameWidth, int frameHeight) {
// // extract all the frames from the source image
// Image[] frames = new Image[framesWide * framesHigh];
// int frameCount = 0;
// for (int fy = 0; fy < framesHigh; fy++)
// for (int fx = 0; fx < framesWide; fx++)
// frames[frameCount++] =
// getImageRegion(sourceImage, sourceX + (fx * frameWidth),
// sourceY + (fy * frameHeight),
// frameWidth, frameHeight);
// return frames;
// }
/**
* static void drawMap(Graphics g,DirectGraphics dg,int viewx,int viewy){
* for (int i=viewx/tileW;i<=(viewx+screenWidth)/tileW;i++){
* for(int j=viewy/tileH;j<=(viewy+screenHeight)/tileH;j++){
* if (i<mapW && j<mapH){
* if(getTileP(i,j)>0 && getTileP(i,j)<24){
* if (getTurnP(i,j)==1){
* dg.drawImage(maptiles[getTileP(i,j)-1], i*tileW-viewx,j*tileH-viewy, 20, dg.FLIP_HORIZONTAL);
* }else if(getTurnP(i,j)==0){
* g.drawImage(maptiles[getTileP(i,j)-1], i*tileW-viewx,j*tileH-viewy, 20);
* }
* }
* }
* }
* }
* }
* static void drawBgMap(Graphics g,DirectGraphics dg,int viewx,int viewy){
* for (int i=viewx/tileW;i<=(viewx+screenWidth)/tileW;i++){
* for(int j=viewy/tileH;j<=(viewy+screenHeight)/tileH;j++){
* if (i<mapW && j<mapH){
* if(getBgTileP(i,j)>0 && getBgTileP(i,j)<24){
* if (getBgTurnP(i,j)==1){
* dg.drawImage(maptiles[getBgTileP(i,j)-1], i*tileW-viewx,j*tileH-viewy, 20, dg.FLIP_HORIZONTAL);
* }else if(getBgTurnP(i,j)==0){
* g.drawImage(maptiles[getBgTileP(i,j)-1], i*tileW-viewx,j*tileH-viewy, 20);
* }
* }
* }
* }
* }
* }*/
public static int objectNum;
public static int[] objectData;
public static int canvasH;
public static void Read_Map(int a){
DataInputStream dis;
try {
dis = new DataInputStream(new MapTool().getClass().getResourceAsStream("/1" + a + ".qzh"));
objectNum = dis.readInt();
objectData = new int[objectNum * 3];//0是X坐标,1是Y坐标,2表示敌人的类型即地图里面图片的编号
int canvasW = dis.readInt();
canvasH = dis.readInt(); //可能没用,在这里扔了。
for (int i = 0; i < objectNum; i++) {
for (int ii = 0; ii < 3; ii++) {
objectData[i * 3 + ii] = dis.readInt(); //读取数据
}
}
dis.close();
} catch (Exception e) {
System.out.println(e);
}
}
/**
*碰撞检测
*@parameter ax ay aw ah 分别是a矩形的左顶点X Y坐标和矩形的 长和宽
*若返回真则为碰撞
*返回为假则为不碰撞
*/
public static final boolean isIntersectingRect(int ax, int ay,int aw, int ah,int bx, int by,int bw, int bh) {
if (by + bh < ay || // is the bottom b above the top of a?
by > ay + ah || // is the top of b below bottom of a?
bx + bw < ax || // is the right of b to the left of a?
bx > ax + aw) // is the left of b to the right of a?
return false;
return true;
}
public static String howplayString = null;
/**
*画帮助内容
*@parameter font 字体的类型
*p_status 当前要显示的字体行数
*返回整行数
*/
public static final int Draw_Help(Graphics g,Font font,int p_status){
g.setColor(0,0,0);
g.fillRect(0,0,screenWidth,screenHeight);
int fontHeight = font.getHeight();//得到字体的高度
//把字符串转换为字符数据
char[] data = new char[howplayString.length()];
howplayString.getChars(0, howplayString.length(), data, 0);//把字符串拷贝到data数组里面
int lineWidth = 0;//行宽度
int charWidth = 0;//单个字符宽度
int y = 0;
int x = 0;
char ch;
g.setColor(212,212,141);
// g.setColor(255,255,255);
for(int ccnt=0; ccnt < data.length; ccnt++) {
ch = data[ccnt];
//测量要绘制的字符
charWidth = font.charWidth(ch);
lineWidth = lineWidth + charWidth;
//看是否需要新的行
if (ccnt<data.length-1){
if (lineWidth +font.charWidth(data[ccnt+1])> FlyGenCavans.Screen_W) {
y = y + fontHeight;
lineWidth = 0;
x = 0;
}
}
//绘制字符
x = lineWidth;
if(p_status+y >= 0 && p_status+y+fontHeight<=FlyGenCavans.Screen_H){
g.drawChar(ch, x, p_status+y,Graphics.TOP|Graphics.LEFT);
}
}
return y;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -