?? mygamecanvas.java
字號:
/**
* <p>
* Title:
* </p>
* <p>
* Description:
*
* </p>
* <p>
* Copyright: Copyright (c) 2005
* </p>
* <p>
* Company:
* </p>
* 非作者授權,請勿用于商業用途。
* @author bruce.fine@gmail.com
* @version 1.0
*/
import javax.microedition.lcdui.*;
// import com.nokia.mid.ui.DirectUtils;
import java.io.*;
import java.util.*;
public final class MyGameCanvas extends MyCanvas {
//
//
static Image imageFire = null;
static Anim animFire = null;
//
static Image imageSuc = null;
static Image imageFailuer = null;
static Image imageX = null;
//
int nPowerCMax = 1;
int nBombNumCMax = 1;
// Anim animBullet = null;
Anim animLisa = null;
Anim animSaving = null;
Anim animZZ = null;
Anim animMouse = null;
Anim animBf = null;
//
Anim animHead = null;
Anim animBody = null;
Anim animEnd = null;
//
Image imageWugong = null;
Image imageBf = null;
static Image imageCi = null;
//
static MyGameCanvas instance;
//
static final short SN_TEXT_NUM_PER_ROW = 7;
static short SN_TEXT_ROWS_NUM_MAX = 0;
static short SN_TEXT_TOP_Y = 0;
static short SN_CHAR_WIDTH = 0;
static short SN_CHAR_HEIGHT = 0;
static short SN_TEXT_TOP_X = 0;
static short SN_TEXT_DIS = 0;
// GLOBAL
/*
* 狀態管理
*/
static final byte SB_STATE_LOADING = 0;
static final byte SB_STATE_SPLASH = 1;
static final byte SB_STATE_MENU = 2;
static final byte SB_STATE_GAMEING = 3;
static final byte SB_STATE_STORY_TELLING = 4;
/**
* bState狀態管理器
*/
static byte sbState = SB_STATE_LOADING;
static byte sbStateToLoad = SB_STATE_LOADING;
// 鍵盤
static int snKeyCodePressed = 0;
static int snKeyCodeReleased = 0;
// Font
static Font font = null;
static int snLevelOpened = 0;
// ------------------------------------------------------------------------------------------
// SPLASH 控制管理
// ------------------------------------------------------------------------------------------
static int nSlpashTimerC = 0;
// ------------------------------------------------------------------------------------------
// LOADING 控制管理
// ------------------------------------------------------------------------------------------
// static int nLoadingTimerC = 0;
// ------------------------------------------------------------------------------------------
// MENU 控制管理
// ------------------------------------------------------------------------------------------
String[] strrTextShows = null;
String[] strrTextForAbout = null;
String[] strrTextForHelp = null;
int nPointerStrrTextShow = 0;
String[] strrMenu = { "開始游戲", "幫助", "關于", "退出" };
int nPointerStrrMenu = 0;
boolean isStrrMenuButtonClicked = false;
//
static Image imageUp = null;
static Image imageDown = null;
static Image imageLeft = null;
static Image imageRight = null;
//
// ------------------------------------------------------------------------------------------
// GAME 控制管理
boolean isGameWin = false;
boolean isMenuInGameWorked = false;
boolean isFoorsMenuWorked = false;
boolean isScriptWorking = false;
boolean isKeyReponseMenu = false;
//
String[] strMenuFoors = { "狀態", "道具", "幫助" };
int nPStrMenuFoors = 0;
String[] strrFoos = { "蜂蜜", "水果", "蜂王漿", "甘露", "靈芝草", "人參" };
/**
*
* num_foos 分別有: 補血:蜂蜜,水果,蜂王漿 補氣:靈芝草,人參,甘露
*
*/
int[] num_foos = new int[] { 10, 10, 10, 10, 10, 10 };
int nPStrrFoos = 0;
int nStarPointer = 0;
int nPoundPointer = 3;
// 這個也需要記錄
// 非BOSS場景
String[] strrMenuInGame = { "繼續游戲", "回主菜單", "退出游戲" };
String[] strrMenuInGameResultFailur = { "重新游戲", "回主菜單", "退出游戲" };
String[] strrMenuInGameResultWin = { "繼續挑戰", "回主菜單", "退出游戲" };
// BOSS場景
String[] strrMenuInGameBOSS = { "繼續游戲", "回主菜單", "退出游戲" };
int nPorintStrrMenuInGame = 0;
//
short nMapId = 0;
//
boolean isMenuInGameForState = false;
// 地圖控制區域
// static Image[] imageTiles = null;
// 地圖絕對坐標
static int snWindowX = 0;
static int snWindowY = 0;
//
static int snMapWidth = 0;
static int snMapHeight = 0;
//
static byte[][] snsTiles = null;
// static boolean[][] sisTilesNull = null;
static int snTilesWidthNum = 0;
static int snTilesHeightNum = 0;
static int snMapX = 0;
static int snMapY = 0;
static int snTilesWidthNumInScreen = 0;
static int snTilesHeightNumInScreeen = 0;
static int snMapAreaWidthInScreen = 0;
static int snMapAreaHeightInScreen = 0;
// 滾動屏幕
static boolean isScrollMapLeft = false;
static boolean isScrollMapRight = false;
static boolean isScrollMapUp = false;
static boolean isScrollMapDown = false;
//
static Image imageSps = null;
static Image imageBox = null;
static Vector vecticUnits = null;
// static Image imageRabit = null;
static Image imageSaving = null;
static Image imageZZ = null;
static Image imageMouse = null;
static Image imageBall = null;
static Image imageDoor = null;
static Image imageMap = null;
// static MyImage[] myImage1d = null;
static Image imageBomb = null;
Anim animBomb = null;
//
int nTimerForDynTiles = 0;
static final int SN_TIMER_FOR_DYN_TILES_MAX = 2;
int nPointerDynTiles = 0;
static final int SN_DYN_TILES_MAX = 3;
//
NPC npcLisa = null;
CPC cpc = null;
CPC cpc2 = null;
// 數據控制,各種任務,對話等的標志位
/***************************************************************************
* 門是否被開啟 是否找到鑰匙
*
*/
byte[] data1D = null;
short[][] dataxy2d = null;
// 道具
// 任務用的道具
int[] num_foos_task = null;
int n_money = 0;
// 對話控制
//
short nDialogWindowX = 0;
short nDialogWindowY = 0;
short nDialogWindowWidth = 0;
short nDialogWindowHeight = 0;
short nDialogWindowTextX = 0;
short nDialogWindowTextY = 0;
short nFontHeight = 0;
short nFontDisY = 2;
//
boolean isDialogWorking = false;
int page = 0;
static final int ROW = 2;
int lastpage = 0;
String[] strDialog1D = null;
//
// 天氣系統
// 天氣狀況是否打開
int nRainOrSnow = 0; // 0 -> null, 1 -> rain, 2 -> snow
int[][] nRainOrSnowXY = null;
//
static boolean isStoryModeWorking = false;
String[] strStory = null;
short nLine = 0;
short nLineMax = 0;
short nLengthMax = 0;
short nTimerStory = 0;
short nTimerStoryMax = 0;
Random random = null;
//
int nTileWidth = Consts.SN_TILE_WIDTH;
int nTileHeight = Consts.SN_TILE_HEIGHT;
int nTileWidthForCalc = nTileWidth * 10;
int nTileHeightForCalc = nTileHeight * 10;
//
//
public void initStory() {
strStory = new String[] { "Lisa是太陽神", "的第7個女兒,", "她聰明伶俐,生", "活在夢幻之地的",
"幽幽山谷中。她", "擁有魔法,卻愛", "心十足,她心靈", "美好,卻不屈服", "于黑暗。一天怪",
"怪之森的惡魔", "Bruce偷走了月", "亮和星星,太陽", "不得不加班工作", ",天使傳信給",
"Lisa,讓她帶著", "父親給她的泡泡", "魔法前去與怪怪", "之森的惡魔", "Bruce戰斗,奪",
"回月亮和星星。" };
nLine = (short) -SN_TEXT_ROWS_NUM_MAX;
nLineMax = (short) (strStory.length);
nTimerStoryMax = 10;
nTimerStory = 0;
}
public void initDialog() {
page = 0;
isDialogWorking = true;
strDialog1D = new String[] { "我就是傳說中的上帝", ",現在賜予你力量,", "殺死 Bruce,人們",
"為你祈福." };
if (strDialog1D.length % ROW == 0) {
lastpage = (strDialog1D.length / ROW) - 1;
} else {
lastpage = (strDialog1D.length / ROW);
}
}
public void freeStrDialog() {
if (isScriptWorking) {
isScriptDialogWorked = true;
}
isDialogWorking = false;
strDialog1D = null;
lastpage = 0;
page = 0;
}
// 對話控制結束
/**
* 內部資源管理類實例
*/
LoadingGameRes loadingGameRes = null;
static int nGameScore = 0;
/**
* 構造
*/
public MyGameCanvas() {
instance = this;
isFivePressed = false;
font = Font.getFont(Font.FACE_SYSTEM, Font.STYLE_PLAIN,
Font.SIZE_MEDIUM);
random = new Random();
//
SN_CHAR_WIDTH = (short) font.getHeight();
SN_CHAR_HEIGHT = (short) font.getHeight();
SN_TEXT_DIS = (short) (font.getHeight() / 6); // 單距
SN_TEXT_ROWS_NUM_MAX = (short) (Consts.SN_SCREEN_HEIGHT
/ (SN_CHAR_HEIGHT + SN_TEXT_DIS) - 3);
SN_TEXT_TOP_X = (short) ((Consts.SN_SCREEN_WIDTH - SN_CHAR_WIDTH
* SN_TEXT_NUM_PER_ROW) >> 1);
SN_TEXT_TOP_Y = (short) (SN_CHAR_HEIGHT + SN_TEXT_DIS + SN_CHAR_HEIGHT / 2);
// INITGLOBAL
sbState = SB_STATE_SPLASH;
try {
int tempWidth = (short) (font.stringWidth("高") * SN_TEXT_NUM_PER_ROW);
nFontHeight = (short) font.getHeight();
nFontDisY = 4;
int nFontDisX = 8;
nDialogWindowWidth = (short) (tempWidth + nFontDisX * 2);
nDialogWindowHeight = (short) ((nFontHeight + nFontDisY) * ROW + nFontDisY);
nDialogWindowX = (short) ((Consts.SN_SCREEN_WIDTH - nDialogWindowWidth) / 2);
nDialogWindowY = (short) ((Consts.SN_SCREEN_HEIGHT - nDialogWindowHeight) - 1);
nDialogWindowTextX = (short) (nDialogWindowX + nFontDisX);
nDialogWindowTextY = (short) (nDialogWindowY + nFontDisY);
} catch (Exception ex) {
int tempWidth = (short) (16 * SN_TEXT_NUM_PER_ROW);
nFontHeight = (short) 16;
nFontDisY = 4;
int nFontDisX = 8;
nDialogWindowWidth = (short) (tempWidth + nFontDisX * 2);
nDialogWindowHeight = (short) ((nFontHeight + nFontDisY) * ROW + nFontDisY);
nDialogWindowX = (short) ((Consts.SN_SCREEN_WIDTH - nDialogWindowWidth) / 2);
nDialogWindowY = (short) ((Consts.SN_SCREEN_HEIGHT - nDialogWindowHeight) - 1);
nDialogWindowTextX = (short) (nDialogWindowX + nFontDisX);
nDialogWindowTextY = (short) (nDialogWindowY + nFontDisY);
}
}
/**
* 清理資源
*/
final void freeAllResource() {
// All of Resources will be free here
strrTextShows = null;
strrTextForHelp = null;
strrTextForAbout = null;
//
imageUp = null;
imageDown = null;
imageLeft = null;
imageRight = null;
//
// imageTiles = null;
//
imageSps = null;
vecticUnits = null;
//
//
npcLisa = null;
cpc = null;
cpc2 = null;
imageBox = null;
// imageRabit = null;
imageSaving = null;
imageZZ = null;
imageMouse = null;
imageDoor = null;
imageBomb = null;
// animBullet = null;
animBomb = null;
animLisa = null;
animSaving = null;
animZZ = null;
animBf = null;
animMouse = null;
//
animHead = null;
animBody = null;
animEnd = null;
imageWugong = null;
imageBf = null;
vecticUnits = null;
imageFire = null;
animFire = null;
imageSuc = null;
imageFailuer = null;
imageX = null;
//
}
boolean isFivePressed = false;
/**
* 載入
*/
final void initResource() {
switch (sbStateToLoad) {
case SB_STATE_SPLASH: {
}
break;
case SB_STATE_MENU: {
try {
//
imageUp = Image.createImage("/res/up.png");
imageDown = Image.createImage("/res/down.png");
imageLeft = Image.createImage("/res/left.png");
imageRight = Image.createImage("/res/right.png");
//
strrTextForAbout = new String[]{"bruce.fine", "@gmail.com:)"};
//
nPointerStrrTextShow = 0;
nPointerStrrMenu = 0;
isStrrMenuButtonClicked = false;
//
snLevelOpened = RMSSystem.loadLevelOpened();
// System.out.println("snLevelOpened:" + snLevelOpened);
if (snLevelOpened > Consts.SN_ABS_MAX_LEVEL) {
//
snLevelOpened = Consts.SN_ABS_MAX_LEVEL;
nMapId = 0;
} else {
//
nMapId = (short) (snLevelOpened + 1);
}
//
initWindowShow(10, 5);
} catch (Exception ex) {
ex.printStackTrace();
}
}
break;
case SB_STATE_GAMEING: {
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -