?? mygamecanvas.java
字號:
//
paintWeather(g);
//
drawHPMP(g);
if (bGameResult != 0) {
g.setColor(0xff0000);
if (bGameResult == 1) {
paintWindow(
g,
imageSuc,
(Consts.SN_SCREEN_WIDTH - imageSuc.getWidth()) >> 1,
(Consts.SN_SCREEN_HEIGHT - imageSuc.getHeight() >> 1),
true);
// g.drawString("成功!!!", Consts.SN_SCREEN_WIDTH >> 1,
// Consts.SN_SCREEN_HEIGHT >> 1, Graphics.TOP
// | Graphics.HCENTER);
} else {
paintWindow(g, imageFailuer,
(Consts.SN_SCREEN_WIDTH - imageFailuer
.getWidth()) >> 1,
(Consts.SN_SCREEN_HEIGHT
- imageFailuer.getHeight() >> 1), true);
// g.drawString("失敗!!!", Consts.SN_SCREEN_WIDTH >> 1,
// Consts.SN_SCREEN_HEIGHT >> 1, Graphics.TOP
// | Graphics.HCENTER);
}
} else {
if (strInfo != null) {
g.setColor(0xff0000);
g.drawString(strInfo, Consts.SN_SCREEN_WIDTH >> 1,
Consts.SN_SCREEN_HEIGHT >> 1, Graphics.TOP
| Graphics.HCENTER);
}
if (isDialogWorking) {
paintDialog(g);
}
}
}
}
}
public void paintDialog(Graphics g) {
g.setColor(0xffffff);
g.fillRoundRect(nDialogWindowX, nDialogWindowY, nDialogWindowWidth,
nDialogWindowHeight, 8, 8);
g.setColor(0x0);
g.drawRoundRect(nDialogWindowX, nDialogWindowY, nDialogWindowWidth,
nDialogWindowHeight, 8, 8);
g.setColor(0x0);
for (int i = 0; i < ROW; i++) {
int id = page * ROW + i;
if (id >= strDialog1D.length) {
break;
} else {
g.drawString(strDialog1D[id], nDialogWindowTextX,
nDialogWindowTextY + i * (nFontHeight + nFontDisY),
Graphics.TOP | Graphics.LEFT);
}
}
}
public void paintBackground(Graphics g) {
g.setColor(0);
g.fillRect(0, 0, Consts.SN_SCREEN_WIDTH, Consts.SN_SCREEN_HEIGHT);
}
public final void paintUnits(Graphics g) {
// cpc.draw(g);
// cpc2.draw(g);
Vector tempVector = new Vector(0, 1);
for (int i = 0; i < vecticUnits.size(); i++) {
CPC cpc = ((CPC) vecticUnits.elementAt(i));
if (cpc.isInsideScreen()) {
tempVector.addElement(cpc);
}
}
// 排序。冒泡
for (int i = 0; i < tempVector.size(); i++) {
for (int j = 0; j < tempVector.size() - i - 1; j++) {
CPC cpc1 = (CPC) tempVector.elementAt(j);
CPC cpc2 = (CPC) tempVector.elementAt(j + 1);
if (cpc1.nYInScreen >= cpc2.nYInScreen) {
tempVector.setElementAt(cpc1, j + 1);
tempVector.setElementAt(cpc2, j);
}
}
}
// DRAW ZHEN
for (int i = 0; i < tempVector.size(); i++) {
CPC cpc1 = (CPC) (tempVector.elementAt(i));
if (cpc1.bVar == CPC.B_VAR_ZHEN) {
cpc1.draw(g);
}
}
// BOMB
for (int i = 0; i < tempVector.size(); i++) {
CPC cpc1 = (CPC) (tempVector.elementAt(i));
if (cpc1.bVar == CPC.B_VAR_BOMB) {
cpc1.draw(g);
}
}
// BOMBFIRE
for (int i = 0; i < tempVector.size(); i++) {
CPC cpc1 = (CPC) (tempVector.elementAt(i));
if (cpc1.bVar == CPC.B_VAR_BOMBSFIRE) {
cpc1.draw(g);
}
}
boolean isLisaDraw = false;
for (int i = 0; i < tempVector.size(); i++) {
CPC cpc1 = (CPC) (tempVector.elementAt(i));
if (cpc1.bVar == CPC.B_VAR_BOSS_UFO) {
continue;
}
if (!isLisaDraw) {
if (cpc1.nYInScreen > npcLisa.nYInScreen) {
isLisaDraw = true;
npcLisa.draw(g);
}
}
if (cpc1.bVar == CPC.B_VAR_BOMBSFIRE || cpc1.bVar == CPC.B_VAR_BOMB
|| cpc1.bVar == CPC.B_VAR_ZHEN) {
} else {
cpc1.draw(g);
}
}
if (!isLisaDraw) {
npcLisa.draw(g);
}
//
for (int i = 0; i < tempVector.size(); i++) {
CPC cpc1 = (CPC) (tempVector.elementAt(i));
if (cpc1.bVar == CPC.B_VAR_BOSS_UFO) {
cpc1.draw(g);
}
}
}
public void initCamera() {
snWindowY = 0;
snWindowX = 0;
snMapX = 0;
snMapY = 0;
if (snMapWidth <= Consts.SN_SCREEN_WIDTH) {
snWindowX = (Consts.SN_SCREEN_WIDTH - snMapWidth) / 2;
} else {
snWindowX = 0;
}
if (snMapHeight <= Consts.SN_SCREEN_HEIGHT) {
snWindowY = (Consts.SN_SCREEN_HEIGHT - snMapHeight) / 2;
} else {
snWindowY = 0;
}
//
if (snWindowX == 0) {
// X方向全屏
if (npcLisa.nX >= (Consts.SN_SCREEN_WIDTH >> 1)
&& npcLisa.nX <= (snMapWidth - (Consts.SN_SCREEN_WIDTH >> 1))) {
snMapX = npcLisa.nX - (Consts.SN_SCREEN_WIDTH >> 1);
} else {
if (npcLisa.nX >= (snMapWidth - (Consts.SN_SCREEN_WIDTH >> 1))) {
snMapX = snMapWidth - Consts.SN_SCREEN_WIDTH;
} else {
snMapX = 0;
}
}
}
if (snWindowY == 0) {
// X方向全屏
if (npcLisa.nY >= (Consts.SN_SCREEN_HEIGHT >> 1)
&& npcLisa.nY <= (snMapHeight - (Consts.SN_SCREEN_HEIGHT >> 1))) {
snMapY = npcLisa.nY - (Consts.SN_SCREEN_HEIGHT >> 1);
} else {
if (npcLisa.nY >= (snMapHeight - (Consts.SN_SCREEN_HEIGHT >> 1))) {
snMapY = snMapHeight - Consts.SN_SCREEN_HEIGHT;
} else {
snMapY = 0;
}
}
}
}
/**
* 繪制Tiles
*/
public final void paintTiles(Graphics g) {
//
int t_mapX = snMapX;
int t_mapY = snMapY;
// g.drawImage(imageMap, 0, 0, Graphics.TOP|Graphics.LEFT);
int nTilesX = t_mapX / Consts.SN_TILE_WIDTH;
int nTilesY = t_mapY / Consts.SN_TILE_HEIGHT;
//
int nTilesXOffset = -(t_mapX % Consts.SN_TILE_WIDTH);
int nTilesYOffset = -(t_mapY % Consts.SN_TILE_HEIGHT);
//
for (int i = -1; i < snTilesHeightNumInScreeen + 1; i++) {
for (int j = -1; j < snTilesWidthNumInScreen + 1; j++) {
//
int nTileToPaintY = nTilesY + i;
int nTileToPaintX = nTilesX + j;
if (isXYInTiles(nTileToPaintX, nTileToPaintY, snsTiles)) {
int pic_id = snsTiles[nTileToPaintY][nTileToPaintX];
if (pic_id > 0) {
// myImage1d[pic_id - 1].drawImage(g, nTilesXOffset
// + snCameraX + Consts.SN_TILE_WIDTH * j, nTilesYOffset
// +snCameraY + Consts.SN_TILE_HEIGHT * i);
blt(
g,
imageMap,
(((pic_id - 1)) % (imageMap.getWidth() / Consts.SN_TILE_WIDTH))
* Consts.SN_TILE_WIDTH,
(((pic_id - 1)) / (imageMap.getWidth() / Consts.SN_TILE_WIDTH))
* Consts.SN_TILE_HEIGHT,
Consts.SN_TILE_WIDTH, Consts.SN_TILE_HEIGHT,
snWindowX + nTilesXOffset
+ Consts.SN_TILE_WIDTH * j, snWindowY
+ nTilesYOffset + Consts.SN_TILE_HEIGHT
* i);
// g.drawImage(imageTiles[pic_id - 1], nTilesXOffset
// + Consts.SN_TILE_WIDTH * j, nTilesYOffset
// + Consts.SN_TILE_HEIGHT * i, Graphics.TOP
// | Graphics.LEFT);
}
}
// if (Consts.SIS_DEBUG) {
// g.setColor(0X00FF00);
// g.drawRect(nTilesXOffset + Consts.SN_TILE_WIDTH * j,
// nTilesYOffset + Consts.SN_TILE_HEIGHT * i,
// Consts.SN_TILE_WIDTH, Consts.SN_TILE_HEIGHT);
// }
}
}
}
static boolean isXYInTiles(int x, int y, byte[][] array) {
if (array == null) {
return false;
}
if (array[0] == null) {
return false;
}
if (x < 0 || y < 0 || x >= array[0].length || y >= array.length) {
return false;
}
return true;
}
/**
* paintText
*/
public void paintText(Graphics g, int anColor, int outLineColor) {
g.setColor(outLineColor);
g.drawRect(-1, SN_TEXT_TOP_Y - 2, Consts.SN_SCREEN_WIDTH + 2,
SN_TEXT_ROWS_NUM_MAX * (SN_CHAR_HEIGHT + SN_TEXT_DIS) + 2);
g.setColor(anColor);
int k = 0;
int i = nPointerStrrTextShow;
for (; i < nPointerStrrTextShow + SN_TEXT_ROWS_NUM_MAX; i++, k++) {
if (i < strrTextShows.length) {
if (strrTextShows[i] != null) {
g.drawString(strrTextShows[i], SN_TEXT_TOP_X, SN_TEXT_TOP_Y
+ (SN_CHAR_HEIGHT + SN_TEXT_DIS) * k, Graphics.TOP
| Graphics.LEFT);
}
}
}
}
/**
* paint
*/
public void paint(Graphics g) {
g.setClip(0, 0, Consts.SN_SCREEN_WIDTH, Consts.SN_SCREEN_HEIGHT);
g.setFont(font);
if (isPaused) {
g.setColor(0);
g.fillRect(0, 0, Consts.SN_SCREEN_WIDTH, Consts.SN_SCREEN_HEIGHT);
//
g.setColor(0xffffff);
g.drawString("任意鍵繼續", Consts.SN_SCREEN_WIDTH >> 1,
(Consts.SN_SCREEN_HEIGHT >> 1), Graphics.HCENTER
| Graphics.TOP);
} else {
switch (sbState) {
case SB_STATE_LOADING: {
g.setColor(Consts.COLOR_BLACK);
g.fillRect(0, 0, Consts.SN_SCREEN_WIDTH,
Consts.SN_SCREEN_HEIGHT);
// int tr = getRandomInt(0, 255, 1);
int tg = getRandomInt(100, 255, 1 << 2);
// int tb = getRandomInt(0, 255, 1 << 4);
g.setColor(0, tg, 0);
g.drawString(Consts.SSTR_LOADING, Consts.SN_SCREEN_WIDTH >> 1,
Consts.SN_SCREEN_HEIGHT >> 1, Graphics.TOP
| Graphics.HCENTER);
}
break;
case SB_STATE_SPLASH: {
g.setColor(Consts.COLOR_WHITE);
g.fillRect(0, 0, Consts.SN_SCREEN_WIDTH,
Consts.SN_SCREEN_HEIGHT);
g.setColor(Consts.COLOR_BLACK);
g.drawString("SPLASH " + nSlpashTimerC,
Consts.SN_SCREEN_WIDTH >> 1,
Consts.SN_SCREEN_HEIGHT >> 1, Graphics.TOP
| Graphics.HCENTER);
paintSpecString(g, "wenjun.gao@gmail.com", 0, 0, Graphics.TOP
| Graphics.LEFT, 0, 0XFFFFFF);
}
break;
case SB_STATE_MENU: {
if (!isStrrMenuButtonClicked) {
g.setColor(Consts.COLOR_GBLUE);
g.fillRect(0, 0, Consts.SN_SCREEN_WIDTH,
Consts.SN_SCREEN_HEIGHT);
g.setColor(Consts.COLOR_BLACK);
g.drawString(Consts.STR_MIDLET_NAME,
Consts.SN_SCREEN_WIDTH >> 1, 1, Graphics.TOP
| Graphics.HCENTER);
if (isFivePressed == false) {
int ty = 35;
g.setColor(0);
g.drawString("按任意鍵繼續", Consts.SN_SCREEN_WIDTH >> 1,
Consts.SN_SCREEN_HEIGHT >> 1, Graphics.TOP
| Graphics.HCENTER);
} else {
g.setColor(0);
int anY = 102;
// g.drawString(strrMenu[nPointerStrrMenu],
// Consts.SN_SCREEN_WIDTH >> 1, anY, Graphics.TOP
// | Graphics.HCENTER);
g.drawString(strrMenu[nPointerStrrMenu],
Consts.SN_SCREEN_WIDTH >> 1, anY, Graphics.TOP
| Graphics.HCENTER);
int alphaY = 5;
int anXIMGL = 27;
int anXIMGR = Consts.SN_SCREEN_WIDTH - anXIMGL;
g.drawImage(imageLeft, anXIMGL, anY + alphaY,
Graphics.TOP | Graphics.RIGHT);
g.drawImage(imageRight, anXIMGR, anY + alphaY,
Graphics.TOP | Graphics.LEFT);
// g.setColor(0XFFFFFF);
// g.drawString("V:" + Main.strVersion,
// Consts.SN_SCREEN_WIDTH - 1, 1, Graphics.TOP
// | Graphics.RIGHT);
paintLeftRightKeyPointer(g, true, false);
}
// g.setColor(0Xff0000);
// g.fillArc(myPoint.nX, myPoint.nY, 10, 10, 0, 360);
} else {
switch (nPointerStrrMenu) {
case 0: {
g.setColor(0);
g.fillRect(0, 0, Consts.SN_SCREEN_WIDTH,
Consts.SN_SCREEN_HEIGHT);
g.setColor(0xffffff);
g.drawString("選擇關卡", Consts.SN_SCREEN_WIDTH >> 1, 1,
Graphics.TOP | Graphics.HCENTER);
//
int menuMaxNum = 5;
int t_array[] = new int[menuMaxNum];
int t_p_array_id = (menuMaxNum) / 2;
t_array[t_p_array_id] = nMapId - 1;
// ...
int k = 0;
for (int i = t_p_array_id - 1; i >= 0; i--) {
k++;
t_array[i] = (((Consts.SN_ABS_MAX_LEVEL + 1)
+ t_array[t_p_array_id] - k) % ((Consts.SN_ABS_MAX_LEVEL + 1)));
}
k = 0;
for (int i = t_p_array_id; i < menuMaxNum; i++) {
t_array[i] = ((t_array[t_p_array_id] + k) % ((Consts.SN_ABS_MAX_LEVEL + 1)));
k++;
}
//
int t_y = Consts.SN_SCREEN_HEIGHT
- (font.getHeight() + 2) * menuMaxNum;
t_y >>= 1;
for (int i = 0; i < t_array.length; i++) {
if (t_array[t_p_array_id] == t_array[i]) {
g.setColor(0xffffff);
} else {
if (t_array[i] < snLevelOpened + 1) {
g.setColor(0x999999);
} else {
g.setColor(0x555555);
}
}
g.drawString("第 " + (t_array[i] + 1) + " 關",
Consts.SN_SCREEN_WIDTH >> 1, t_y + (i)
* (font.getHeight() + 2),
Graphics.TOP | Graphics.HCENTER);
}
// g.setColor(0xffffff);
paintLeftRightKeyPointer(g, true, true);
}
break;
case 1: {
g.setColor(Consts.COLOR_GBLUE);
g.fillRect(0, 0, Consts.SN_SCREEN_WIDTH,
Consts.SN_SCREEN_HEIGHT);
g.setColor(Consts.COLOR_BLACK);
g.drawString(strrMenu[nPointerStrrMenu],
Consts.SN_SCREEN_WIDTH >> 1, 1, Graphics.TOP
| Graphics.HCENTER);
paintText(g, Consts.COLOR_BLACK, 0XFFFFFF);
// DOWN UP
int anDownX = (Consts.SN_SCREEN_WIDTH >> 1)
- (imageDown.getWidth());
int anUpX = (Consts.SN_SCREEN_WIDTH >> 1);
g.drawImage(imageDown, anDownX,
Consts.SN_SCREEN_HEIGHT - 1, Graphics.BOTTOM
| Graphics.LEFT);
g.drawImage(imageUp, anUpX,
Consts.SN_SCREEN_HEIGHT - 4, Graphics.BOTTOM
| Graphics.LEFT);
}
break;
case 2: {
g.setColor(Consts.COLOR_GBLUE);
g.fillRect(0, 0, Consts.SN_SCREEN_WIDTH,
Consts.SN_SCREEN_HEIGHT);
g.setColor(Consts.COLOR_BLACK);
g.drawString(strrMenu[nPointerStrrMenu],
Consts.SN_SCREEN_WIDTH >> 1, 1, Graphics.TOP
| Graphics.HCENTER);
paintText(g, Consts.COLOR_BLACK, 0XFFFFFF);
// DOWN UP
int anDownX = (Consts.SN_SCREEN_WIDTH >> 1)
- (imageDown.getWidth());
int anUpX = (Consts.SN_SCREEN_WIDTH >> 1);
g.drawImage(imageDown, anDownX,
Consts.SN_SCREEN_HEIGHT - 1, Graphics.BOTTOM
| Graphics.LEFT);
g.drawImage(imageUp, anUpX,
Consts.SN_SCREEN_HEIGHT - 4, Graphics.BOTTOM
| Graphics.LEFT);
}
break;
}
paintLeftRightKeyPointer(g, false, true);
}
}
break;
case SB_STATE_GAMEING: {
paintGamingState(g);
}
break;
}
}
}
public void drawHPMP(Graphics g) {
// int rect_height_max = 6;
// int rect_width_max = 40;
//
// g.setColor(0xffffff);
// g.drawRect(0, 120, rect_width_max + 1, rect_height_max + 1);
// int length = 0;
// length = npcLisa.nHP * rect_width_max / npcLisa.nHPMax;
// g.setColor(0xff0000);
// g.fillRect(0 + 1, 120 + 1, length, rect_height_max);
//
// g.setColor(0xffffff);
// g.drawRect(86, 120, rect_width_max + 1, rect_height_max + 1);
// length = npcLisa.nMP * rect_width_max / npcLisa.nMPMax;
// g.setColor(0x0000ff);
// g.fillRect(86 + 1, 120 + 1, length, rect_height_max);
//
// g.setColor(0xffffff);
// g.drawRect(86, 100, rect_width_max + 1, rect_height_max + 1);
// length = npcLisa.nEX * rect_width_max / npcLisa.nEXMax;
// g.setColor(0x00ff00);
// g.fillRect(86 + 1, 100 + 1, length, rect_height_max);
//
// //
// g.setColor(0xffffff);
// g.drawString("" + npcLisa.nLevel, 1, 100, Graphics.LEFT |
// Graphics.TOP);
}
final void paintWeather(Graphics g) {
// :)
g.setColor(0xeeeeee);
if (nR
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -