⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bullet.java

📁 这是一款竖版射击手机游戏
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/*
 * Bullet.java
 *
 * Created on 2006年4月17日, 下午5:10
 *
 * To change this template, choose Tools | Options and locate the template under
 * the Source Creation and Management node. Right-click the template and choose
 * Open. You can then make changes to the template in the Source Editor.
 */
import javax.microedition.lcdui.Image;
import javax.microedition.lcdui.*;
import java.io.*;
/**
 *
 * @author Administrator
 */
public class Bullet {
    
    /** Creates a new instance of Bullet */
    /**
     *[i][0]子弹X坐标
     *[i][1]子弹Y坐标
     *[i][2]子弹Y方向速度
     *[i][3]子弹X方向的速度
     *[i][4]子弹的存活状态property
     *[i][5]子弹的初始X坐标
     *[i][6]子弹的初始Y坐标
     *[i][7]标志子弹是否已经改变状态
     *[i][8]子弹的方向
     *[i][9]图片的宽
     *[i][10]图片的高
     *[i][11]标识为哪种类型的精灵发出的箭支
     *[i][12]精灵的射程.
     *[i][13]子弹在图片中的X坐标
     *[i][14]子弹在图片中的Y坐标
     *[i][15]子弹的攻击力
     */
    public static final int PLAY_BULLET_NUM = 12;
    public static final int PLAY_PROPERTY = 16;
    private int[][] Play_Rocket = new int[3][PLAY_PROPERTY];//玩家的火箭支数
    //public int gunshot = 100;
    public int[][] play_bullet = new int[PLAY_BULLET_NUM][PLAY_PROPERTY];//玩家的子弹//是否可以通用?
    private Hero hero_play;
    private Image bullet_image = null;
    private int[] play_explosion = {//x:y:w:h
        13,14,5,5,
                42,11,12,12,
                70,8,21,18,
                96,0,32,32
    };
    private int[] explosion = {//帧序列:播放时间
        0,50,
                1,50,
                2,50,
                3,50
    };
    public static boolean is_explosion;//标志玩家发射的火箭是否要到爆炸的时间
    private long explosion_start;
    int explosion_i = 0;
    protected int x,y;//当前爆炸的地点
    protected int w, h; //当前爆炸图像的宽,高
    protected int x1,y1;//当前爆炸图象在大图片的位置
    
    
    
    
    //敌人的子弹的各个属性------------------------------------------------
    protected static final int FOE_BULLET_NUM = 30;//精灵子弹的个数
    private int[][] foe_bullet = new int[FOE_BULLET_NUM][PLAY_PROPERTY];
    private Foe foe_sprite;//敌人类
    //----------------------------------------------------------------------------------------------
    
    public Bullet(Hero hreo) {
        hero_play = hreo;
        ini_play_bullet();
        ini_foe_bullet();
        ini_rocket_bullet();
        is_explosion = false;
    }
    
    public void ini_play_bullet(){
        for(int i = 0;i<PLAY_BULLET_NUM;i++){
            for(int j=0;j<PLAY_PROPERTY;j++){
                play_bullet[i][j] = 0;
            }
        }
    }
    public void ini_rocket_bullet(){
        for(int i = 0;i<3;i++){
            for(int j=0;j<PLAY_PROPERTY;j++)
                Play_Rocket[i][j] = 0;
        }
    }
    /**
     *初始化精灵子弹
     */
    public void ini_foe_bullet(){
        for(int i = 0;i<FOE_BULLET_NUM;i++){
            for(int j = 0;j<PLAY_PROPERTY;j++){
                foe_bullet[i][j] = 0;
            }
        }
    }
    
