📄 ge.java
字号:
int res = 0;
for ( int i = num - 1; i >= 0; i-- ) {
res <<= 8;
res += b[ i + off ];
if ( b[ i + off ] < 0 )
res += 256;
}
return res;
}
static int readInt( byte[] b, int off)
{
return ( ((b[off]&0xff)<<24) | ((b[off+1]&0xff)<<16) | ((b[off+2]&0xff)<<8) | (b[off+3]&0xff) );
}
final static int INDEX_LEN = 4;
// load resources for each level -------------------------------------------
int loadString()
{
try
{
int count, len = 0;
DataInputStream is = new DataInputStream(this.getClass().getResourceAsStream("/s.bin"));
count = is.readUnsignedShort(); // data count == 4
is.skipBytes(count*INDEX_LEN);
len += 2 + count*INDEX_LEN;
if (m_text == null)
m_text = new String[count];
for (int i = 0; i < count; i++)
{
m_text[i] = is.readUTF();
len += 2 + m_text[i].length();
}
is.close();
return len;
}
catch (Exception e)
{
}
return 0;
}
// load index of tile map
int loadPlayfield()
{
try
{
int count, size, offset, len;
byte[] indexbytes = null;
DataInputStream is = new DataInputStream(this.getClass().getResourceAsStream("/p.bin"));
count = is.readUnsignedShort();
indexbytes = new byte[count*INDEX_LEN];
is.readFully(indexbytes, 0, count*INDEX_LEN); // string offset
if (m_levelSelected >= count || m_levelSelected < 0)
m_levelSelected = 0;
if (m_levelSelected > 0)
offset = readUnsignedInt(indexbytes, (m_levelSelected-1)*INDEX_LEN);
else
offset = 0;
size = readUnsignedInt(indexbytes, m_levelSelected*INDEX_LEN) - offset;
len = 2 + count * INDEX_LEN;
len += is.skipBytes(offset);
offset = readUnsignedInt(indexbytes, (count-1)*INDEX_LEN) - size - offset;
//len += loadPlayfield(is, size);
m_tileImageID = is.readUnsignedShort();
m_bgWidth = is.readUnsignedShort();
m_bgHeight = is.readUnsignedShort();
m_tileWidth = is.readUnsignedShort();
m_tileHeight = is.readUnsignedShort();
len += 10;
size -= 10;
m_mapBuf = new byte[size];
len += is.read(m_mapBuf, 0, size);
//loadPlayfield
len += is.skipBytes(offset);
is.close();
return len;
}
catch (Exception e)
{
}
return 0;
}
int loadScene()
{
try
{
int count, size, offset, actorCount, actorSize, len, actorID;
byte[] indexbytes = null;
DataInputStream is = new DataInputStream(this.getClass().getResourceAsStream("/c.bin"));
count = is.readUnsignedShort(); // scene data count
indexbytes = new byte[count*INDEX_LEN];
is.readFully(indexbytes, 0, count*INDEX_LEN); // string offset
if (m_levelSelected > 0)
offset = readUnsignedInt(indexbytes, (m_levelSelected-1)*INDEX_LEN);
else
offset = 0;
size = readUnsignedInt(indexbytes, m_levelSelected*INDEX_LEN) - offset;
len = 2 + count * INDEX_LEN;
len += is.skipBytes(offset);
len += m_player.loadActors(is, size);
offset = readUnsignedInt(indexbytes, (count-1)*INDEX_LEN) - size - offset;
len += is.skipBytes(offset);
is.close();
return len;
}
catch (Exception e)
{
}
return 0;
}
int loadAnimation()
{
try
{
int count, size, len;
DataInputStream is = new DataInputStream(this.getClass().getResourceAsStream("/a.bin"));
count = is.readUnsignedShort(); // animations count
len = 2;
Player.m_anims = new Animation[count];
for (int i = 0; i < count; i++)
{
size = is.readUnsignedShort(); // animation data size
len += 2;
Animation a = new Animation();
Player.m_anims[i] = a;
len += a.loadAnimation(is);
}
is.close();
return len;
}
catch (Exception e)
{
}
return 0;
}
// free resources after complete a level -----------------------------------
void freeLevelData()
{
m_levelLoad = -1;
m_mapBuf = null;
m_player.freePlayer();
}
//==========================================================================
// Image Process
//==========================================================================
// Initialize images -------------------------------------------------------
static void loadImages(boolean misc)
{
try
{
if (m_imageMisc == null)
m_imageMisc = Image.createImage( "/misc.png" );
if (!misc)
{
switch (m_progress)
{
case 4:
if (m_imagePrince == null)
m_imagePrince = Image.createImage( "/prince.png" );
break;
case 5:
if (m_imageSandman == null)
m_imageSandman = Image.createImage( "/sandman.png" );
break;
case 6:
if (m_imageTilekit == null)
m_imageTilekit = Image.createImage( "/"+m_text[m_tileImageID] );
break;
case 7:
if (m_imageFire == null)
m_imageFire = Image.createImage( "/fire.png" );
break;
case 8:
if (m_imageWater == null)
m_imageWater = Image.createImage( "/water.png" );
break;
}
}
}
catch ( Exception e )
{
//handleException("image Init", e);
}
}
static void freeImages(boolean misc)
{
m_imageFire = null;
m_imageWater = null;
m_imagePrince = null;
m_imageSandman = null;
m_imageTilekit = null;
if (misc)
{
m_imageMisc = null;
}
}
//==========================================================================
// Sound & Vibrate Process
//==========================================================================
//----------------------------------------------------------
void soundInit()
{
try
{
m_sound = new SoundPlayer();
m_sound.init();
new Thread(m_sound).start();
}
catch (Exception e)
{
}
/*
try
{
int num, offset0, offset1, len, size;
byte[] indexbytes;
String fileName = "/sound.bin";
java.io.InputStream is = fileName.getClass().getResourceAsStream(fileName);
indexbytes = new byte[4];
is.read( indexbytes );
m_melodyNum = ReadInt( indexbytes, 0, 4 ) - 1;
m_SoundTracks = new javax.microedition.media.Player[m_melodyNum];
indexbytes = new byte[4*m_melodyNum+4];
is.read( indexbytes, 0, 4*m_melodyNum+4 );
offset0 = 0;
for ( int i = 0; i < m_melodyNum; i++ )
{
offset1 = ReadInt( indexbytes, 4*i+4, 4 );
len = offset1 - offset0;
byte[] melody = new byte[len];
size = is.read( melody, 0, len );
ByteArrayInputStream bis = new ByteArrayInputStream(melody);
m_SoundTracks[i] = Manager.createPlayer(bis, "audio/midi");
m_SoundTracks[i].realize();
offset0 = offset1;
melody = null;
bis = null;
}
is.close();
}
catch ( Exception e )
{
//handleException("Sound Init", e);
}
//*/
}
//----------------------------------------------------------
static void playSound( int id, int loop )
{
///*
if ( m_playSound == 0 )
return;
if ( id < -1 || id >= m_sound.m_melodyNum )
return;
stopSound();
if ( id == -1 )
return;
m_sound.play(id);
//*/
}
//----------------------------------------------------------
static void stopSound()
{
///*
m_sound.stop();
//*/
}
/** draw bg 's part which is in camera. <br>
*
* fastDraw can not draw transparent bg, because when tiles draw to m_bgImage,
* the transparent info missed.<br>
* bg[0]'s must = map's size, and not transparent. If it's transparent,
* what should draw to the map area when no bg ? <br>
* So fastDraw can only used for bg[0];
*
* @param g : the screen
* @param cx
* @param cy : the camera's postion in map
* @param cw
* @param ch screen's width & height
*/
void mapFastDraw(int camX, int camY)
{
int alignedX0, alignedY0, alignedX1, alignedY1, start, end; // tile
int modX0, modX1, modY0, modY1; // pixel
Graphics gb = m_imageBg.getGraphics();
alignedX0 = camX / m_tileWidth;
//if ((camX % m_tileWidth) < 0) alignedX0--;
alignedX1 = alignedX0 + Def.PF_WIDTH / m_tileWidth + 1;
alignedY0 = camY / m_tileHeight;
//if ((camY % m_tileHeight) < 0) alignedY0--;
alignedY1 = alignedY0 + Def.PF_HEIGHT / m_tileHeight + 1;
// Lyman DEBUG
//m_piece[7] = System.currentTimeMillis() - m_piece[3];
if (m_updateBg)
{
m_updateBg = false;
mappedDraw(gb, alignedX0, alignedY0, alignedX1, alignedY1);
m_prevX0 = alignedX0;
m_prevY0 = alignedY0;
m_prevX1 = alignedX1;
m_prevY1 = alignedY1;
}
if (m_prevX0 != alignedX0)
{
if(m_prevX0 < alignedX0)
{
start = m_prevX1+1;
end = alignedX1;
}
else
{
start = alignedX0;
end = m_prevX0-1;
}
mappedDraw(gb, start, alignedY0, end, alignedY1);
m_prevX0 = alignedX0;
m_prevX1 = alignedX1;
}
if (m_prevY0 != alignedY0)
{
if(m_prevY0 < alignedY0)
{
start = m_prevY1+1;
end = alignedY1;
}
else
{
start = alignedY0;
end = m_prevY0-1;
}
mappedDraw(gb, alignedX0, start, alignedX1, end);
m_prevY0 = alignedY0;
m_prevY1 = alignedY1;
}
// Lyman DEBUG
//m_piece[8] = System.currentTimeMillis() - m_piece[3] - m_piece[7];
modX0 = camX % m_bufWidth;
modY0 = camY % m_bufHeight;
modX1 = (camX + Def.PF_WIDTH) % m_bufWidth;
modY1 = (camY + Def.PF_HEIGHT) % m_bufHeight;
//if (modX0 < 0) modX0 += m_bufWidth;
//if (modY0 < 0) modY0 += m_bufHeight;
//if (modX1 < 0) modX1 += m_bufWidth;
//if (modY1 < 0) modY1 += m_bufHeight;
if(modX1 > modX0)
{
if(modY1 > modY0)
{
copyFromBackImage(modX0, modY0, Def.PF_WIDTH, Def.PF_HEIGHT, 0, Def.PF_TOP);
}
else
{
copyFromBackImage(modX0, modY0, Def.PF_WIDTH, Def.PF_HEIGHT - modY1, 0, Def.PF_TOP);
copyFromBackImage(modX0, 0, Def.PF_WIDTH, modY1, 0, Def.PF_TOP + Def.PF_HEIGHT - modY1);
}
}
else
{
if(modY1 > m
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -