llet2.setVisible(false);jiangli=11;
slife=85;drawslife=0;
playerno=playerno+1;sbz=-1;//sbos sbpzbz=1;}
if((sboss.getY()==getHeight())){
sbz=-1;sbpzbz=1;drawadd=21;
}if(drawadd==21){sboss.move(0,-3);
if(sboss.getY()<-65){
sboss.setVisible(false);drawadd=31;
}}if(planert==1){inputno=1;
pzbz=1;s2=65;c1.setImage(img("/pic/MyPlaneFrames.png"),24,24);c1.setFrame(0);c1.setVisible(true);
c1.setPosition(getWidth()/2,planepo+48);
planert=2;
}if(planert==2)
{c1.move(0,-2);if(c1.getY()<(planepo-24))
{System.out.println(c1.getY());
System.out.println(planepo-24);inputno=0;
s1=1;
planert=3;}if(c1.getY()>(planepo+24))
{c1.move(0,-2);}}
et=System.currentTimeMillis();
if((et-st)
planepo){jiangli=20;
}}if(s1==1){g.setColor(255,255,255);
g.fillRect(170,22,65,5);g.setColor(255,0,0);
g.fillRect(170,22,s2,5);g.drawString("无敌时间",124,18,0);drawadd=1;s2=s2-1;
if(s2==0){pzbz=0;s1=2;}}
flushGraphics();}publicvoidrenderboss(Graphicsg){lm.setViewWindow(0,0,getWidth(),getHeight()); lm.paint(g,0,0);if(over==1)
{//c1.getHeight(),0);g.drawString("1937年8月14日,空军第4大队少尉飞行员刘思",c1.getWidth()-24,40,0);
g.drawString("仅21岁",c1.getWidth()-24,80,0);inputno=1;
}g.setColor(255,0,0);g.fillRect(2,2,60,5);//
g.setColor(255,255,255);g.fillRect(2,2,bosslife,5);//
if((bossover==1)&&(c1.isVisible()))
{g.drawString("此处加览桥空战真实历史战果",c1.getWidth()-24,40,0);g.drawString("此处加览桥空战真实历史战果",c1.getWidth()-24,60,0);g.drawString("仅21岁",c1.getWidth()-24,80,0);}
if(playerno==4){g.drawImage(img("/pic/playerbiaozhi.png"),145,4,0);g.drawImage(img("/pic/playerbiaozhi.png"),170,4,0);g.drawImage(img("/pic/playerbiaozhi.png"),195,4,0);g.drawImage(img("/pic/playerbiaozhi.png"),220,4,0);}if(playerno==3){
g.drawImage(img("/pic/playerbiaozhi.png"),170,4,0);
g.drawImage(img("/pic/playerbiaozhi.png"),195,4,0); g.drawImage(img("/pic/playerbiaozhi.png"),220,4,0);}if(playerno==2){ g.drawImage(img("/pic/playerbiaozhi.png"),195,4,0);
g.drawImage(img("/pic/playerbiaozhi.png"),220,4,0);
}if(playerno==1){g.drawImage(img("/pic/playerbiaozhi.png"),220,4,0);}
if(s1==1){ g.setColor(255,255,255);
g.fillRect(170,22,65,5);g.setColor(255,0,0);
g.fillRect(170,22,s2,5);g.drawString("无敌",124,18,0);s2=s2-1;if(s2==0)
{pzbz=0;s1=2;}}
flushGraphics();}
publicvoidinput(){if(inputno==0)
{intkeystate=getKeyStates();
if((keystate&UP_PRESSED)!=0){
moveUp();}
if((keystate&DOWN_PRESSED)!=0){
moveDown();}if((keystate&LEFT_PRESSED)!=0){moveLeft();}
if((keystate&LEFT_PRESSED)==0){
c1.setFrame(0);}if((keystate&RIGHT_PRESSED)!=0){moveRight();}
if((keystate&FIRE_PRESSED)!=0){
for(inti=0;i<=6;i=i+3){
if(huokebullet[i].no==1){
for(intz=i;zplanepo)
{
c1.setPosition(c1.getX(),planepo-c1.getHeight());}}privatevoidmoveUp(){c1.move(0,-4);
if(c1.getY()
privatevoidmoveRight(){
c1.setFrame(2);
c1.move(3,0);
if(c1.getX()>(getWidth()-c1.getWidth()))
{ c1.setPosition((getWidth()-c1.getWidth())c1.getY());
} }
privatevoidmoveLeft(){
c1.move(-3,0);
c1.setFrame(1);
if(c1.getX()<=0)
{
c1.setPosition(0,c1.getY());
}
}
publicvoidstart()
{
Threadt=newThread(this);
t.start();
}
publicvoidcommandAction(Commandc,Displayabled)
{
if(c.getLabel()=="暂停")
{conti=false;
removeCommand(c);
addCommand(newCommand("继续",Command.OK,1));
}
if(c.getLabel()=="继续")
{conti=true;
start();//
removeCommand(c);
addCommand(newCommand("暂停",Command.OK,2));
}
if(c.getLabel()=="返回")
{conti=false;
midlet.menuscreensecond();
}
}
}
附录二操作说明
在电脑中使用模拟器的步骤如下:
1使用WTK的新建项目功能建立一个新项目,要求与Eclipse工作区下的项目名称MIDlet类名相同。
2新建项目后,将Eclipse工作区下的.java文件拷入src文件夹,将.class文件拷入class文件夹(需要新建),将pic文件夹拷入res文件夹,点击生成,如一切正常。
3选择项目-包-生成包。
4生成的jar和jad文件存储在lzhhdm/bin目录下。
5运行MotorolaSDKv4.2forJ2ME,使用MOTOA760手机模拟器进行测试。点击Lanuc按纽,即可以进行游戏了。
电脑键盘的方向键上、下、左、右可以控制玩家飞机的运动,回车可以发射子弹。
可以将鼠标移动到相应的按纽处单击,以测试相应的按纽。
附录三英文文献及其译文
What'sNewintheJ2MEWirelessToolkit2.2
byJonathanKnudsen
June2004
Theaward-winningJ2MEWirelessToolkithasbecomethedefactostandardtoolkitfordevelopingapplicationsforJava2,MicroEdition(J2ME).Sinceitsdebutin2000,thetoolkithasevolvedtokeeppacewiththerapidlychangingfaceofmobileJavatechnology.Don'tbemisledbythesmallchangeinversionnumberfrom2.1.ThenewtoolkitsupportsnewoptionalAPIsspecifiedthroughtheJavaCommunityProcess(JCP)infourvitalareas:3Dgraphics,multimediamessaging,Bluetoothnetworking,anddatamanagement.InthisarticleI'lldescribethesenewAPIsandshowyouhowthey'reimplementedinthetoolkit.
BeforeIdo,takeamomenttoadmiretheupdatedDefaultColorPhoneemulatorskin.Sinceversion2.1,thisskinhasgottenalargerscreen(320x240,orQVGA)andfarmorecolors(4096insteadof256).
Mobile3DGraphics
JSR184,theMobile3DGraphicsAPIforJ2ME(M3G),providesthree-dimensionalgraphicsfunctionalityinacompactpackagethat'sappropriatefordevicesthatsupportthemostwidelyadoptedJ2MEsoftwarestack,theConnected,LimitedDeviceConfiguration(CLDC)andtheMobileInformationDeviceProfile(MIDP).TheAPIprovidestwoAPIsfordisplaying3Dcontent.TheimmediatemodeAPImakesitpossibleforapplicationstocreateandmanipulate3Delementsdirectly.OntopofthislayerisascenegraphAPI,alsocalledretainedmode,thatmakesitpossibletoloadanddisplayentire3Dscenesyou'vedesignedaheadoftime.ApplicationsmayusewhicheverAPIismostappropriate,oracombinationofretainedmodeandimmediatemode.TheJSR184specificationalsodefinesafileformatforscenegraphs,.m3g.
Thetoolkit'semulatorfullysupportsJSR184andyou'llfindseveralMIDletsthatshowofftheAPI'scapabilitiesintheDemo3Dproject.
Life3Ddemonstratestheuseofimmediatemode:
PogoRooisaninteractivedemonstrationthatfeaturesabouncingkangaroo:
Finally,retainedmodeshowshowtoloadandrenderascenegraphfile:
MultimediaMessaging
TheJ2MEWirelessToolkithaslongsupportedJSR120,version1.1oftheWirelessMessagingAPI(WMA);thenewreleasesupportsWMA2.0(JSR205),whichexpandsWMA'scapabilitiestoincludeMultimediaMessaging.
Inthetoolkit,messagingtakesplaceinasimulatedenvironment.Ifyouruntheemulatormultipletimes,applicationsontheemulatorscancommunicatewitheachother,andyoucanusethetoolkit'shandyWMAConsoleutilitytoexchangemessageswiththeapplicationsinthesameenvironment.Messagesmayconformtoanyofthreestandardprotocols:ShortMessageService(SMS),CellBroadcastService(CBS),or-newinversion2.2ofthetoolkit-MultimediaMessagingService(MMS).
YoucanaddressMMSmessagesandaddanycollectionoffilestothemessage.
Furthermore,thenetworkmonitornowdisplaysMMSmessagesthataresentorreceivedbytheemulator.
BluetoothandOBEX
TheJ2MEWirelessToolkitemulatorsupportsJSR82,theJavaAPIsforBluetooth,whichincludestwoindependentAPIs:
TheBluetoothAPIprovidesaninterfacetoBluetoothwireless
networking,includingdevicediscoveryanddataexchange.
TheOBEXAPIallowsapplicationstousetheObjectExchange(OBEX)
protocoloverBluetoothorothercommunicationchannels.
ThetoolkitallowsyoutodevelopandtestapplicationsthatuseBluetoothtechnologyevenifyoudon'thaveanyactualBluetoothhardware.ThetoolkitsimulatesaBluetoothenvironment,inwhichyoucanrunmultipleemulatorinstancesthatcandiscovereachotherandexchangedatausingtheBluetoothAPI.
Anexampleapplication,BluetoothDemo,showshowtotransferimagesfromoneemulatortoanother.
TheJ2MEWirelessToolkitimplementsOBEXtransferoversimulatedBluetoothandinfraredconnections.Thesimulatedinfraredconnection
followstheIrDAstandarddefinedbytheInfraredDataAssociation.Thetoolkitsimulatesinfraredtransfersbetweenmultiplerunningemulators.
YoucanconfiguretheBluetoothandOBEXenvironmentusingtheBluetooth/OBEXtabinthetoolkitpreferences.Thiscontrolssuch
parametersashowlongtheemulatorattemptstodiscoverotherdevicesinthesimulatedBluetoothenvironmentandthemaximumpacketsize.Seethetoolkit'sUser'sGuideformoredetails.
LocalFilesandPersonalInformation
TheJ2MEWirelessToolkitsupportsJSR75,thePDAOptionalPackagesfor
theJ2MEPlatform,whichalsoincludestwoindependentAPIs:
TheFileConnectionAPIgivesMIDletsaccesstoalocalfilesystemonthedevice.
ThePersonalInformationManagement(PIM)optionalpackageincludesAPIsformanipulatingcontactlists,calendars,andto-dolists.
ArealdevicemayhavealocalfilesystemwhichcanbeaccessedusingtheFileConnectionAPI.IntheJ2MEWirelessToolkitemulator,asimulatedfilesystemismaintainedasadirectoryonyourharddisk.
ThefilesyourapplicationcanaccessusingFileConnectionarestoredinsubdirectoriesof\appdb\\filesystem.,whereistheinstallationdirectoryoftheJ2MEWirelessToolkitandisthenameoftheemulatorskin.Forexample,theDefaultColorPhoneemulatorskincomeswitharootdirectoryinstalledcalledroot1,whichcontainsafilecalledReadme.Thefile'sfullpathis\appdb\DefaultColorPhone\filesystem\root1\Readme.
YoucanmanagetherootdirectoriesthatareavailablebychoosingMIDlet>Externaleventsfromtheemulatorwindow'smenu.You'llseeasmallutilitywindowforaddingandremovingroots.Theseactionswillalsogenerateeventsforaregisteredlistenerobject.
Inarealdevice,personalinformationmightbestoredinaproprietary
formatinmemory.Theemulatorusesadirectoryonyourharddiskto
containthisinformation,accessibleusingthePIMAPI.Allinformationisstoredin\appdb\pim.Listsarestoredinsubdirectoriesofthecontacts,events,andtododirectories.Forexample,acontactlistcalledContactsiscontainedin\appdb\pim\contacts\Contacts.
Insidethelistdirectory,itemsarestoredinstandardformatsspecifiedbytheInternetMailConsortium.ContactsarestoredinvCardformat,whilecalendarandto-doitemsarebothstoredinvCalendarformat.
Summary
TheJ2MEWirelessToolkit2.2ismuchmorethananincrementalupdateofanexcellenttool.Itincludessupportforfourexcitingnew
specificationsthattogetherdefinesixnewAPIs.AstheworldofwirelessJavatechnologyrapidlyevolves,theJ2MEWirelessToolkitkeepspaceandcontainsallthetoolsyouneedfor
AbouttheAuthor:JonathanKnudsen[e-mail][homepage]istheauthorofseveralbooks,includingWirelessJava(secondedition),TheUnofficialGuidetoLEGOMINDSTORMSRobots,LearningJava(secondedition),andJava2DGraphics.JonathanhaswrittenextensivelyaboutJavaandLegorobots,includingarticlesforJavaWorld,EXE,NZZFolio,andtheO'ReillyNetwork.JonathanholdsadegreeinmechanicalengineeringfromPrincetonUniversity.
译文
J2MEWirelessToolkit2.2新改进
作者:JonathanKnudsen
2004年6月
屡获殊荣的J2MEWirelessToolkit已经成为J2ME开发应用程序的事实标准工具包。自从2000年初次亮相以来,该工具包一直在发展以赶上移动Java技术外观上快速改变的步伐。不要被从2.1版本以来的小改变所误导。新的工具包在四个重要的领域支持 JavaCommunityProcess(JCP) 所指定的新的可选API:3D图形、多媒体通信、蓝牙连网(Bluetoothnetworking)和数据管理。本文将描述这些新的API并且向您展示如何在工具包中实现他们。
在这之前,让我们赞美一下更新后的DefaultColorPhone模拟器皮肤,自从2.1版本以来,该皮肤已有了一个更大的屏幕(320x240,或QVGA)和更多的颜色(4096色而不是256色)。
移动3D图形
JSR184,即Mobile3D图形APIforJ2ME(M3G)在一个集成软件包中提供了三维图形功能,适用于支持最为广泛采用的J2ME软件栈、有限连接设备配置(CLDC)和移动信息设备描述(MIDP)的设备。API为显示3D内容提供了两种API。立即模式API使应用程序能够直接创建和操纵3D元素。这一层之上是一个场景图API,也称为保留模式,能够提早加载并显示已设计的整个3D场景。应用程序可以采用最适合的API,或保留模式与立即模式的组合。JSR184规范还为场景图定义了一种文件格式-.m3g。
该工具包的模拟器全面支持JSR184,并且有几个MIDlet展示了API在Demo3D项目中的功能。Life3D演示了立即模式的使用。PogoRoo是一个的交互的演示,特点是显示一只跳跃的袋鼠:
多媒体通信
J2MEWirelessToolkit长期支持JSR120、WirelessMessagingAPI(WMA)的1.1版本;新版本支持WMA2.0(JSR205),其把WMA的功能扩展到包括多媒体通信。
在工具包中,通信发生于模拟的环境中。如果多次运行模拟器,模拟器上的应用程序能够相互通信,并且可以使用工具包方便的WMAConsole实用程序在同一环境中与应用程序交换消息。通信可以遵照以下三种标准协议之一:短消息服务(ShortMessageService,SMS)、蜂窝广播服务(CellBroadcastService,CBS)或工具包2.2版本中的新协议-多媒体通信服务(MMS)。
您可以标记MMS消息,并向消息添加任何文件集合。
而且,现在网络监视器能够显
上一篇:JAVA打飞机游戏设计(论文和程序)
下一篇:试题库管理系统毕业论文