    /**
     *设置玩家子弹的原始坐标
     *@parameter play_sort:发箭的类型1表示玩家的弓箭.2表示跟随者的类型
     */
    public void set_bullet_point(int x ,int y,int play_sort){
        boolean tem1=false;
        int tem_num = 2;
        for(int i=0;i<PLAY_BULLET_NUM;i++){
            if(play_sort == 2){//hero_play.hero_property[9]!=0 && hero_play.hero_property[11]==1
                if(play_bullet[i][4] != 1 && tem_num > 0){
                    play_bullet[i][0] = x;
                    play_bullet[i][1] = y;
                    play_bullet[i][5] = x;
                    play_bullet[i][6] = y;
                    play_bullet[i][11] = play_sort;
                    play_bullet[i][4] = 1;
                    tem_num = tem_num - 2;
                }
            }else{//设置玩家子弹开始
                if(hero_play.hero_property[1] ==2){//双发子弹
                    if(play_bullet[i][4] != 1 && tem_num > 0){
                        if(tem_num == 1){
                            play_bullet[i][0] = x;
                            play_bullet[i][1] = y;
                            play_bullet[i][5] = x;
                            play_bullet[i][6] = y;
                        } else{
                            play_bullet[i][0] = x + 5;
                            play_bullet[i][1] = y;
                            play_bullet[i][5] = x + 5;
                            play_bullet[i][6] = y;
                        }
                        play_bullet[i][11] = 1;//1表示玩家发射的弓箭,2表示跟随者发射的弓箭
                        play_bullet[i][4] = 1;
                        tem_num--;
                    }
                } else{//单发
                    if(play_bullet[i][4] != 1 && tem_num > 0){
                        play_bullet[i][0] = x;
                        play_bullet[i][1] = y;
                        play_bullet[i][5] = x;
                        play_bullet[i][6] = y;
                        play_bullet[i][11] = 1;
                        play_bullet[i][4] = 1;
                        tem_num = tem_num - 2;
                    }
                }
            }//设置玩家子弹结束
            //play_bullet[i][11] = play_sort;
        }
    }
    /**
     *设置玩家发射火箭时的原始坐标
     */
    public void set_rocket_bullet_point(int x,int y){
        boolean tem_rocket = false;
        for(int i = 0;i<3;i++){
            if(Play_Rocket[i][4] !=1 && !tem_rocket){
                Play_Rocket[i][0] = x;
                Play_Rocket[i][1] = y;
                Play_Rocket[i][5] = x;
                Play_Rocket[i][6] = y;
                Play_Rocket[i][4] = 1;
                tem_rocket = true;
            }
        }
    }
    /**
     *设置玩家的速度
     */
    public void set_bullet_speed(){
        for(int i = 0;i<this.PLAY_BULLET_NUM;i++){
            if(play_bullet[i][4] == 1 && play_bullet[i][7] !=1){
                switch(hero_play.hero_property[8]){
                    case 1://向左发
                        play_bullet[i][3] = (-1)*hero_play.hero_property[18] * 7071/10000;//X方向速度
                        play_bullet[i][2] = (-1)*hero_play.hero_property[18] * 7071/10000;//Y方向速度
                        play_bullet[i][8] = 1;
                        break;
                    case 2://向上发
                        play_bullet[i][3] = 0;
                        play_bullet[i][2] = (-1)*hero_play.hero_property[18];
                        play_bullet[i][8] = 2;
                        break;
                    case 3://向右发
                        play_bullet[i][3] = hero_play.hero_property[18] * 7071/10000;
                        play_bullet[i][2] = (-1) * hero_play.hero_property[18] * 7071/10000;
                        play_bullet[i][8] = 3;
                        break;
                }
                if(play_bullet[i][11]==1){//玩家的子弹
                    if(hero_play.hero_property[1]==1){//穿心箭
                        play_bullet[i][13] = arrow_attack_area[(play_bullet[i][8]+2)*4];
                        play_bullet[i][14] = arrow_attack_area[(play_bullet[i][8]+2)*4+1];
                        play_bullet[i][9] = arrow_attack_area[(play_bullet[i][8]+2)*4+2];
                        play_bullet[i][10] = arrow_attack_area[(play_bullet[i][8]+2)*4+3];
                    }else{//普通箭
                        play_bullet[i][13] = arrow_attack_area[(play_bullet[i][8]-1)*4];
                        play_bullet[i][14] = arrow_attack_area[(play_bullet[i][8]-1)*4+1];
                        play_bullet[i][9] = arrow_attack_area[(play_bullet[i][8]-1)*4+2];
                        play_bullet[i][10] = arrow_attack_area[(play_bullet[i][8]-1)*4+3];
                    }
                }else{//跟随者箭
                    play_bullet[i][13] = arrow_attack_area[(play_bullet[i][8]-1)*4];
                    play_bullet[i][14] = arrow_attack_area[(play_bullet[i][8]-1)*4+1];
                    play_bullet[i][9] = arrow_attack_area[(play_bullet[i][8]-1)*4+2];
                    play_bullet[i][10] = arrow_attack_area[(play_bullet[i][8]-1)*4+3];
                }
                play_bullet[i][7] = 1;
            }
        }
    }
    /**
     *设置玩家发射火箭的速度
     */
    public void set_rocket_bullet_speed(){
        for(int i = 0;i<3;i++){
            if(Play_Rocket[i][4] ==1 && Play_Rocket[i][7]!=1){
                switch(hero_play.hero_property[8]){
                    case 1://向左发
                        Play_Rocket[i][3] = (-1)*hero_play.hero_property[21] * 7071/10000;//X方向速度
                        Play_Rocket[i][2] = (-1)*hero_play.hero_property[21] * 7071/10000;//Y方向速度
                        Play_Rocket[i][8] = 1;
                        break;
                    case 2://向上发
                        Play_Rocket[i][3] = 0;
                        Play_Rocket[i][2] = (-1)*hero_play.hero_property[21];
                        Play_Rocket[i][8] = 2;
                        break;
                    case 3://向右发
                        Play_Rocket[i][3] = hero_play.hero_property[21] * 7071/10000;
                        Play_Rocket[i][2] = (-1) * hero_play.hero_property[21] * 7071/10000;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -