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

📄 bullet.java

📁 这是一款竖版射击手机游戏
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
                            if(direction_num == 1)
                                foe_bullet[i][8]=5;
                            if(direction_num ==2)
                                foe_bullet[i][8]=2;
                            break;
                        case 3://向左下方发
                            bullet_direction = 1;
                            if(direction_num ==0)
                                foe_bullet[i][8] = 4;
                            if(direction_num == 1)
                                foe_bullet[i][8]=1;
                            if(direction_num ==2)
                                foe_bullet[i][8]=5;
                            break;
                        case 4://向右下方发
                            bullet_direction = 2;
                            if(direction_num ==0)
                                foe_bullet[i][8] = 5;
                            if(direction_num == 1)
                                foe_bullet[i][8]=2;
                            if(direction_num ==2)
                                foe_bullet[i][8]=3;
                            break;
                    }
                    foe_bullet[i][3] = foe_speed * arc_num_x[bullet_direction*3+direction_num]/10000;//X方向速度
                    foe_bullet[i][2] = foe_speed * arc_num_y[bullet_direction*3+direction_num]/10000;//Y方向速度
                    direction_num++;
                }else{//其它精灵的攻击
                    switch(foe_face_direction){//根据精灵当前的面向来确定箭支发出的方向!
                        case 3://向左下发
                            foe_bullet[i][3] = (-1) * foe_speed * 7071/10000;//X方向速度
                            foe_bullet[i][2] = foe_speed * 7071/10000;//Y方向速度
                            foe_bullet[i][8] = 1;
                            break;
                        case 1://向上发
                            foe_bullet[i][3] = 0;
                            foe_bullet[i][2] = (-1)*foe_speed;
                            foe_bullet[i][8] = 6;
                            break;
                        case 4://向右下发
                            foe_bullet[i][3] = foe_speed * 7071/10000;
                            foe_bullet[i][2] = foe_speed * 7071/10000;
                            foe_bullet[i][8] = 2;
                            break;
                        case 2://向下发
                            foe_bullet[i][3] = 0;
                            foe_bullet[i][2] = foe_speed;
                            foe_bullet[i][8] = 5;
                            break;
                    }
                }
                try{
                    foe_bullet[i][13] = arrow_attack_area[(play_bullet[i][8]+5)*4];
                    foe_bullet[i][14] = arrow_attack_area[(play_bullet[i][8]+5)*4+1];
                    foe_bullet[i][9] = arrow_attack_area[(play_bullet[i][8]+5)*4+2];
                    foe_bullet[i][10] = arrow_attack_area[(play_bullet[i][8]+5)*4+3];
                    foe_bullet[i][7] = 1;//标志此只箭已经发射出去!
                }catch(ArrayIndexOutOfBoundsException e){
                    System.out.println("play_bullet[i][8]+5====="+play_bullet[i][8]+5);
                    System.out.println(e.toString());
                    e.printStackTrace();
                }
            }
        }
    }
    /**
     *更新精灵子弹的坐标
     *@parameter yview 为当前视图的最上边Y坐标.bullet_range 为此类种类型的精灵的射程.bullet_sort 精灵的类型
     *bow_sort  子弹的类型
     */
    public void update_foe_bullet_point(int yview,int bow_sort){//,int bullet_range,int bullet_sort
        for(int i = 0 ; i<FOE_BULLET_NUM;i++){
            if(foe_bullet[i][4] == 1 && foe_bullet[i][7] == 1){
                int temX = (foe_bullet[i][0] - foe_bullet[i][5]);
                int temY = (foe_bullet[i][1] - foe_bullet[i][6]);
                //System.out.println("精灵的类型=="+foe_bullet[i][11]);
                switch(foe_bullet[i][11]){//这里可以用foe_bullet[i][11]来代替精灵的类型
                    case 1://雕骑兵
                    case 6://Boss
                        if((temX * temX + temY * temY) > (foe_bullet[i][12] * foe_bullet[i][12]) || foe_bullet[i][0] < 0 || foe_bullet[i][0] > 176 || foe_bullet[i][1] < yview || foe_bullet[i][1] > yview + 208){
                            foe_bullet[i][4] = 0;
                            foe_bullet[i][7] = 0;
                            foe_bullet[i][8] = 0;
                            foe_bullet[i][11] = 0;
                            foe_bullet[i][12] = 0;
                        }
                        break;
                    case 2://弓骑兵
                        if((temX * temX + temY * temY) > (foe_bullet[i][12] * foe_bullet[i][12]) || foe_bullet[i][0] < 0 || foe_bullet[i][0] > 176 || foe_bullet[i][1] < yview || foe_bullet[i][1] > yview + 208){
                            foe_bullet[i][4] = 0;
                            foe_bullet[i][7] = 0;
                            foe_bullet[i][8] = 0;
                            foe_bullet[i][11] = 0;
                            foe_bullet[i][12] = 0;
                        }
                        break;
                    case 3://千骑长
                    case 11://兵营
                        if((temX * temX + temY * temY) > (foe_bullet[i][12] * foe_bullet[i][12]) || foe_bullet[i][0] < 0 || foe_bullet[i][0] > 176 || foe_bullet[i][1] < yview || foe_bullet[i][1] > yview + 208){
                            foe_bullet[i][4] = 0;
                            foe_bullet[i][7] = 0;
                            foe_bullet[i][8] = 0;
                            foe_bullet[i][11] = 0;
                            foe_bullet[i][12] = 0;
                        }
                        break;
                    case 4://弩步兵
                        if((temX * temX + temY * temY) > (foe_bullet[i][12] * foe_bullet[i][12]) || foe_bullet[i][0] < 0 || foe_bullet[i][0] > 176 || foe_bullet[i][1] < yview || foe_bullet[i][1] > yview + 208){
                            foe_bullet[i][4] = 0;
                            foe_bullet[i][7] = 0;
                            foe_bullet[i][8] = 0;
                            foe_bullet[i][11] = 0;
                            foe_bullet[i][12] = 0;
                        }
                        break;
                }
                //System.out.println("foe_bullet[i][3]==="+foe_bullet[i][3]);
                if(foe_bullet[i][11] == bow_sort){
                    foe_bullet[i][0] +=foe_bullet[i][3];
                    foe_bullet[i][1] +=foe_bullet[i][2];
                }
                /*int temX = (foe_bullet[i][0] - foe_bullet[i][5]);
                int temY = (foe_bullet[i][1] - foe_bullet[i][6]);
                if((temX * temX + temY * temY) > (bullet_range * bullet_range) || foe_bullet[i][0] < 0 || foe_bullet[i][0] > 176 || foe_bullet[i][1] < yview || foe_bullet[i][1] > yview + 208){
                    foe_bullet[i][4] = 0;
                    foe_bullet[i][7] = 0;
                    foe_bullet[i][8] = 0;
                }*/
            }
        }
    }
    /**
     *画精灵的子弹
     *@parameter
     *foe_bow_sort 弓箭的类型
     */
    public void draw_foe_bullet(Graphics g, int yview,int foe_bow_sort){
        for(int i=0;i<FOE_BULLET_NUM;i++){
            if(foe_bullet[i][4] == 1 && foe_bullet[i][7]==1){
                X = arrowimgdata[(foe_bullet[i][8]+8)*4];
                Y = arrowimgdata[(foe_bullet[i][8]+8)*4+1];
                w1 = arrowimgdata[(foe_bullet[i][8]+8)*4+2];
                h1 = arrowimgdata[(foe_bullet[i][8]+8)*4+3];
                
//                if(foe_bullet[i][9] == 0 || foe_bullet[i][10] == 0){//赋值,保存图片的宽和高
//                    foe_bullet[i][9] = w1;
//                    foe_bullet[i][10] = h1;
//                }
                if(foe_bullet[i][11] == foe_bow_sort){
                    try{
                        g.setClip(foe_bullet[i][0],foe_bullet[i][1],w1,h1);//画小图片
                        g.drawImage(FlyGenCavans.Game_Arrow,foe_bullet[i][0]-X,foe_bullet[i][1]-Y,Graphics.LEFT|Graphics.TOP);//画大图片
                        g.setClip(0, 0, 176, 208);
                    }catch (Exception e) {}
                }
            }
        }
    }
    /**
     *检测敌人对玩家造成伤害
     *@parameter
     *Hero hero 被攻击的玩家
     */
    public void check_attack_hero(Hero hero){
        boolean tem_hide = false;
        for(int i=0;i<PLAY_BULLET_NUM;i++){
            if(foe_bullet[i][4] == 1 && foe_bullet[i][7]==1){
                if(MapTool.isIntersectingRect(foe_bullet[i][0]+foe_bullet[i][13], foe_bullet[i][1]+foe_bullet[i][14], foe_bullet[i][9], foe_bullet[i][10], hero.getX(), hero.getY(), hero.getWidth(), hero.getHeight())){
                    if(hero.hero_property[19]>0){
                        hero.hero_property[19]-=foe_bullet[i][15];
                    }else
                        hero.hero_property[0]-=foe_bullet[i][15];
                    tem_hide = true;
                }
                if(hero.hero_property[9]==1 && hero.hero_property[22] == 0 && MapTool.isIntersectingRect(foe_bullet[i][0]+foe_bullet[i][13], foe_bullet[i][1]+foe_bullet[i][14], foe_bullet[i][9], foe_bullet[i][10], hero.hero_servant.getX(), hero.hero_servant.getY(), hero.hero_servant.getWidth(), hero.hero_servant.getHeight())){
                    tem_hide = true;
                    hero.hero_servant.hero_servant_property[0]-=foe_bullet[i][15];
                }
                if(tem_hide){
                    foe_bullet[i][4] = 0;
                    foe_bullet[i][7] = 0;
                    foe_bullet[i][8] = 0;
                    foe_bullet[i][9] = 0;
                    foe_bullet[i][10] = 0;
                    foe_bullet[i][11] = 0;
                    foe_bullet[i][13] = 0;
                    foe_bullet[i][14] = 0;
                    foe_bullet[i][15] = 0;
                }
                
                
//                    if(hero_play.hero_property[1]!=1 || play_bullet[i][11]==2){
            }
        }
    }
    
    protected int w1, h1; //当前动作图像的宽,高
    protected int X,Y;//当前人物图象在大图片的位置
    //protected int currently_x, currently_y; //当前所处位置,y是脚底的坐标
    public static final short[] arrowimgdata ={//x,y,w,h
        0,6,15,15,//一般弓箭
                15,4,5,20,
                20,6,15,15,//穿心箭
                35,4,22,22,
                57,0,5,30,
                62,4,22,22,//火箭
                84,3,23,24,
                107,0,8,30,
                
                115,3,23,24,//敌人弓箭
                138,7,15,15,
                153,7,15,15,
                168,12,20,7,
                188,12,20,7,
                208,5,5,20,
                213,5,5,20
    };
    public static final short[] arrow_attack_area ={
        0,0,5,5,//一般弓箭的攻击范围
                0,0,5,5,
                10,0,5,5,
                0,0,7,7,//穿心箭的攻击范围
                0,0,5,7,
                15,0,7,7,
                
                0,9,6,6,//敌人弓箭的攻击范围
                9,9,6,6,
                13,0,7,7,
                0,0,7,7,
                0,14,5,6,
                0,0,5,6
    };
    //http://www.comicfans.net/
}

⌨️ 快捷键说明

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