📄 maincanvas.java
字号:
flushGraphics();
} catch (Exception ex) {ex.printStackTrace();}
System.gc();
}
}
private void paintLaser(Magic stuff, int direction, Graphics g) {
g.setColor(0x00FF00);
int fromRow = stuff.row, fromColumn = stuff.column;
int incr = (direction == 0 || direction == 3) ? -1 : 1;
// 沿激光方向读取物体
int row = fromRow, column = fromColumn;
Magic e = null;
int t = -1;
int ottaX = otta.getRefPixelX();
int ottaY = otta.getRefPixelY();
loop: while (true) {
if (direction == 3 || direction == 1)
column += incr;
else
row += incr;
if (row < 0 || column < 0 || row >= 12 || column >= 10)
break loop;
int x = column << 4;
int y = row << 4;
if (ottaX > x - 8 && ottaX < x + 8 && ottaY > y - 8 &&
ottaY < y + 8 && otta.status < 3) {
if (ottaX == column * 16 && ottaY == row * 16)
otta.laser();
t = 0;
break loop;
}
// 获取物体
e = stuffs[row][column];
// 物体不存在,接着获取下一个位置的物体
if (null == e)
continue;
t = e.type;
switch (t) {
case STUFF_STONE: // 假如是石头,激光就应该终止了
break loop;
case STUFF_MIRROR_CCW: // 假如是镜子,就反射激光
if (stuff.status != Magic.STATUS_DYING)
paintLaser(e, 3 - direction, g);
break loop;
case STUFF_MIRROR_CW:
// 确定反射后的方向
if (stuff.status != Magic.STATUS_DYING)
paintLaser(e, (5 - direction) % 4, g);
break loop;
case STUFF_BOMB: // 假如是炸弹,点燃它
e.apply(TOOL_TORCH);
break;
default:
e.apply(LASER);
break loop;
}
}
int fromX = fromColumn << 4;
int fromY = fromRow << 4;
int startX = fromX + 8, startY = fromY + 3;
int endX = startX, endY = startY;
switch (stuff.type) {
case STUFF_LASER_UP:
startY = fromY - 5;
break;
case STUFF_LASER_RIGHT:
startX =fromX + 19;
break;
case STUFF_LASER_DOWN:
startY = fromY + 15;
break;
case STUFF_LASER_LEFT:
startX =fromX - 5;
break;
case STUFF_MIRROR_CW:
switch (direction) {
case 0:
startY = fromY - 7;
break;
case 1:
startX =fromX + 8;
break;
case 2:
startY = fromY + 1;
break;
case 3:
startX =fromX+3;
break;
}
break;
case STUFF_MIRROR_CCW:
switch (direction) {
case 0:
startY = fromY - 7;
break;
case 1:
startX =fromX + 14;
break;
case 2:
startY = fromY + 3;
break;
case 3:
startX =fromX + 8;
break;
}
break;
}
int ex = column << 4;
int ey = row << 4;
switch (t) {
case STUFF_MIRROR_CW:
switch (direction) {
case 0:
endY = ey + 3;
break;
case 1:
endX = ex+1;
break;
case 2:
endY = ey - 7;
break;
case 3:
endX = ex + 8;
break;
}
break;
case STUFF_MIRROR_CCW:
switch (direction) {
case 0:
endY = ey + 3;
break;
case 1:
endX = ex + 7;
break;
case 2:
endY = ey - 7;
break;
case 3:
endX = ex + 16;
break;
}
break;
case STUFF_STONE:
switch (direction) {
case 0:
endY = ey + 9;
break;
case 1:
endX = ex + 1;
break;
case 2:
endY = ey - 4;
break;
case 3:
endX = ex + 13;
break;
}
break;
case 0:
switch (direction) {
case 0:
endY = ey + 16;
break;
case 1:
endX = ex;
break;
case 2:
endY = ey;
break;
case 3:
endX = ex + 16;
break;
}
default:
switch (direction) {
case 0:
endY = ey + 14;
break;
case 1:
endX = ex + 2;
break;
case 2:
endY = ey + 2;
break;
case 3:
endX = ex + 14;
break;
}
}
if (direction == 2 && startY > endY)
return;
g.drawLine(startX, startY, endX, endY);
}
public static void showMenu() {
if (subMenuVisible)
return;
subMenuVisible = true;
subMenuIndex = 0;
switch (missionStatus) {
case MISSION_FAIL:
subMenuItems = new Image[2];
subMenuItems[0] = word_retry;
subMenuItems[1] = word_mainMenu;
break;
case MISSION_COMPLETED:
if (missionNum < missionCount - 1) {
subMenuItems = new Image[2];
subMenuItems[0] = word_nextMission;
subMenuItems[1] = word_mainMenu;
} else {
subMenuItems = new Image[1];
subMenuItems[0] = word_mainMenu;
}
break;
case MISSION_RUNNING:
subMenuItems = new Image[3];
subMenuItems[0] = word_continue;
subMenuItems[1] = word_retry;
subMenuItems[2] = word_mainMenu;
break;
}
}
public void loadMission(int no) throws Exception {
missionNum = no;
InputStream input = getInputStream();
input.read();
//略过前面的字节,定位到指定的任务的存储位置上。
int count = 0;
for (int i = 0; i < missionNum; i++) {
//略过任务描述
count = input.read();
input.skip(count + 122);
//略过工具描述
count = input.read();
input.skip(count);
}
//读取任务描述
count = input.read();
byte[] descBytes = new byte[count];
input.read(descBytes);
input.read(temp);
int pos = input.read();
initRow = pos & 0x0F;
initColumn = pos >> 4;
floor = input.read();
// 读取工具描述
count = input.read();
initTools = new byte[count];
input.read(initTools);
// 关闭输入流
input.close();
reload();
descriptionX = 0;
int w = font.stringWidth(info.describe[no]);
int h = font.getHeight();
image_description = Image.createImage(w, h);
Graphics g = image_description.getGraphics();
g.setFont(font);
g.setColor(0x002844);
g.fillRect(0, 0, w, h);
g.setColor(0xFFFFFF);
g.drawString(info.describe[no], 0, 0, 20);
image_description = resizeImage(image_description, w * 14/ h, 14);
System.gc();
if(Start.isSoundOpen) {
if(!Start.isCustom)
playSound(players[Math.abs(Magic.random.nextInt())%3], -1);
else
playSound(player_custom, -1);
} else
nowPlayer.deallocate();
}
public InputStream getInputStream() {
return getClass().getResourceAsStream("/MapInfo.dat");
}
public void reload() {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -