📄 aims.java
字号:
// ObjectDB [x][11] = OBJDATA 4
// ObjectDB [x][12] = points for this object when the player hits this object
// ObjectDB [c][13] = OBJDATA 5 (specjally for tank; pointer for tank's turret since object are not Born static
midlet = mymidlet;
rand=new Random();
try{
//read recordStore
records = RecordStore.openRecordStore("AIMS", true);
//if no entires means first time so we have to allow language choosing
if(records.getNumRecords()<1){
//language temp
Vector vlangs=new Vector();
DataInputStream din=null;
try{
for(int i=0;;i++){
din=new DataInputStream(getClass().getResourceAsStream("/LANG"+i+".JUTF"));
vlangs.addElement(din.readUTF());
din.close();
din=null;
}
}catch(Exception e){
//#if _DEBUG_
//# e.printStackTrace();
//#endif
}
langs=new String[vlangs.size()];
for(int i=0;i<vlangs.size();i++)
langs[i]=(String)vlangs.elementAt(i);
vlangs.removeAllElements();
//fill higscore entries to empty
temp1=6;
//#if _V220_
//# temp1=3;
//#endif
for(int i=0;i<temp1;i++){
hnames.addElement(new String("..."));
hpoints.addElement(new Integer(0));
}
//set a pointer to first language temp1 will be a pointer for gamemode 0
temp1=0;
}else{//that means we have at least language chosen
byte[] data=records.getRecord(1);
DataInputStream in = new DataInputStream(new ByteArrayInputStream(data));
loadLanguage(in.readByte());
in.close();
//we have to set the gamemode to 1 to show the intro
//switch to intro mode
gamemode=1;
//set the intro bkg color to white
temp1=255;
//so if we have language we have also a records for highscore and continue but maybe empty
//try to read highscores
if((data=records.getRecord(2))!=null){
in = new DataInputStream(new ByteArrayInputStream(data));
try{
while(true){
hnames.addElement(in.readUTF());
hpoints.addElement(new Integer(in.readInt()));
}
}catch(Exception he){
//#if _DEBUG_
//# he.printStackTrace();
//#endif
}
in.close();
}
//try to read a paused game data
if((data=records.getRecord(3))!=null){
in = new DataInputStream(new ByteArrayInputStream(data));
//level
//lifes
//points
//player power
//player missiles
//player smartbombs
level=in.readInt();
lifes=in.readInt();
score=in.readInt();
player_power=in.readByte();
player_missiles=in.readByte();
player_sbombs=in.readByte();
//set menu pode to continue
menumode=1;
}
}
}catch(Exception e){
//#if _DEBUG_
//# e.printStackTrace();
//#endif
}
//prepare unchangable music (rest in tmepGFXUpdate_
//#if _MMAPI_
//# try{
//# VolumeControl vc=null;
//# title_music=Manager.createPlayer(getClass().getResourceAsStream("aims-titel.MID"),"audio/midi");
//# title_music.realize();
//# title_music.setLoopCount(-1);
//# vc=(VolumeControl)title_music.getControl("VolumeControl");
//# vc.setLevel(50);
//#
//# endboss_music=Manager.createPlayer(getClass().getResourceAsStream("aims-endboss.MID"),"audio/midi");
//# endboss_music.realize();
//# endboss_music.setLoopCount(-1);
//# vc=(VolumeControl)endboss_music.getControl("VolumeControl");
//# vc.setLevel(50);
//#
//# stage1_music=Manager.createPlayer(getClass().getResourceAsStream("1.MID"),"audio/midi");
//# stage1_music.realize();
//# stage1_music.setLoopCount(-1);
//# vc=(VolumeControl)stage1_music.getControl("VolumeControl");
//# vc.setLevel(50);
//#
//# stage2_music=Manager.createPlayer(getClass().getResourceAsStream("2.MID"),"audio/midi");
//# stage2_music.realize();
//# stage2_music.setLoopCount(-1);
//# vc=(VolumeControl)stage2_music.getControl("VolumeControl");
//# vc.setLevel(50);
//#
//# stage3_music=Manager.createPlayer(getClass().getResourceAsStream("3.MID"),"audio/midi");
//# stage3_music.realize();
//# stage3_music.setLoopCount(-1);
//# vc=(VolumeControl)stage3_music.getControl("VolumeControl");
//# vc.setLevel(50);
//#
//# stage_music=stage1_music;
//# //endboss_music.deallocate();
//#
//# }catch(Exception e){
//#if _DEBUG_
//# e.printStackTrace();
//#endif
//# }
//#elif _NOKIA_
try{
collecting_s=new Sound(collecting_s_data,Sound.FORMAT_TONE);
tile_music_s=new Sound(tile_music_s_data,Sound.FORMAT_TONE);
smartbomb_s=new Sound(smartbomb_s_data,Sound.FORMAT_TONE);
}catch(Exception e){
//#if _DEBUG_
//# e.printStackTrace();
//#endif
}
//#endif
}
/*###################################################################### */
// KEYBOARD REQUEST
/*##################################################################### */
protected void keyPressed(int keyCode) {
if(keyCode==LSOFTKEY || keyCode==RSOFTKEY)
game_keypressed=FIRE;
else game_keypressed = getGameAction(keyCode);
keypressed = keyCode;
}
protected void keyReleased(int keyCode) {
game_keypressed = 0;
keypressed = 0;
}
/*##################################################################### */
// animation task for the main game loop
/* class AnimationTask extends TimerTask {
public AnimationTask(Aims mymidlet) {
Aims midlet = mymidlet;
}
*/
public void run(){
Thread thread=Thread.currentThread();
long timer;
int loop=1000/FPS;
while(th==thread){
timer=System.currentTimeMillis();
try {
DoAll();
}catch (Exception e) {
//System.out.println("E="+e);
//#if _DEBUG_
//# e.printStackTrace();
//#endif
}
int t=sleep(thread,timer,loop);
//#if _FPS_COUNT_
//# if(t>0){FPS++;loop=1000/FPS;}
//# else if(t<0){FPS--;loop=1000/FPS;}
//#endif
}
}
// }
/*##################################################################### */
public void saveRMS(){
byte[] data;
ByteArrayOutputStream bais;
DataOutputStream out;
try{
//save highscore if any
if(hnames.size()!=0){
bais = new ByteArrayOutputStream();
out = new DataOutputStream(bais);
for(int i=0;i<hnames.size();i++){
out.writeUTF((String)hnames.elementAt(i));
out.writeInt(((Integer)hpoints.elementAt(i)).intValue());
}
out.close();
data=bais.toByteArray();
records.setRecord(2,data,0,data.length);
data=null;
bais.close();
//otherwise save as null
}else records.setRecord(2,null,0,0);
//save paused game if any
if(lifes>-1){
bais = new ByteArrayOutputStream();
out = new DataOutputStream(bais);
//level
//lifes
//points
//player power
//player missiles
//player smartbombs
out.writeInt(level);
out.writeInt(lifes);
out.writeInt(score);
out.writeByte(player_power);
out.writeByte(player_missiles);
out.writeByte(player_sbombs);
out.close();
data=bais.toByteArray();
records.setRecord(3,data,0,data.length);
bais.close();
}else records.setRecord(3,null,0,0);
records.closeRecordStore();
}catch(Exception e){
//#if _DEBUG_
//# e.printStackTrace();
//#endif
}
}
/*##################################################################### */
/*this method load a language string from specified file
*strings are represented in Java modified UTF format
*/
void loadLanguage(int lang){
try{
DataInputStream din=new DataInputStream(getClass().getResourceAsStream("/LANG"+lang+".JUTF"));
//skip first string witch is a language string
din.readUTF();
LOADING_STR=din.readUTF();
LEV_STR=din.readUTF();
GETREADY_STR=din.readUTF();
RESTROOPS_STR=din.readUTF();
YOUHAVERES_STR=din.readUTF();
TROOPS_STR=din.readUTF();
PRESSFIRE_STR=din.readUTF();
LIFELOST_STR=din.readUTF();
GAMEOVER_STR=din.readUTF();
MISSIONFAILED_STR=din.readUTF();
SCORE_STR=din.readUTF();
CONGRATULATIONS_STR=din.readUTF();
LEVCLEARED_STR=din.readUTF();
YOURSCORE_STR=din.readUTF();
MSTARTMISSION_STR=din.readUTF();
MCONTINUE_STR=din.readUTF();
MSOUND_STR=din.readUTF();
MMUSIC_STR=din.readUTF();
ON_STR=din.readUTF();
OFF_STR=din.readUTF();
MVIEWHIGHSCORE_STR=din.readUTF();
MVIEWHELP_STR=din.readUTF();
MABOUT_STR=din.readUTF();
MSAVEQUIT_STR=din.readUTF();
NEWHIGHSCORE_STR=din.readUTF();
ENTERNAME_STR=din.readUTF();
HIGHSCORES_STR=din.readUTF();
HELP_STR=din.readUTF();
CREDITS_STR=din.readUTF();
EXIT_STR=din.readUTF();
OK_STR=din.readUTF();
LANDNOW_STR=din.readUTF();
PAUSE_STR=din.readUTF();
RESTARTMISSION_STR=din.readUTF();
ALPHABET=din.readUTF();
HHELP_STR=din.readUTF();
CCREDITS_STR=din.readUTF();
GAMEEND_STR=din.readUTF();
din.close();
}catch(Exception e){
//#if _DEBUG_
//# e.printStackTrace();
//#endif
}
}
/*##################################################################### */
public void DoAll() {
// FOR EVER GAME LOOP
//CLIPPING VARIABLE IS !=0 we have to implement wipe in/out effect
//unfortunatelly most of intresting things wil be made here like loading gfx
// all becouse of this moment beetween wipe in and out is all in here
if(clipping_var!=0){
//this means the is wipe in
if(clipping_var >0){
clipping+=clipping_var;
if(clipping>screenY/2){
clipping=screenY/2;
//abnormal function just TEMP I HOPE
//we have to prepare some things before wipe out; depends on desired_mode
switch(desired_mode){
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -