?? westgamecanvas.java~52~
字號(hào):
*/
private void drawLayer(Graphics g, int id, int xDraw, int yDraw)
{
drawId(g, id, xDraw, yDraw);
drawId(g, id, xDraw + screenWidth, yDraw);
if (yFar != 0)
{
mapId++;
drawId(g, id, xDraw, yDraw - screenHeight);
drawId(g, id, xDraw + screenWidth, yDraw - screenHeight);
mapId--;
}
}
/**
* 繪制一張圖片---------------------------1
*
* @param g
* @param id
* 0:遠(yuǎn)景 1:中景 2:近景
* @param xImg
* 繪圖的x坐標(biāo)
* @param yImg
* 繪圖的y坐標(biāo)
*
*/
private void drawId(Graphics g, int id, int xImg, int yImg)
{
if (mapId > 0)
{
// switch(gameLevel)
// {
// case 1:
// break;
// case 2:
// switch (id)
// {
// case 0:
// g.setColor(65, 144, 218);
// g.fillRect(0, yImg, screenWidth, screenHeight);
// return;
// case 1:
// return;
// }
// break;
// case 3:
// break;
// case 4:
// if(id==0)
// {
// g.setColor(86, 163, 226);
// g.fillRect(0, yImg, screenWidth, screenHeight);
// }
// break;
// }
// }
// }
if (( gameLevel == 1 || gameLevel == 4 ) && id == 0)
{
g.setColor(86, 163, 226);
g.fillRect(0, yImg, screenWidth, screenHeight);
return;
}
if (gameLevel == 2)
{
switch (id)
{
case 0:
g.setColor(65, 144, 218);
g.fillRect(0, yImg, screenWidth, screenHeight);
return;
case 1:
return;
}
}
if (gameLevel == 3)
g.drawImage(GameDataSimple.imgBack[id], xImg, yImg, 0);
else
g.drawImage(GameDataSimple.imgBack[id + 3], xImg, yImg, 0);
}
else
{
g.drawImage(GameDataSimple.imgBack[id], xImg, yImg, 0);
}
}
//----------------------------------------------------------------------back和map>
//-----------------------------------------------------------------------<surface
private void drawSurface(Graphics g)
{
g
.setClip(0, 0, WestGameCanvas.screenWidth,
WestGameCanvas.screenHeight);
//頭像
g.drawImage(GameDataSimple.imgSurface[0], 3, 3, 0);
//畫(huà)血
g.setColor(0xff0000);
int lif_w = 72 * WestGameCanvas.hp / 100;
g.fillRect(29, 8, lif_w, 3);
g.drawImage(GameDataSimple.imgSurface[1], 25, 7, 0);//畫(huà)血槽
//分?jǐn)?shù)
drawNum(score, 4, 110, 0, GameDataSimple.imgSurface[3], 15, 15, g);
//命數(shù)
drawNum(life, 1, 32, 14, GameDataSimple.imgSurface[2], 7, 7, g);
}
private void drawNum(int num, int nBit, int xStart, int yStart, Image img,
int srcFrameWidth, int srcFrameHeight, Graphics g)
{
//要繪制的字符串
String str = Integer.toString(num);
//補(bǔ)0的位數(shù)
int addZeroBite = nBit - str.length();
for (int j = 0; j < nBit; j++)
{
int useStartX = xStart;
//要繪制的字符
char currentDrawChar = j < addZeroBite ? '0' : str.charAt(j
- addZeroBite);
for (int i = 48; i < 58; i++)
{
if (currentDrawChar == i)
{
g.setClip(xStart, yStart, srcFrameWidth, srcFrameHeight);
g.drawImage(img, useStartX, yStart, 0);
break;
}
useStartX -= srcFrameWidth;
}
xStart += srcFrameWidth;
}
}
//-----------------------------------------------------------------------surface>
//-----------------------------------------------------------------------<sound
/* ************************************************* */
//TODO 播放聲音方法******************************** */
/* *********************************************** */
/**
* 打開(kāi)聲音
*
* @param idx
* 聲音文件序號(hào)
* @return 聲音對(duì)象
*/
private Player soundOpen(int idx)
{
//TODO 打開(kāi)聲音
try
{
return Manager.createPlayer(getClass().getResourceAsStream(
"/" + idx), "audio/midi");
}
catch (IOException e)
{
//Tools.txtOut("sound IOException");
}
catch (MediaException e)
{
//Tools.txtOut("sound MediaException");
}
return null;
}
/** 播放聲音 */
private void soundPlay()
{
int idx;
switch (0xf000000 & markNum)
{
case 0:
case 0x8000000:
idx = SOUND_MENU_IDX;
break;
case 0x2000000:
switch (gameState)
{
case 0://正常游戲
idx = SOUND_GAME_IDX;
break;
case 2://勝利
idx = SOUND_WIN_IDX;
break;
case 4://死了一條命
case 8://失敗
idx = SOUND_FAIL_IDX;
break;
default:
return;
}
break;
default:
return;
}
if (this.soundIdx != idx)
{
this.soundStop();
this.soundIdx = idx;
}
try
{
this.sounds[idx].realize();
this.sounds[idx].setLoopCount(-1);
VolumeControl soundVolumeControl = (VolumeControl) this.sounds[idx]
.getControl("VolumeControl");
soundVolumeControl.setLevel(60);
this.sounds[idx].start();
this.soundPlaying = true;
}
catch (MediaException e)
{
}
}
/** 停止聲音 */
private final void soundStop()
{
try
{
this.soundPlaying = false;
if (this.sounds[this.soundIdx] != null)
this.sounds[this.soundIdx].stop();
}
catch (MediaException e)
{
}
}
/**
* 關(guān)閉聲音
*
* @param idx
* 聲音數(shù)組的索引,退出游戲時(shí)為聲音數(shù)組最大索引號(hào),關(guān)卡切換時(shí)為0
*/
private final void soundClose(int idx)
{
for (; idx >= 0; idx--)
{
if (this.sounds[idx] == null)
continue;
this.sounds[idx].close();
this.sounds[idx] = null;
}
}
/* ************************************************* */
//TODO 聲音播放臨時(shí)變量***************************** */
/* *********************************************** */
/** 聲音索引 */
private static final byte SOUND_GAME_IDX = 0;
/** 聲音索引 */
private static final byte SOUND_FAIL_IDX = 1;
/** 聲音索引 */
private static final byte SOUND_WIN_IDX = 2;
/** 聲音索引 */
private static final byte SOUND_MENU_IDX = 3;
/** 聲音文件號(hào) */
private static final byte SOUND_FAIL_NUM = 4;
/** 聲音文件號(hào) */
private static final byte SOUND_WIN_NUM = 5;
/** 聲音文件號(hào) */
private static final byte SOUND_MENU_NUM = 6;
/** 播放對(duì)象數(shù)組 */
private Player sounds[] = new Player[4];
/** 聲音播放標(biāo)志 */
private boolean soundPlaying = false;
/** 聲音索引 */
private int soundIdx = SOUND_MENU_IDX;
/** 系統(tǒng)切換出去標(biāo)志 */
private boolean gameIsOut;
//-----------------------------------------------------------------------sound>
//-----------------------------------------------------------------------<rmd
/* ************************************************* */
//TODO 數(shù)據(jù)庫(kù)處理方法****************************** */
/* *********************************************** */
/**
* 開(kāi)啟紀(jì)錄倉(cāng)庫(kù)
*
* @param recordStoreName
* @param createIfNecessary
* true: 開(kāi)啟紀(jì)錄倉(cāng)庫(kù); false: 開(kāi)啟已經(jīng)存在的紀(jì)錄倉(cāng)庫(kù)
* @return RecordStore 紀(jì)錄倉(cāng)庫(kù)對(duì)象
*/
private RecordStore rsOpen(String recordStoreName, boolean createIfNecessary)
{
try
{
return RecordStore.openRecordStore(recordStoreName,
createIfNecessary);
}
catch (RecordStoreFullException e)
{
}
catch (RecordStoreNotFoundException e)
{
}
catch (RecordStoreException e)
{
}
return null;
}
/**
* 關(guān)閉數(shù)據(jù)庫(kù)
*
* @param rs
* RecordStore 數(shù)據(jù)庫(kù)對(duì)象
*/
private void rsClose(RecordStore rs)
{
try
{
rs.closeRecordStore();
}
catch (RecordStoreNotOpenException e)
{
}
catch (RecordStoreException e)
{
}
}
/**
* 向數(shù)據(jù)庫(kù)中加入記錄
*
* @param rs
* RecordStore 數(shù)據(jù)庫(kù)對(duì)象
* @param data
* byte[] 1維數(shù)據(jù)數(shù)組
*/
private void rsAddRecord(RecordStore rs, byte[] data)
{
try
{
rs.addRecord(data, 0, data.length);
}
catch (RecordStoreNotOpenException e)
{
}
catch (RecordStoreFullException e)
{
}
catch (RecordStoreException e)
{
}
}
/**
* 取得記錄
*
* @param rs
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -