📄 numencanva.java
字号:
// hero_bombcount = 10;
// hero_being = 3;
// hero_score = 0;
// gamemenushow = false;
// gamebodyexit = false;
// mission_start(selegate_index);
sound = temp;
process_set(SCREEN_MAINMENU);
//screen_index = SCREEN_GAMEBODY;
break;
}
}
private void selegate_run() {
refresh();
}
//****************************************************************************
/** @todo:地图数据 */
//****************************************************************************
private static Image[] platres; //图形资源列表
private static Image[] faceres; //界面用的图形资源
private final void face_load() {
InputStream in = stream_create("/game.bin");
try {
faceres = new Image[in.read() + (in.read() << 8)];
skip(in, faceres.length * 2);
for (int i = 0; i < faceres.length; i++) {
int len = in.read() + (in.read() << 8);
byte[] gdata = new byte[len + 6];
System.arraycopy("GIF89a".getBytes(), 0, gdata, 0, 6);
in.read(gdata, 6, len);
// System.out.println(faceres.length);
faceres[i] = Image.createImage(gdata, 0, gdata.length);
}
}
catch (Exception e) {
e.printStackTrace();
}
}
//****************************************************************************
/** @todo: 场景 */
//****************************************************************************
private static int platid = 1; //当前的地图索引
private static int plat_w; //地图网格宽度
private static int plat_h; //地图网格高度
private static int plat_n; //右边出口
private int[][] facts; //基本地物数据
private int backIndex; //0层及后面的图形的个数
private final void fact_draw_back() {
g.setClip(0, 0, screen_w, screen_h);
int[] fact;
for (int i = 0; i < backIndex; i++) {
fact = facts[i];
if (visible(fact[0], fact[1], fact[2], fact[3])) {
g.drawImage(platres[fact[5]], fact[0] - position_x,
fact[1] - position_y, 0);
}
}
}
private final void fact_draw_fore() { //地物
g.setClip(0, 0, screen_w, screen_h);
int[] fact;
for (int i = backIndex; i < facts.length; i++) {
fact = facts[i];
if (visible(fact[0], fact[1], fact[2], fact[3])) {
g.drawImage(platres[fact[5]], fact[0] - position_x,
fact[1] - position_y, 0);
}
}
}
private final void fact_load(InputStream in) throws IOException {
backIndex = readWord(in);
// System.out.println(backIndex);
int total = readWord(in);
facts = new int[total][6];
for (int i = 0; i < total; i++) {
facts[i][0] = readByte(in) * 8;
facts[i][1] = readByte(in) * 8;
facts[i][4] = translateRotate(in.read());
facts[i][5] = in.read();
if ( (facts[i][4] == 90) || (facts[i][4] == 270)) {
facts[i][2] = facts[i][0] + platres[facts[i][5]].getHeight();
facts[i][3] = facts[i][1] + platres[facts[i][5]].getWidth();
}
else {
facts[i][2] = facts[i][0] + platres[facts[i][5]].getWidth();
facts[i][3] = facts[i][1] + platres[facts[i][5]].getHeight();
}
}
}
//****************************************************************************
/** @todo: 地形 */
//****************************************************************************
private byte[] grids; //地形数组 每个方格占4BIT
// private final int CELL_NONE = 0; //空白
private final int CELL_WALL = 1; //墙壁
// private final int CELL_ROOF = 2; //平台
/**********************************************
* 查询地图上某个格子的作用区属性
* @param x int 场景上某格的X坐标
* @param y int 场景上某格的Y坐标
* @return int (X,Y)所表示格子的作用区值 如果(X,Y)的位置超出地图范围-1
**********************************************/
private final int grid_cellvalue(int x, int y) {
if ( (x < 0) || (x >= plat_w) || (y < 0) || (y >= plat_h)) {
return -1;
}
int v = x + y * plat_w;
return ( (v & 1) == 1) ? grids[v >> 1] >> 4 : grids[v >> 1] & 0x0f;
}
private final void grid_load(InputStream in) throws IOException {
grids = new byte[ (plat_h * plat_w) >> 1];
in.read(grids);
}
//****************************************************************************
/** @todo: 背景 */
//****************************************************************************
private int background1_face_w;
private int background1_face_h;
private int background1_face_index = -1;
private int background2_face_y;
private int background2_face_w;
private int background2_speed;
private int background2_face_index = -1;
private int background2_position_x;
private int background3_face_y;
private int background3_face_w;
private int background3_speed;
private int background3_face_index = -1;
private int background3_position_x;
/**********************************************
* 初始化游戏背景
* @param in InputStream 地图文件流
* @throws IOException IO异常
**********************************************/
private final void back_load(InputStream in) throws IOException {
int bg1 = readByte(in);
int bg2 = readByte(in);
int bg3 = readByte(in);
int bg2_top = readWord(in);
int bg3_top = readWord(in);
int bg2_spd = readByte(in);
int bg3_spd = readByte(in);
if ( (bg1 >= 0) && (bg1 < platres.length)) {
background1_face_index = bg1;
background1_face_w = platres[bg1].getWidth();
background1_face_h = platres[bg1].getHeight();
}
else {
background1_face_index = -1;
}
if ( (bg2 >= 0) && (bg2 < platres.length)) {
background2_face_index = bg2;
background2_face_y = bg2_top;
background2_face_w = platres[bg2].getWidth();
background2_position_x = 0;
background2_speed = bg2_spd;
}
else {
background2_face_index = -1;
}
if ( (bg3 >= 0) && (bg3 < platres.length)) {
background3_face_index = bg3;
background3_face_y = bg3_top;
background3_face_w = platres[bg3].getWidth();
background3_position_x = 0;
background3_speed = bg3_spd;
}
else {
background3_face_index = -1;
}
}
/**********************************************
* 画背景
**********************************************/
private final void back_draw() {
int x, y;
g.setClip(0, 0, screen_w, screen_h);
if (background1_face_index >= 0) {
y = -position_y % background1_face_h;
while (y < screen_h) {
x = -position_x % background1_face_w;
while (x < screen_w) {
g.drawImage(platres[background1_face_index], x, y, 0);
x += background1_face_w;
}
y += background1_face_h;
}
}
else {
if (background3_face_index >= 0) {
x = -background3_position_x % background3_face_w;
while (x < screen_w) {
g.drawImage(platres[background3_face_index], x, background3_face_y, 0);
x += background3_face_w;
}
}
if (background2_face_index >= 0) {
x = -background2_position_x % background2_face_w;
while (x < screen_w) {
g.drawImage(platres[background2_face_index], x, background2_face_y, 0);
x += background2_face_w;
}
}
}
}
/**********************************************
* 运行背景
**********************************************/
private final void back_run() {
if (background3_face_index >= 0) {
if (background3_speed != 0) {
background3_position_x += background3_speed;
}
else {
background3_position_x = position_x >> 3;
}
}
if (background2_face_index >= 0) {
if (background2_speed != 0) {
background2_position_x += background2_speed;
}
else {
background2_position_x = position_x >> 2;
}
}
}
//****************************************************************************
/** @todo: 道具 */
//****************************************************************************
private Vector props = new Vector();
private final int PROP_POS_W = 16;
private final int PROP_POS_H = 16;
private final int PROP_COUNT = 7;
private final int PROP_POS_X = 0;
private final int PROP_POS_Y = 1;
private final int PROP_INDEX = 2;
private final int PROP_TOTAL = 3;
private final void prop_create(int pos_x, int pos_y, int prop_index,
int prop_total) {
int[] prop = new int[PROP_COUNT];
prop[PROP_POS_X] = pos_x;
prop[PROP_POS_Y] = pos_y;
prop[PROP_INDEX] = prop_index;
prop[PROP_TOTAL] = prop_total;
props.addElement(prop);
}
private final void prop_run() {
for (int i = props.size() - 1; i >= 0; i--) {
int[] prop = (int[]) props.elementAt(i);
int v = grid_cellvalue(prop[PROP_POS_X] >> 3, prop[PROP_POS_Y] >> 3);
if ( (v == 1) || (v == 2)) {
prop[PROP_POS_Y] = (prop[PROP_POS_Y] >> 3) << 3;
}
else {
prop[PROP_POS_Y] += 4;
}
}
}
private final void prop_draw() {
for (int i = props.size() - 1; i >= 0; i--) {
int[] prop = (int[]) props.elementAt(i);
clipRect(prop[PROP_POS_X] - (PROP_POS_W >> 1),
prop[PROP_POS_Y] - PROP_POS_H,
PROP_POS_W, prop[PROP_POS_Y]);
drawFace(faceres[FACE_PROP_ICON],
prop[PROP_POS_X] - prop[PROP_INDEX] * PROP_POS_W -
(PROP_POS_W >> 1),
prop[PROP_POS_Y] - PROP_POS_H, 0);
}
}
//****************************************************************************
/** @todo:俘虏 */
//****************************************************************************
// private final int PAWN_FACEW = 25;
// private final int PAWN_FACEH = 28;
private final int PAWN_HALFW = 12;
private final int PAWN_HALFH = 14;
private Vector pawns = new Vector();
private final int PAWN_COUNT = 10;
private final int PAWN_RESID = 0;
private final int PAWN_POS_X = 1;
private final int PAWN_POS_Y = 2;
private final int PAWN_INDEX = 3; //携带的道具的索引
private final int PAWN_TOTAL = 4; //道具数目 对于加分道具这个是分数 对于弹药这个是弹药数量
private final int PAWN_STATE = 5; //俘虏当前的状态
private final int PAWN_DIREC = 6;
private final int PAWN_FRAME = 7;
private final int PAWN_FLASH = 8;
private final int PAWN_TALLY = 9;
// private final int PAWN_STATE_HOLD = 0; //绑缚状态
// private final int PAWN_STATE_STAN = 1; //站立状态
// private final int PAWN_STATE_FADE = 2; //消失状态
private final void pawn_rescue(int[] pawn) {
if (pawn[PAWN_STATE] == 0) {
pawn[PAWN_STATE] = 1;
pawn[PAWN_FRAME] = 1;
}
}
private final void pawn_load(InputStream in) throws IOException {
for (int i = in.read() - 1; i >= 0; i--) {
int[] pawn = new int[PAWN_COUNT];
pawn[PAWN_RESID] = in.read();
pawn[PAWN_POS_X] = readByte(in) * 8;
pawn[PAWN_POS_Y] = readByte(in) * 8;
pawn[PAWN_INDEX] = in.read();
pawn[PAWN_TOTAL] = in.read();
pawn[PAWN_STATE] = 0;
pawn[PAWN_DIREC] = -1;
pawn[PAWN_FRAME] = 0;
pawn[PAWN_FLASH] = 0;
pawn[PAWN_TALLY] = 0;
pawns.addElement(pawn);
}
}
// private final void pawn_run() {
// int v;
// for (int i = pawns.size() - 1; i >= 0; i--) {
// int[] pawn = (int[]) pawns.elementAt(i);
// switch (pawn[PAWN_STATE]) {
// case PAWN_STATE_HOLD:
// v = grid_cellvalue(pawn[PAWN_POS_X] >> 3,
// (pawn[PAWN_POS_Y] + PAWN_HALFH) >> 3);
// if ( (v != 1) && (v != 2)) {
// pawn[PAWN_POS_Y] += 4;
// }
// pawn[PAWN_DIREC] = (pawn[PAWN_POS_X] > hero_pos_x) ? -1 : 1;
// break;
// case PAWN_STATE_STAN:
// if (pawn[PAWN_FRAME] < 2) {
// if (pawn[PAWN_TALLY]++ > 2) {
// pawn[PAWN_FRAME]++;
// pawn[PAWN_TALLY] = 0;
// prop_create(pawn[PAWN_POS_X], pawn[PAWN_POS_Y], pawn[PAWN_INDEX],
// pawn[PAWN_TOTAL]);
// }
// }
// else {
// pawn[PAWN_STATE]++;
// }
// break;
// case PAWN_STATE_FADE:
// if (pawn[PAWN_FLASH]++ > 20) {
// pawns.removeElementAt(i);
// }
// break;
// }
// }
// }
// private final void pawn_draw() {
// for (int i = pawns.size() - 1; i >= 0; i--) {
// int[] pawn = (int[]) pawns.elementAt(i);
// if ( (pawn[PAWN_STATE] == PAWN_STATE_FADE) &&
// ( (pawn[PAWN_FLASH] & 2) == 2)) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -