📄 numencanva.java
字号:
// continue;
// }
// clipRect(pawn[PAWN_POS_X] - PAWN_HALFW, pawn[PAWN_POS_Y] - PAWN_HALFH,
// PAWN_FACEW, PAWN_FACEH);
// switch (pawn[PAWN_DIREC]) {
// case -1:
// drawFace(platres[pawn[PAWN_RESID]],
// pawn[PAWN_POS_X] - PAWN_HALFW -
// pawn[PAWN_FRAME] * PAWN_FACEW,
// pawn[PAWN_POS_Y] - PAWN_HALFH, 0);
// break;
// case 1:
// drawFace(platres[pawn[PAWN_RESID]],
// pawn[PAWN_POS_X] + PAWN_HALFW +
// pawn[PAWN_FRAME] * PAWN_FACEW - 3 * PAWN_FACEW,
// pawn[PAWN_POS_Y] - PAWN_HALFH, 0x2000);
// break;
// }
// }
// }
//****************************************************************************
/** @todo:箱子 */
//****************************************************************************
private Vector chest = new Vector();
private final int CHEST_COUNT = 9;
private final int CHEST_RESID = 0;
private final int CHEST_POS_X = 1;
private final int CHEST_POS_Y = 2;
private final int CHEST_POS_W = 3;
private final int CHEST_POS_H = 4;
private final int CHEST_BLAST = 5; //爆炸效果
private final int CHEST_PROPS = 6; //道具的类型
private final int CHEST_TOTAL = 7; //道具加的分 或者 子弹个数
private final int CHEST_ANIMA = 8; //箱子的类型
private final boolean chet_include(int[] chet, int x, int y) {
return
(x >= chet[CHEST_POS_X]) &&
(y >= chet[CHEST_POS_Y]) &&
(x <= chet[CHEST_POS_X] + chet[CHEST_POS_W]) &&
(y <= chet[CHEST_POS_Y] + chet[CHEST_POS_H]);
}
private final void chet_load(InputStream in) throws IOException {
int size_chet = in.read();
for (int i = 0; i < size_chet; i++) {
int[] chet = new int[CHEST_COUNT];
chet[CHEST_RESID] = in.read();
chet[CHEST_POS_X] = readByte(in) * 8;
chet[CHEST_POS_Y] = readByte(in) * 8;
chet[CHEST_ANIMA] = in.read();
chet[CHEST_PROPS] = readByte(in);
chet[CHEST_TOTAL] = in.read();
chet[CHEST_BLAST] = readByte(in);
chet[CHEST_POS_W] = platres[chet[CHEST_RESID]].getWidth();
chet[CHEST_POS_H] = platres[chet[CHEST_RESID]].getHeight();
chest.addElement(chet);
}
}
private final void chet_run() {
boolean touch = false;
for (int i = chest.size() - 1; i >= 0; i--) {
touch = false;
int[] chet = (int[]) chest.elementAt(i);
int chet_l = chet[CHEST_POS_X] + 3;
int chet_r = chet[CHEST_POS_X] + chet[CHEST_POS_W] - 3;
int chet_y = chet[CHEST_POS_Y] + chet[CHEST_POS_H] + 4;
int v1 = grid_cellvalue(chet_l >> 3, chet_y >> 3);
int v2 = grid_cellvalue(chet_r >> 3, chet_y >> 3);
if ( (v1 == 1) || (v2 == 1) || (v1 == 2) || (v2 == 2)) {
chet[CHEST_POS_Y] = ( (chet_y >> 3) << 3) - chet[CHEST_POS_H];
continue;
}
for (int j = chest.size() - 1; j >= 0; j--) {
if (i == j) {
continue;
}
int[] chet_v = (int[]) chest.elementAt(j);
if (chet_include(chet_v, chet_l, chet_y) ||
chet_include(chet_v, chet_r, chet_y) ||
chet_include(chet_v, (chet_l + chet_r) >> 1, chet_y)) {
chet[CHEST_POS_Y] = chet_v[CHEST_POS_Y] - chet[CHEST_POS_H];
touch = true;
}
}
if (!touch) {
chet[CHEST_POS_Y] += 4;
}
}
}
private final void chet_hitted(int[] chet, int attack) {
chet[CHEST_ANIMA] -= attack;
int center_x = ( (chet[CHEST_POS_X] << 1) + chet[CHEST_POS_W]) >> 1;
int center_y = ( (chet[CHEST_POS_Y] << 1) + chet[CHEST_POS_H]) >> 1;
if (chet[CHEST_ANIMA] > 0) {
return;
}
if (chet[CHEST_BLAST] >= 0) {
movi_create(chet[CHEST_BLAST], center_x, center_y, 0, 0, 0, 0, -1,
MOVI_DEATH_ONCE);
}
if (chet[CHEST_PROPS] >= 0) {
prop_create(center_x, center_y, chet[CHEST_PROPS], chet[CHEST_TOTAL]);
}
chest.removeElement(chet);
}
private final void chet_draw() {
g.setClip(0, 0, screen_w, screen_h);
for (int i = chest.size() - 1; i >= 0; i--) {
int[] chet = (int[]) chest.elementAt(i);
int x = chet[CHEST_POS_X];
int y = chet[CHEST_POS_Y];
if (visible(x, y, x + chet[CHEST_POS_W], y + chet[CHEST_POS_H])) {
drawFace(platres[chet[CHEST_RESID]], chet[CHEST_POS_X],
chet[CHEST_POS_Y], 0);
}
}
}
//****************************************************************************
/** @todo:动画 */
//****************************************************************************
private Vector movis = new Vector(); //动画元件数据
private int[][] movis_defin;
private Image[] movis_image;
private final int MOVI_DEFIN_COUNT = 5;
private final int MOVI_DEFIN_FRAME = 0;
private final int MOVI_DEFIN_LINKX = 1;
private final int MOVI_DEFIN_LINKY = 2;
private final int MOVI_DEFIN_FRAMW = 3;
private final int MOVI_DEFIN_FRAMH = 4;
private final int MOVI_COUNT = 18;
private final int MOVI_DEFID = 0; //图形索引
private final int MOVI_POS_X = 1; //动画位置X
private final int MOVI_POS_Y = 2; //动画位置Y
private final int MOVI_FRAML = 3; //连接点到帧左边的距离
private final int MOVI_FRAMT = 4; //连接点到帧上边的距离
private final int MOVI_FRAMR = 5; //连接点到帧右边的距离
private final int MOVI_FRAMB = 6; //连接点到帧下边的距离
private final int MOVI_FACEW = 7;
private final int MOVI_FRAMH = 8;
private final int MOVI_FRAMW = 9;
private final int MOVI_FRAME = 10; //动画帧数
private final int MOVI_INDEX = 11; //当前帧索引
private final int MOVI_SPD_X = 12;
private final int MOVI_SPD_Y = 13;
private final int MOVI_ACCEX = 14;
private final int MOVI_ACCEY = 15;
private final int MOVI_DIREC = 16;
private final int MOVI_DEATH = 17;
private final int MOVI_DEATH_ONCE = 0;
private final int MOVI_DEATH_EVER = 1;
private final int MOVI_DEATH_SIDE = 2;
private final void movi_loaddefine() {
InputStream in = stream_create("/movi.bin");
try {
movis_defin = new int[in.read()][MOVI_DEFIN_COUNT];
movis_image = new Image[movis_defin.length];
for (int i = 0; i < movis_defin.length; i++) {
movis_image[i] = platres[in.read()];
movis_defin[i][MOVI_DEFIN_FRAME] = in.read();
movis_defin[i][MOVI_DEFIN_LINKX] = in.read();
movis_defin[i][MOVI_DEFIN_LINKY] = in.read();
movis_defin[i][MOVI_DEFIN_FRAMW] = movis_image[i].getWidth() /
movis_defin[i][MOVI_DEFIN_FRAME];
movis_defin[i][MOVI_DEFIN_FRAMH] = movis_image[i].getHeight();
}
}
catch (Exception e) {}
}
private final void movi_load(InputStream in) throws IOException {
for (int i = in.read() - 1; i >= 0; i--) {
movi_create(in.read(), readByte(in) * 8, readByte(in) * 8, 0, 0, 0, 0, -1,
MOVI_DEATH_EVER);
}
}
private final void movi_create(int movi_index, int pos_x, int pos_y,
int spd_x,
int spd_y, int accelx, int accely, int direct,
int death) {
int[] movi = new int[MOVI_COUNT];
movi[MOVI_DEFID] = movi_index;
movi[MOVI_POS_X] = pos_x;
movi[MOVI_POS_Y] = pos_y;
movi[MOVI_FRAML] = movis_defin[movi_index][MOVI_DEFIN_LINKX];
movi[MOVI_FRAMT] = movis_defin[movi_index][MOVI_DEFIN_LINKY];
movi[MOVI_FRAMR] = movis_defin[movi_index][MOVI_DEFIN_FRAMW] -
movis_defin[movi_index][MOVI_DEFIN_LINKX];
movi[MOVI_FRAMB] = movis_defin[movi_index][MOVI_DEFIN_FRAMH] -
movis_defin[movi_index][MOVI_DEFIN_LINKY];
movi[MOVI_FACEW] = movis_image[movi_index].getWidth();
movi[MOVI_FRAMH] = movis_image[movi_index].getHeight();
movi[MOVI_FRAME] = movis_defin[movi_index][MOVI_DEFIN_FRAME];
movi[MOVI_FRAMW] = movis_defin[movi_index][MOVI_DEFIN_FRAMW];
movi[MOVI_INDEX] = 0;
movi[MOVI_SPD_X] = spd_x;
movi[MOVI_SPD_Y] = spd_y;
movi[MOVI_ACCEX] = accelx;
movi[MOVI_ACCEY] = accely;
movi[MOVI_DIREC] = direct;
movi[MOVI_DEATH] = death;
movis.addElement(movi);
}
private final void movi_run() {
for (int i = movis.size() - 1; i >= 0; i--) {
int[] movi = (int[]) movis.elementAt(i);
int movi_l = movi[MOVI_POS_X] -
( (movi[MOVI_DIREC] == -1) ? movi[MOVI_FRAML] : movi[MOVI_FRAMR]);
int movi_t = movi[MOVI_POS_Y] - movi[MOVI_FRAMT];
int movi_r = movi[MOVI_POS_X] +
( (movi[MOVI_DIREC] == -1) ? movi[MOVI_FRAMR] : movi[MOVI_FRAML]);
int movi_b = movi[MOVI_POS_Y] + movi[MOVI_FRAMB];
switch (movi[MOVI_DEATH]) {
case MOVI_DEATH_ONCE:
if (movi[MOVI_INDEX] == movi[MOVI_FRAME] - 1) {
movis.removeElementAt(i);
}
break;
case MOVI_DEATH_SIDE:
if (!visible(movi_l, movi_t, movi_r, movi_b)) {
movis.removeElementAt(i);
}
break;
}
movi[MOVI_POS_X] += movi[MOVI_SPD_X] / 100;
movi[MOVI_POS_Y] += movi[MOVI_SPD_Y] / 100;
movi[MOVI_SPD_X] += movi[MOVI_ACCEX];
movi[MOVI_SPD_Y] += movi[MOVI_ACCEY];
movi[MOVI_INDEX] = (movi[MOVI_INDEX] < movi[MOVI_FRAME] - 1) ?
movi[MOVI_INDEX] + 1 : 0;
}
}
private final void movi_draw() {
//画动画物体
for (int i = movis.size() - 1; i >= 0; i--) {
int[] movi = (int[]) movis.elementAt(i);
int movi_l = movi[MOVI_POS_X] -
( (movi[MOVI_DIREC] == -1) ? movi[MOVI_FRAML] : movi[MOVI_FRAMR]);
int movi_t = movi[MOVI_POS_Y] - movi[MOVI_FRAMT];
int movi_r = movi[MOVI_POS_X] +
( (movi[MOVI_DIREC] == -1) ? movi[MOVI_FRAMR] : movi[MOVI_FRAML]);
int movi_b = movi[MOVI_POS_Y] + movi[MOVI_FRAMB];
int draw_x = (movi[MOVI_DIREC] == -1) ?
movi_l - movi[MOVI_INDEX] * movi[MOVI_FRAMW] :
movi_r + movi[MOVI_INDEX] * movi[MOVI_FRAMW] - movi[MOVI_FACEW];
if (visible(movi_l, movi_t, movi_r, movi_b)) {
clipRect(movi_l, movi_t, movi[MOVI_FRAMW], movi[MOVI_FRAMH]);
g.drawImage(movis_image[movi[MOVI_DEFID]],
draw_x - position_x, movi_t - position_y,
(movi[MOVI_DIREC] == -1) ? 0 : 0x2000);
}
}
}
/**********************************************
* 转换图形翻转属性
* @param rotate int 地图中用到的翻转数据
* @return int nokia j2me api中的图形翻转数据
**********************************************/
private int translateRotate(int rotate) {
switch (rotate) {
case 1:
return 0x2000;
case 2:
return 0x4000;
case 3:
return 90;
case 4:
return 180;
case 5:
return 270;
default:
return 0;
}
}
//****************************************************************************
// 游戏中的文字提示信息
//****************************************************************************
// private String message_prompt = null;
// private final void message_prompt(String msg) {
// message_prompt = msg;
// refresh();
// }
// private final void message_prompt_show() {
// if (message_prompt == null) {
// return;
// }
// drawframe(15, 54, screen_w - 15, 74);
// g.setColor(0xFFFFFF);
// g.drawString(message_prompt, screen_w >> 1, 57, 0x11);
// }
/**********************************************
* 主角被怪物攻击
* @param attack 怪物的攻击力
**********************************************/
private final void hero_hitted(int attack) {
if (hero_cflash > 0) {
return;
}
if (attack <= 0) {
return;
}
hero_anima--;
hero_cflash = 10;
if (hero_anima <= 0) {
hero_setfirestatus(STATUS_FIRE_DEATHS);
hero_setaction(HERO_ACTION_SHOTDEAD);
}
}
/**********************************************
* 判断主角是否和一个矩形发生碰撞
* @param x int
* @param y int
* @param r int
* @param b int
* @return boolean
**********************************************/
private final boolean hero_nexus(int x, int y, int r, int b) {
int[] fram = heroaction[hero_action][hero_cframe];
return! ( (x > hero_pos_x + fram[HERO_FRAME_RECTW]) ||
(r < hero_pos_x - fram[HERO_FRAME_RECTW]) ||
(y > hero_pos_y + hero_frectb) ||
(b < hero_pos_y - fram[HERO_FRAME_RECTT]));
}
//****************************************************************************
/** @todo: 主角 */
//****************************************************************************
private Image hero_face; //当前主角图形资源
private int hero_pos_x; //主角位置X
private int hero_pos_y; //主角位置Y
private int hero_old_x; //主角上次站立位置X
private int hero_old_y; //主角上次站立位置Y
private int hero_anima = 32; //生命值
private int hero_attak = 10;
private int hero_being = 3; //生命次数
private int hero_score = 0; //得分
private int hero_spd_y = 0; //垂直速度 速度数值为实际位移量的10倍
private int hero_style = 0; //主角的样式:人物,飞机,坦克
private int hero_shot_type = 0; //子弹类型
private int hero_shotcount = 0; //子弹数量
private int hero_shottally = 0; //子弹延时计数
private int hero_bombcount = 0; //炸弹数量
private int hero_bombtally = 0; //炸弹投掷延时
private int HERO_BOMBTALLY = 5; //投弹延迟常数
// private int hero_add_being = 0; //根据分数添加的人数0
private boolean hero_death = false; //如果主角完成了死亡动作 该标记被设为true 用于新出现主角
private final int SHOT_TYPE_TOMM = 0; //机枪
private final int SHOT_TYPE_MISS = 1; //导弹
private int SPEED_HORZ_ACCEL = 60; //水平方向加速度
private int SPEED_VERT_ACCEL = 50; //垂直方向加速度
private int SPEED_VERT_START = -220; //起跳初速度
private int SPEED_VERT_LIMIT = 200; //垂直方向最大速度
private int hero_direct = 1; //主角动作的方向 -1:向左 1:向右
private int hero_cflash;
private int hero_status;
private int hero_action;
private int hero_cframe;
private int hero_frectw;
private int hero_frectt;
// private int hero_fire_count = 0;
private final int hero_frectb = 11;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -