选择显示字体大小

j2me小游戏-fly

package fly;

import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
import java.util.*;

/**
* <p>title: </p>
* <p>description: </p>
* <p>copyright: copyright (c) 2004</p>
* <p>company: </p>
* @author not attributable
* @version 1.0
*/

public class flymidlet extends midlet &#123;
navigate ng;
public flymidlet() &#123;
ng=navigate.getinstance(this);
&#125;
protected void startapp() &#123;
system.out.println("startapp");
ng.display.setcurrent(ng.mc);
printinfo();
&#125;
protected void pauseapp() &#123;
system.out.println("pauseapp");
&#125;
protected void destroyapp(boolean parm1) &#123;
system.out.println("destroyapp");
navigate.mc.stop();
mygamecanvas.cleanjob();
navigate.cleanjob();
&#125;

private void printinfo()&#123;
system.out.println("flymidlet printinfo() start:");
system.out.println("flymidlet printinfo() end:");
&#125;

&#125;

2、bullets.java

package fly;
import javax.microedition.lcdui.game.*;
import javax.microedition.lcdui.*;
import java.util.random;
/**
* <p>title: </p>
* <p>description: </p>
* <p>copyright: copyright (c) 2004</p>
* <p>company: </p>
* @author not attributable
* @version 1.0
*/

public class bullets extends gameobject &#123;
private int[][] bullets;
private int bulletstotal;
private random rnd;
public static final int bullet_type_left=0;
public static final int bullet_type_right=1;
public static final int bullet_type_top=2;
public static final int bullet_type_bottom=3;
private int width,height;

public bullets(image img,int picwidth,int picheight,int bulletstotal,int width,int height) &#123;
super(img,picwidth,picheight);
this.bulletstotal=bulletstotal;
bullets=new int[bulletstotal][6];
rnd=new random();
this.width=width;
this.height=height;
&#125;

public void initbullets()&#123;
for (int i = 0; i < bullets.length; i++) &#123;
initbullet(i);
&#125;
&#125;

private void initbullet(int i) &#123;
bullets[i][0] = (rnd.nextint() & 0x7fffffff) % 4; //type
bullets[i][5] = 1; //alive
switch (bullets[i][0]) &#123;
case bullet_type_left:
bullets[i][1] = -5;
bullets[i][2] = (rnd.nextint() & 0x7fffffff) % height;
bullets[i][3] = (rnd.nextint() & 0x7fffffff) % 3 + 1; //vx
bullets[i][4] = (rnd.nextint()) % 3; //vy
break;
case bullet_type_right:
bullets[i][1] = width + 5;
bullets[i][2] = (rnd.nextint() & 0x7fffffff) % height;
bullets[i][3] = ( (rnd.nextint() & 0x7fffffff) % 3 + 1) * -1; //vx
bullets[i][4] = (rnd.nextint()) % 3; //vy
break;
case bullet_type_top:
bullets[i][1] = (rnd.nextint() & 0x7fffffff) % width;
bullets[i][2] = -5;
bullets[i][3] = (rnd.nextint()) % 3; //vx
bullets[i][4] = (rnd.nextint() & 0x7fffffff) % 3 + 1; //vy
break;
case bullet_type_bottom:
bullets[i][1] = (rnd.nextint() & 0x7fffffff) % width;
bullets[i][2] = height + 5;
bullets[i][3] = (rnd.nextint()) % 3; //vx
bullets[i][4] = ( (rnd.nextint() & 0x7fffffff) % 3 + 1) * -1; //vy
break;
&#125;
&#125;

public void updata(int i)&#123;
bullets[i][1]+=bullets[i][3];
bullets[i][2]+=bullets[i][4];
if(bullets[i][1]<-5 bullets[i][1]>width+5)&#123;
bullets[i][3]*=-1;
&#125;
if(bullets[i][2]<-5 bullets[i][2]>height+5)&#123;
bullets[i][4]*=-1;
&#125;
&#125;

