📄 ge.java
字号:
{
strTemp = STR_OPTION[i];
if (i == 1)
strTemp += (m_playHint!=0?"On":"Off");
else if (i == 2)
strTemp += (m_playSound!=0?(m_playSound!=1?"High":"Low"):"Off");
if (i==index)
afficheSmall(strTemp, -1, y, Def.TEXT_COLOR9, 0);
else
afficheSmall(strTemp, -1, y, clr, 0);
y += sFont_H;
}
break;
}
}//*/
/* display menu item
private void displayMenu(int y, int index, int clr)
{
String strTemp = "";
if (m_gameState == Def.STATE_MENU)
{
index = (index+MENU_ITEM_NUM) % MENU_ITEM_NUM;
strTemp = STR_MENU[index];
if (index == 3)
strTemp += (m_playHint!=0?"On":"Off");
else if (index == 4)
strTemp += (m_playSound!=0?"On":"Off");
afficheSmall(strTemp, -1, y, clr, -1);
}
else // STATE_PAUSE
{
index = (index+PAUSE_ITEM_NUM) % PAUSE_ITEM_NUM;
strTemp = STR_PAUSE[index];
if (index == 1)
strTemp += (m_playHint!=0?"On":"Off");
else if (index == 2)
strTemp += (m_playSound!=0?"On":"Off");
afficheSmall(strTemp, -1, y, clr, 0);
}
//if (m_lastFrameTime % 1000 > 500) // left & right arrow
//{
// m_g.setClip(26, y, 10, 18);
// m_g.drawImage(m_imageMisc, 26-100, y-24, TOPLEFT);
// m_g.setClip(Def.SCREEN_WIDTH-38, y, 10, 18);
// m_g.drawImage(m_imageMisc, Def.SCREEN_WIDTH-38-108, y-24, TOPLEFT);
//}
}//*/
// display level selected
private void displayLevel(int x, int y, int level, int clr)
{
level = (level+Def.LEVEL_NUMBER) % Def.LEVEL_NUMBER;
if (m_levelPassed[level] == 0)
clr /= 4;
afficheSmall("Level "+(level+1), -1, y, clr, -1);
}
// display options in the bottom corner
static private void displayOption(String left, String right)
{
if (left != null)
afficheSmall(left, 2, Def.SCREEN_HEIGHT-sFont_H, Def.TEXT_COLOR0, 0);
if (right != null)
afficheSmall(right, Def.SCREEN_WIDTH-sFont.stringWidth(right)-2, Def.SCREEN_HEIGHT-sFont_H, Def.TEXT_COLOR0, 0);
}
final static int SYMBOL_HINT = 0;
final static int SYMBOL_FACE = 1;
final static int SYMBOL_UBILOGO = 2;
static private void drawSymbol(int index)
{
switch (index)
{
case SYMBOL_HINT: // triangle
m_g.setClip( Def.SCREEN_WIDTH - 15, Def.SCREEN_HEIGHT - 11, 14, 8 );
m_g.drawImage(m_imageMisc, Def.SCREEN_WIDTH - 15-100, Def.SCREEN_HEIGHT - 11-24, TOPLEFT);
break;
case SYMBOL_FACE: // face
m_g.setClip(3, 3, 18, 22);
m_g.drawImage(m_imageMisc, 3-110, 3-91, TOPLEFT);
break;
case SYMBOL_UBILOGO:
if (m_images[Def.PNG_UBILOGO] != null)
{
m_g.setClip(0, 0, Def.SCREEN_WIDTH, Def.SCREEN_HEIGHT);
m_g.drawImage(m_images[Def.PNG_UBILOGO], Def.SCREEN_WIDTH/2, Def.SCREEN_HEIGHT-20, Graphics.HCENTER | Graphics.BOTTOM);
}
}
}
// Display progress --------------------------------------------------------
private void displayProgress(int pos, int max )
{
m_g.setClip( 16, Def.SPLASH_TEXT_Y+sFont_H*2, Def.SCREEN_WIDTH - 32, 5 );
m_g.setColor(0xFFFFFF);
m_g.drawRect(16, Def.SPLASH_TEXT_Y+sFont_H*2, Def.SCREEN_WIDTH - 32, 5);
if (pos > 0)
m_g.fillRect(16, Def.SPLASH_TEXT_Y+sFont_H*2, pos * (Def.SCREEN_WIDTH - 32) / max, 5);
}
/* scroll
boolean displayString(String strText)
{
int indexStart = 0, indexEnd;
int posX = (Def.SCREEN_WIDTH - sFont.stringWidth("www.gameloft.com"))/2;
int posY = Def.SCREEN_HEIGHT - m_textCounter;
boolean over = false;
String temp;
switchImage(Def.SWITCH_STORY);
m_g.drawImage(m_images[Def.PNG_STORY], Def.SCREEN_WIDTH/2, Def.SCREEN_HEIGHT/2, CENTER);
for (int i = 0; ; i++)
{
if (posY > Def.SCREEN_HEIGHT)
break;
indexEnd = strText.indexOf('^', indexStart);
if (indexEnd == -1)
indexEnd = strText.length();
temp = strText.substring(indexStart, indexEnd);
afficheSmall(temp, posX, posY, 0xffffff, -1 );
posY += sFont_H + 1;
indexStart = indexEnd + 1;
if (indexStart > strText.length())
{
if (posY < 0)
{
over = true;
m_textCounter = Def.TEXT_OVER;
}
break;
}
}
m_textCounter+=2;
return over;
}
*/
void displayString(String strText)
{
int indexStart = 0, indexEnd;
//int posX = (Def.SCREEN_WIDTH - m_fontMsg.stringWidth("www.gameloft.com"))/2;
int lines = Def.STRING_LINES;//(Def.SCREEN_HEIGHT - 2) / (sFont_H + 1);
int posY = Def.STRING_Y - m_textCounter * (sFont_H + 1);//((Def.SCREEN_HEIGHT - 2) % (sFont_H + 1)) / 2 - m_textCounter * (sFont_H + 1);
String temp;
m_textOver = false;
for (int i = 0; ; i++)
{
if (posY >= Def.STRING_Y + (sFont_H + 1) * lines)
break;
indexEnd = strText.indexOf('^', indexStart);
if (indexEnd == -1)
indexEnd = strText.length();
temp = strText.substring(indexStart, indexEnd);
if (posY >= Def.STRING_Y)
{
afficheSmall(temp, (Def.SCREEN_WIDTH-sFont.stringWidth(temp))/2+1, posY+1, 0x444444, -1 );
afficheSmall(temp, -1, posY, Def.TEXT_COLOR9, -1 );
}
posY += sFont_H + 1;
indexStart = indexEnd + 1;
if (indexStart > strText.length())
{
m_textOver = true;
return;
}
}
if (m_lastInput != Def.KEY_NONE)
{
m_textCounter += lines;
resetKey();
}
}
static boolean drawMessage(String msg, int line)
{
int indexStart = 0;
int indexEnd;
boolean over = true;
String temp;
for (int i = 0; ; i++)
{
indexEnd = msg.indexOf('^', indexStart);
if (indexEnd == -1)
indexEnd = msg.length();
if (i == line)
{
temp = msg.substring(indexStart, indexEnd);
afficheSmall(temp, -1, Def.SCREEN_HEIGHT - sFont_H - 1, 0xffffff, 0 );
//y += sFont_H;
over = false;
break;
}
indexStart = indexEnd + 1;
if (indexStart > msg.length())
break;
}
return over;
}
/**
* Because of the shortage of memory, there is only one part of image can be created in buffer
* @param imageType : which image should the big buffer for.
* 0, clear all image buffer
* 1, create menu & logo image
* 2, create back image buffer
* 3, v1.png for PNG_VI
* 4, v2.png for PNG_VI
* 5, controls.png for PNG_CONTROLS
* 6, credits.png for PNG_CREDITS
*/
void switchImage(int imageType)
{
int curType = Def.SWITCH_NONE;
if (m_imageBg != null)
curType = Def.SWITCH_BG;
else if (m_images[Def.PNG_MENU] != null)
curType = Def.SWITCH_MENU;
else if (m_images[Def.PNG_STORY] != null)
curType = Def.SWITCH_STORY;
if (curType == imageType)
return;
if (curType == Def.SWITCH_BG)
{
m_imageBg = null;
System.gc();
}
switch(imageType)
{
case Def.SWITCH_MENU:
m_images[ Def.PNG_STORY ] = null;
if (m_images[Def.PNG_MENU] == null)
loadImage( Def.PNG_MENU, "/menu.png" );
if (m_images[Def.PNG_SPLASH] == null)
loadImage( Def.PNG_SPLASH, "/splash.png" );
break;
case Def.SWITCH_STORY:
m_images[ Def.PNG_MENU ] = null;
m_images[ Def.PNG_SPLASH ] = null;
if (m_images[Def.PNG_STORY] == null)
loadImage( Def.PNG_STORY, "/story.png" );
break;
case Def.SWITCH_NONE:
case Def.SWITCH_BG:
m_images[ Def.PNG_MENU ] = null;
m_images[ Def.PNG_SPLASH ] = null;
m_images[ Def.PNG_STORY ] = null;
System.gc();
if (imageType == Def.SWITCH_BG)
{
//final private void initPlayfield()
//{
m_tileCountPerLine = m_imageTilekit.getWidth() / m_tileWidth;
// tile dimension is fixed 8 * 8
m_bufWidth = (Def.PF_WIDTH + m_tileWidth * 2) & ~(m_tileWidth-1);
m_bufHeight = (Def.PF_HEIGHT + m_tileHeight * 2) & ~(m_tileHeight-1);
m_imageBg = Image.createImage(m_bufWidth, m_bufHeight);
m_updateBg = true;
//}
}
break;
}
}
static boolean loadImage( int imageID, String file )
{
try
{
m_images[imageID] = Image.createImage( file );
return true;
}
catch ( Exception e )
{
System.out.println("Load Image " + file + " failed: "+e.toString());
//handleException("load image: " + file, e);
}
return false;
}
//==========================================================================
// Read Files
//==========================================================================
static void loadRecord()
{
try
{
RecordStore rs = RecordStore.openRecordStore("POP2RECORD", true);
//If record exist
if (rs.getNumRecords() > 0 && rs.getRecord (1, record, 0) == RECORD_LENGTH)
{
int i;
for (i = 0 ; i < Prince.ABILITY_NUMBER; i++)
{
Prince.ability[i] = record[i];
}
for (i = 0; i < Def.LEVEL_NUMBER; i++)
{
m_levelPassed[i] = record[i+10];
}
m_playSound = record[20];
m_playHint = record[21];
for (i = 0; i < Def.LEVEL_NUMBER; i++)
{
m_levelScore[i] = (short)((record[i*2+30] & 0xff) + (record[i*2+31]<<8));
}
}
else
{
resetRecord();
}
rs.closeRecordStore();
}
catch(Exception e)
{
System.out.println("Load Record Exception: "+e);
}
}
static void resetRecord()
{
for (int i = 0; i < Prince.ABILITY_NUMBER; i++)
Prince.ability[i] = 0;
for (int i = 0; i < Def.LEVEL_NUMBER; i++)
m_levelPassed[i] = 0;
}
//--------------------------------
static void saveRecord()
{
try
{
RecordStore rs = RecordStore.openRecordStore("POP2RECORD", false);
int i;
for (i = 0 ; i < Prince.ABILITY_NUMBER; i++)
{
record[i] = Prince.ability[i];
}
for (i = 0; i < Def.LEVEL_NUMBER; i++)
{
record[i+10] = m_levelPassed[i];
}
record[20] = m_playSound;
record[21] = m_playHint;
for (i = 0; i < Def.LEVEL_NUMBER; i++)
{
record[i*2+30] = (byte)m_levelScore[i];
record[i*2+31] = (byte)(m_levelScore[i]>>8);
}
if (rs.getNumRecords() > 0)
rs.setRecord (1, record, 0, RECORD_LENGTH);
else
rs.addRecord (record, 0, RECORD_LENGTH);
rs.closeRecordStore();
}
catch(Exception e)
{
System.out.println("Save Record Exception: "+e);
}
}
/**
* convert 2 or 4 bytes as unsigned into short or int number respectively
* @param b buffer contains ints in little endian
* @param off offset of those bytes in buffer
* @return int
*/
final static int readUnsignedShort(byte[] b, int off)
{
int res = b[off++];
if (res < 0) res += 256;
res <<= 8;
res += b[off];
if (b[off] < 0) res += 256;
return res;
}
final static int readUnsignedInt(byte[] b, int off)
{
int res = 0;
for (int i = 0; i < 4; i++, off++)
{
res <<= 8;
res += b[off];
if (b[off] < 0) res += 256;
}
return res;
}
/**
* convert 2 or 4 bytes into short or int number respectively
* @param b buffer contains ints in little endian
* @param off offset of those bytes in buffer
* @param num convert a short, 4 convert a int
* @return int
*/
static int ReadInt( byte[] b, int off, int num )
{
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -