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 {
navigate ng;
public flymidlet() {
ng=navigate.getinstance(this);
}
protected void startapp() {
system.out.println("startapp");
ng.display.setcurrent(ng.mc);
printinfo();
}
protected void pauseapp() {
system.out.println("pauseapp");
}
protected void destroyapp(boolean parm1) {
system.out.println("destroyapp");
navigate.mc.stop();
mygamecanvas.cleanjob();
navigate.cleanjob();
}
private void printinfo(){
system.out.println("flymidlet printinfo() start:");
system.out.println("flymidlet printinfo() end:");
}
}
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 {
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) {
super(img,picwidth,picheight);
this.bulletstotal=bulletstotal;
bullets=new int[bulletstotal][6];
rnd=new random();
this.width=width;
this.height=height;
}
public void initbullets(){
for (int i = 0; i < bullets.length; i++) {
initbullet(i);
}
}
private void initbullet(int i) {
bullets[i][0] = (rnd.nextint() & 0x7fffffff) % 4; //type
bullets[i][5] = 1; //alive
switch (bullets[i][0]) {
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;
}
}
public void updata(int i){
bullets[i][1]+=bullets[i][3];
bullets[i][2]+=bullets[i][4];
if(bullets[i][1]<-5 bullets[i][1]>width+5){
bullets[i][3]*=-1;
}
if(bullets[i][2]<-5 bullets[i][2]>height+5){
bullets[i][4]*=-1;
}
}
private void paint(graphics g,int i){
updataspritepos(i);
sprite.paint(g);
}
public void paint(graphics g) {
for (int i = 0; i < bullets.length; i++) {
if(bullets[i][5]==0){
continue;
}
sprite.setposition(bullets[i][1],bullets[i][2]);
sprite.paint(g);
}
}
public void refreshbullets(sprite planesprite, boolean needcollision){
for (int i = 0; i < bullets.length; i++) {
if(bullets[i][5]==0){
continue;
}
if(needcollision){
//system.out.println("needcollision ");
if (iscollision(planesprite, i, 10)) {
//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;
}
}
updata(i);
}
}
private boolean iscollision(sprite sprite,int i,int range){
//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){
if (math.abs(planeycenter - bulletycenter )< range) {
result = true;
}
}
return result;
}
private void updataspritepos(int i){
sprite.setposition(bullets[i][1],bullets[i][2]);
}
/* no use now
public void resetdeadbullet(){
for (int i = 0; i < bullets.length; i++) {
if(bullets[i][5]==0){//dead bullet
initbullet(i);
}
}
}
*/
public void killbullets(sprite planesprite,int range){
for (int i = 0; i < bullets.length; i++) {
if(bullets[i][5]!=0){//alive bullets
if(iscollision(planesprite, i, range)){
bullets[i][5]=0;
initbullet(i);
}
}
}
}
}
[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 安全 模式 框架 测试 开源 游戏
Windows XP Windows 2000 Windows 2003 Windows Me Windows 9.x Linux UNIX 注册表 操作系统 服务器 应用服务器