private void paint(graphics g,int i)&#123;
updataspritepos(i);
sprite.paint(g);
&#125;

public void paint(graphics g) &#123;
for (int i = 0; i < bullets.length; i++) &#123;
if(bullets[i][5]==0)&#123;
continue;
&#125;
sprite.setposition(bullets[i][1],bullets[i][2]);
sprite.paint(g);
&#125;
&#125;

public void refreshbullets(sprite planesprite, boolean needcollision)&#123;
for (int i = 0; i < bullets.length; i++) &#123;
if(bullets[i][5]==0)&#123;
continue;
&#125;
if(needcollision)&#123;
//system.out.println("needcollision ");
if (iscollision(planesprite, i, 10)) &#123;
//system.out.println("collision ");
navigate.mc.gameover = true;
navigate.mc.explosion.sprite.setposition(bullets[i][1] - 16,
bullets[i][2] - 16);
bullets[i][5] = 0;
continue;
&#125;
&#125;
updata(i);
&#125;
&#125;

private boolean iscollision(sprite sprite,int i,int range)&#123;
//updataspritepos(i);
//return sprite.collideswith(this.sprite,true);
boolean result=false;
int planexcenter=sprite.getx()+12;
int planeycenter=sprite.gety()+12;
int bulletxcenter=bullets[i][1]+3;
int bulletycenter=bullets[i][2]+3;
if(math.abs(planexcenter-bulletxcenter) < range)&#123;
if (math.abs(planeycenter - bulletycenter )< range) &#123;
result = true;
&#125;
&#125;
return result;
&#125;

private void updataspritepos(int i)&#123;
sprite.setposition(bullets[i][1],bullets[i][2]);
&#125;

/* no use now
public void resetdeadbullet()&#123;
for (int i = 0; i < bullets.length; i++) &#123;
if(bullets[i][5]==0)&#123;//dead bullet
initbullet(i);
&#125;
&#125;
&#125;
*/

public void killbullets(sprite planesprite,int range)&#123;
for (int i = 0; i < bullets.length; i++) &#123;
if(bullets[i][5]!=0)&#123;//alive bullets
if(iscollision(planesprite, i, range))&#123;
bullets[i][5]=0;
initbullet(i);
&#125;
&#125;
&#125;
&#125;
&#125;

[1] [2] [3] [4]  下一页


 


关键字 本文所属关键字

相关 与本文相关文章

分类 所有文章关键字导航

源码编程相关

Java   Asp   PHP   .Net   XML   C/C++   CGI   VB   Jsp   J2ee   J2se   J2me   EJB   Servlet   Tomcat   Resin   Struts   Weblogic   Eclipse   ANT   GUI   JMS   Web servise   IDEA   Webphere   Hibernate   Spring   Jboss   Applet   Swing   Socket   Javamail   Perl   Ajax   P2P   安全   模式   框架   测试   开源   游戏

SQL数据库相关

My-SQL   Ms-SQL   Access   DB2   Oracle   Sybase   SQLserver   索引   存储过程   加密   数据库   分页   视图  

手机无线相关

3G   Wap   CDMA   GRPS   GSM   IVR   彩信   短信   无线   增值业务

网页设计制作相关

HTML   CSS   网页配色   网页特效   Javascript   VBscript   Dreamweaver   Frontpage   JS   Web   网站设计

网站建设推广相关

建站经验   网站优化   网站排名   推广   Alexa

操作系统/服务器相关

Windows XP   Windows 2000   Windows 2003   Windows Me   Windows 9.x   Linux   UNIX   注册表   操作系统   服务器   应用服务器

图形图像多媒体相关

Photoshop   Fireworks   Flash   Coreldraw   Illustrator   Freehand   Photoimpact   多媒体   图形图像

标准 网站致力的规范

Valid CSS!

无不良内容,无不良广告,无恶意代码

Valid XHTML 1.0 Transitional

creativecommons