📄 maincanvas.java
字号:
break;
case -2:
if (missionCount - 1 > missionSelectedIndex)
missionSelectedIndex++;
break;
case -5:
case -6:
loadMission(missionSelectedIndex);
status = STATUS_MISSION_RUNNING;
break;
}
back.paint(g);
back.nextFrame();
//画边框
g.drawImage(chen,0,0,0);
//画关卡
g.drawRegion(level, 0, 0, 67, missionCount*16, 0, 55, 63, 0);
//绘制画面
for (int i = 0; i < 10; i ++) {
int curNum = missionPageNum * 10 + i;
if (curNum >= missionCount)
break;
int y = 66 + i * 16;
int disno = curNum + 1;
//假如该任务完成过就显示一个对号
if ((record[curNum / 8] & (0x01 << curNum % 8)) != 0)
g.drawImage(image_cup, 125, y, 20);
}
if (incr <= 3)
g.drawImage(hand, 39, 63 + missionSelectedIndex % 10 * 16, 0);
break;
case STATUS_OPTION: //选项菜单
if(lastKeyPressed != 0)
status = STATUS_MAINMENU;
g.drawImage(link, 0, 0, 0);
g.drawImage(window, 13, 25, 0);
if(isLinking)
g.drawRegion(word2, 142, 0, 72, 14, 0, 53, 68,0);
Thread.sleep(1000);
if(getHttpConnection("http://127.0.0.1:8080/MapInfo.dat")) {
g.setColor(0xFFFFFF);
g.fillRect(53, 68, 75, 14);
g.drawRegion(word2, 0, 0, 70, 14, 0, 53, 68,0);
} else {
g.setColor(0xFFFFFF);
g.fillRect(53, 68, 75, 14);
g.drawRegion(word2, 70, 0, 70, 14, 0, 53, 68,0);
}
break;
case STATUS_MISSION_RUNNING: //游戏运行时
if (subMenuVisible) {
int size = subMenuItems.length;
switch(lastKeyPressed) {
case -1:
subMenuIndex = (--subMenuIndex + size) % size;
break;
case -2:
subMenuIndex = ++subMenuIndex % size;
break;
case -5:
case -6:
Image item = subMenuItems[subMenuIndex];
subMenuVisible = false;
if (item == word_mainMenu) {
status = STATUS_MAINMENU;
continue;
} else if (item == word_nextMission)
loadMission(missionNum + 1);
else if (item == word_retry)
reload();
break;
}
} else {
switch (lastKeyPressed) {
case -3:
cursorColumn = (--cursorColumn + 10) % 10;
break;
case -4:
cursorColumn = ++cursorColumn % 10;
break;
case -1:
cursorRow = (--cursorRow + 12) % 12;
break;
case -2:
cursorRow = ++cursorRow % 12;
break;
case -7:
showMenu();
break;
case 48:
selectedToolIndex = -1;
break;
case -5:
case -6:
if (selectedToolIndex == -1) {
if (canCross(cursorRow, cursorColumn))
otta.setPath(cursorRow, cursorColumn);
} else {
int toolType = tools[selectedToolIndex];
Magic stuff = stuffs[cursorRow][cursorColumn];
int ottaX = otta.getRefPixelX();
int ottaY = otta.getRefPixelY();
//判断otta是不是处于光标之下
int cursorX = cursorColumn << 4;
int cursorY = cursorRow << 4;
if (ottaX > cursorX - 8
&& ottaX < cursorX + 8
&& ottaY > cursorY - 8
&& ottaY < cursorY + 8
&& stuff == null) {
if (otta.apply(toolType))
removeSelectedTool();
} else if (stuff != null) {
if (stuff.apply(toolType))
removeSelectedTool();
} else if (toolType >= TOOL_BOMB && base[cursorRow][cursorColumn] == 0) {
stuff = new Magic(toolType + 16, cursorRow, cursorColumn);
stuffs[cursorRow][cursorColumn] = stuff;
removeSelectedTool();
}
}
break;
default:
int i = lastKeyPressed - GameCanvas.KEY_NUM1;
if (i >= 0 && i <= 9 && tools[i] != 0)
selectedToolIndex = i;
}
}
// 绘制地图
iceFloor.nextFrame();
targetFloor.nextFrame();
for (int i = 0; i < 12; i++) {
for (int j = 0; j < 10; j++) {
int type = base[i][j];
int x = j * 16;
int y = i * 16;
switch (type) {
case 0:
g.drawImage(image_floors[floor], x, y, 20);
break;
case RIVER:
iceFloor.setPosition(x,y);
iceFloor.paint(g);
break;
case TARGET:
g.drawImage(image_floors[floor], x, y, 20);
targetFloor.setPosition(x,y);
targetFloor.paint(g);
break;
default:
g.setColor(0xb7ecff); //填充颜色
g.fillRect(x, y, 16, 16);
g.drawImage(image_tools[type - 4], x, y, 20);
g.setColor(0x634d36); //边框颜色
g.drawRect(x,y,15,15);
}
}
}
int cursorX = cursorColumn << 4;
int cursorY = cursorRow << 4;
g.setColor(0x00ff5b1b);
g.drawRect(cursorX, cursorY, 15, 15);
boolean ottaUndrawn = true;
for (int i = 0; i < 12; i++) {
for (int j = 0; j < 10; j++) {
Magic stuff = stuffs[i][j];
if (stuff != null) {
stuff.draw(g);
if (stuff.status == Magic.STATUS_DEAD)
stuffs[i][j] = null;
}
if (otta.getRefPixelY() <= i <<4
&& ottaUndrawn && otta.status != otta.STATUS_HOT) {
otta.draw(g);
ottaUndrawn = false;
}
}
}
// 绘制激光
for (int i = 0; i < 12; i++) {
for (int j = 0; j < 10; j++) {
Magic stuff = stuffs[i][j];
if (stuff != null
&& stuff.type >= STUFF_LASER_UP
&& stuff.type <= STUFF_LASER_LEFT
&& stuff.status != Magic.STATUS_DYING) {
paintLaser(stuff, stuff.type - STUFF_LASER_UP, g);
}
}
}
if (ottaUndrawn) otta.draw(g);
// 绘制光标
if (selectedToolIndex == -1)
g.drawImage(image_hand, cursorX + 1, cursorY + 5, 20);
else {
int type = tools[selectedToolIndex];
switch(type) {
case TOOL_LASER_UP:
g.drawRegion(image_laser, 0, 0, 24, 20, Sprite.TRANS_NONE,
cursorX - 4, cursorY - 4, 20);
break;
case TOOL_LASER_RIGHT:
g.drawRegion(image_laser, 48, 0, 24, 20, Sprite.TRANS_NONE,
cursorX - 4, cursorY - 4, 20);
break;
case TOOL_LASER_DOWN:
g.drawRegion(image_laser, 96, 0, 24, 20, Sprite.TRANS_NONE,
cursorX - 4, cursorY - 4, 20);
break;
case TOOL_LASER_LEFT:
g.drawRegion(image_laser, 48, 0, 24, 20, Sprite.TRANS_MIRROR,
cursorX - 4, cursorY - 4, 20);
break;
case TOOL_MIRROR_CW:
g.drawRegion(image_mirror, 0, 0, 16, 24, Sprite.TRANS_MIRROR,
cursorX, cursorY - 8, 20);
break;
case TOOL_MIRROR_CCW:
g.drawRegion(image_mirror, 0, 0, 16, 24, Sprite.TRANS_NONE,
cursorX, cursorY - 8, 20);
break;
default:
g.drawImage(image_tools[type - 4], cursorX, cursorY, 20);
}
}
// 绘制工具栏
g.drawImage(image_toolbar, 160, 0, 20);
for (int i = 0; i < 9; i++) {
int y = i * 19 + 1;
int toolType = tools[i];
if (toolType > 0)
g.drawImage(image_tools[toolType - 4], 160, y, 20);
}
// 绘制时间
g.drawImage(image_bottom, 0, 192, 0);
int interval = (int) ((System.currentTimeMillis() - startTime)/1000);
int onesDigit = interval % 10;
int tensDigit = (interval / 10) % 6;
int hundredDigit = (interval / 60) % 10;
int thousandDigit = (interval / 600) % 6;
g.drawImage(number[thousandDigit], 30, 201, 0);
g.drawImage(number[hundredDigit], 37, 201, 0);
g.drawImage(number[10], 44, 201, 20);
g.drawImage(number[tensDigit], 51, 201, 0);
g.drawImage(number[onesDigit], 58, 201, 0);
// 绘制任务描述
int descWidth = image_description.getWidth();
int lx = descriptionX - 96;
int ly = descriptionX;
if (ly > descWidth)
ly = descWidth;
int s = 77;
if (lx < 0) {
lx = 0;
s = 172 - descriptionX;
}
g.setColor(0x000000);
g.drawRegion(image_description, lx, 1, ly - lx,
image_description.getHeight() - 1, Sprite.TRANS_NONE , s, 199, 20);
descriptionX = (descriptionX + 1) % (descWidth + 96);
// 绘制子菜单
if (subMenuVisible) {
g.drawImage(menub, 49, 59, 20);
int y = ((70 - subMenuItems.length * 15) >> 1) + 56;
for (int i = 0; i < subMenuItems.length; i++) {
int x = 48 + ((80 - subMenuItems[i].getWidth()) >> 1);
g.drawImage(subMenuItems[i], x, y + i * 15, 20);
}
if (incr <= 3)
g.drawImage(hand, 30 + ((80 - subMenuItems[subMenuIndex]
.getWidth()) >> 1), y + subMenuIndex * 15 - 1, 20);
}
break;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -