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

📄 hero.java

📁 这是一款竖版射击手机游戏
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
                change_direction(3);
            } else
                move(-hero_property[20], 0);
            if(getX() < 0){
                setPosition(0, getY());
            }
            nextFrame();
        }
    }
    /**
     *向右运动
     */
    public void right_movie(){
        if(!is_play_frame){
            if(hero_property[24] != 4 || !is_move){
                change_direction(4);
            } else{
                this.setTransform(Sprite.TRANS_MIRROR);
                move(hero_property[20], 0);
            }
            if(getX() > (176 - this.getWidth()))
                setPosition((176 - getWidth()),getY());
            nextFrame();
        }
    }
    
    public void stopmove(int moveway){
        if(!is_play_frame){
            is_move = false;
            switch(moveway){
                case 0:
                    setFrameSequence(this.Up_Stop);
                    break;
                case 1 :
                    setFrameSequence(this.Down_Stop);
                    break;
                case 2:
                    setFrameSequence(this.Left_Stop);
                    break;
                case 3:
                    setFrameSequence(this.Right_Stop);
                    break;
            }
            setFrame(0);
        }
    }
    /**
     *改变方向(面向)
     */
    public void change_direction(int directions){
        int[] tem_heroframe = new int[4];
        switch(directions){
            case 1://上
                setTransform(Sprite.TRANS_NONE);
                tem_heroframe[0] = Hero_FrameSequence[0];//this.hero_walk_framesequence[0];
                tem_heroframe[1] = Hero_FrameSequence[1];//this.hero_walk_framesequence[1];
                tem_heroframe[2] = Hero_FrameSequence[2];//this.hero_walk_framesequence[2];
                tem_heroframe[3] = Hero_FrameSequence[3];//this.hero_walk_framesequence[3];
                //setFrameSequence(Up_FrameSequence);
                //hero_property[24] = 1;
                hero_property[24] = 1;
                //is_move = true;
                break;
            case 2://下
                this.setTransform(Sprite.TRANS_NONE);
                tem_heroframe[0] = Hero_FrameSequence[4];//this.hero_walk_framesequence[4];
                tem_heroframe[1] = Hero_FrameSequence[5];//this.hero_walk_framesequence[5];
                tem_heroframe[2] = Hero_FrameSequence[6];//this.hero_walk_framesequence[6];
                tem_heroframe[3] = Hero_FrameSequence[7];//this.hero_walk_framesequence[7];
                //setFrameSequence(Down_FrameSequence);
                //hero_property[24] = 2;
                hero_property[24] = 2;
                //is_move = true;
                break;
            case 3://左
                this.setTransform(Sprite.TRANS_NONE);
                tem_heroframe[0] = Hero_FrameSequence[8];//this.hero_walk_framesequence[8];
                tem_heroframe[1] = Hero_FrameSequence[9];//this.hero_walk_framesequence[9];
                tem_heroframe[2] = Hero_FrameSequence[10];//this.hero_walk_framesequence[10];
                tem_heroframe[3] = Hero_FrameSequence[11];//this.hero_walk_framesequence[11];
                //setFrameSequence(Left_FrameSequence);
                //hero_property[24] = 3;
                hero_property[24] = 3;
                ////is_move = true;
                break;
            case 4://右
                this.setTransform(Sprite.TRANS_MIRROR);
                tem_heroframe[0] = Hero_FrameSequence[12];//this.hero_walk_framesequence[12];
                tem_heroframe[1] = Hero_FrameSequence[13];//this.hero_walk_framesequence[13];
                tem_heroframe[2] = Hero_FrameSequence[14];//this.hero_walk_framesequence[14];
                tem_heroframe[3] = Hero_FrameSequence[15];//this.hero_walk_framesequence[15];
                //hero_property[24] = 4;
                hero_property[24] = 4;
                break;
        }
        is_move = true;
        setFrameSequence(tem_heroframe);
        this.setFrame(0);
    }
    /**
     *设置玩家购买的相应物品
     */
    public void set_hero_award(int award_sort){
        switch(award_sort){
            case 6://跟随者2
                if(hero_property[9]!=1){
                    hero_property[9]=1;
                    hero_property[11]=2;//刀剑兵
                    hero_property[22]=1;//标志玩家跟随者还没有生成
                }
                break;
            case 7://跟随者1
                if(hero_property[9]!=1){
                    hero_property[9]=1;
                    hero_property[11]=1;//弓箭兵
                    hero_property[22]=1;//标志玩家跟随者还没有生成
                    System.out.println("生成跟随者之弓箭雇佣兵");
                }
                break;
            case 0://穿心箭
                if(hero_property[12]==0)//此属性没有设置,则设置.设置之后则不能设置
                    hero_property[12] = 1;
                break;
            case 2://多重箭
                if(hero_property[12]==0)
                    hero_property[12] = 2;
                break;
            case 1://超威箭
                if(hero_property[13]==0)
                    hero_property[13]=1;
                break;
            case 3://超距箭
                if(hero_property[14]==0)
                    hero_property[14]=1;
                break;
            case 4://速射箭
                if(hero_property[15]==0)
                    hero_property[15] = 1;
                break;
            case 8://召唤军马
                if(hero_property[16]==0)
                    hero_property[16]=1;
                break;
            case 5://增加HP
                hero_property[17] = 1;
                break;
        }
        is_change = true;//设置玩家显示变身动画
    }
    /**
     *设置玩家火箭爆炸的时间给敌人造成的伤害
     *@parameter Foe foe敌人 rocket_xy.当前爆炸的坐标
     */
    public void set_hero_rocket_blast(Foe foe,int[] rocket_xy){
        int tem_foe_x = foe.getX() + foe.getWidth()/2;
        int tem_foe_y = foe.getY() + foe.getHeight()/2;
        tem_foe_x = rocket_xy[0]-tem_foe_x;
        tem_foe_y = rocket_xy[1]-tem_foe_y;
        if(Bullet.is_explosion){
            if((tem_foe_x*tem_foe_x + tem_foe_y * tem_foe_y)<hero_property[28]*hero_property[28]){
                //减血
                foe.foe_property[2]-=hero_property[27];
            }
        }
    }
    /**
     *设置玩家开火帧,并让玩家开火
     */
    public void set_hero_fire(){
        hero_fire_num++;
        if(hero_fire_num>40){
            hero_fire_num = 0;
            is_play_frame = true;
            hero_fire = true;
            is_move = false;
            frame_start = System.currentTimeMillis();
            int[] tem_frame = new int[3];
            switch(this.hero_property[8]){
                case 1://左
                    //System.out.println("左左左左左左左左基左左左左左左左左左基左左左左左左左左左基左左左左左左左左左基左");
                    if(hero_property[24]==4)
                        setTransform(Sprite.TRANS_MIRROR);
                    else
                        this.setTransform(Sprite.TRANS_NONE);
                    tem_frame[0] = Hero_Fire_FrameSequence[(hero_property[24]-1)*3];// this.hero_fire_framesequence[(hero_property[24]-1)*3];
                    tem_frame[1] = Hero_Fire_FrameSequence[(hero_property[24]-1)*3+1];//this.hero_fire_framesequence[(hero_property[24]-1)*3+1];
                    tem_frame[2] = Hero_Fire_FrameSequence[(hero_property[24]-1)*3+2];//this.hero_fire_framesequence[(hero_property[24]-1)*3+2];
                    //this.setFrameSequence(tem_frames);
                    break;
                case 2://中
                    //System.out.println("中中中中吕中 吕中 中吕中中吕中中中中中吕中中中吕中中中");
                    //System.out.println("移动方向hero_property[24]=="+hero_property[24]);
                    if(hero_property[24]==4)
                        this.setTransform(Sprite.TRANS_MIRROR);
                    else
                        this.setTransform(Sprite.TRANS_NONE);
                    tem_frame[0] = Hero_Fire_FrameSequence[(hero_property[24]+3)*3];//this.hero_fire_framesequence[(hero_property[24]+3)*3];
                    tem_frame[1] = Hero_Fire_FrameSequence[(hero_property[24]+3)*3+1];//this.hero_fire_framesequence[(hero_property[24]+3)*3+1];
                    tem_frame[2] = Hero_Fire_FrameSequence[(hero_property[24]+3)*3+2];//this.hero_fire_framesequence[(hero_property[24]+3)*3+2];
                    break;
                case 3://右
                    tem_frame[0] = Hero_Fire_FrameSequence[(hero_property[24]+7)*3];//this.hero_fire_framesequence[(hero_property[24]+7)*3];
                    tem_frame[1] = Hero_Fire_FrameSequence[(hero_property[24]+7)*3+1];//this.hero_fire_framesequence[(hero_property[24]+7)*3+1];
                    tem_frame[2] = Hero_Fire_FrameSequence[(hero_property[24]+7)*3+2];//this.hero_fire_framesequence[(hero_property[24]+7)*3+2];
                    if(hero_property[24]==3){
                        setTransform(Sprite.TRANS_NONE);
                    } else
                        setTransform(Sprite.TRANS_MIRROR);
                    break;
            }
            this.setFrameSequence(tem_frame);
            this.setFrame(0);
        }
    }
    /**
     *检测玩家是否已经Over
     */
    public void Check_Hero_IsOver(){
        if(hero_property[0]<=0){
            if(this.hero_currently_live_num<=0){//已经要死亡了~~~
                if(isVisible()){
                    setVisible(false);
                    Start_Continue_Time = System.currentTimeMillis();
                    hero_currently_live_num = 9;
                    FlyGenCavans.Game_Two_State = 4;
                }
                if(!isVisible()){
                    if(System.currentTimeMillis() - Start_Continue_Time > 9000){
                        FlyGenCavans.Game_Two_State = 5;
                    }else{
                        if(Is_Continue){//继续游戏
                            Is_Continue = false;
                            setVisible(true);
                            hero_currently_live_num = hero_live_num;
                            this.ini_import_property();
                            this.set_hero_point((FlyGenCavans.Screen_W-hero_image_w)/2, (FlyGenCavans.Screen_H-hero_image_h));
                        }
                    }
                }
            }else if(this.isVisible()){//剩下不只一条命
                this.hero_currently_live_num--;
                this.ini_import_property();
                this.set_hero_point((FlyGenCavans.Screen_W-hero_image_w)/2, (FlyGenCavans.Screen_H-hero_image_h));
            }
        }
    }
    
    class HeroServant extends Sprite{//跟随者类
        /**
         *玩家跟随者的属性397203247
         */
        private static final int PROPERTY = 8;
        public int[] hero_servant_property = new int[PROPERTY];//各各参数参照文档说明
        
        
        private int[] hero_servant_fire_frame = {//第一个是当前的面向,第二个是攻击的帧.暂定为3帧弓驽兵的攻击方式
            6,6,6,
                    3,3,3,
                    9,9,9
        };
        private int[] hero_knife_servant_fire_frame = {//第一个是当前的攻击方向,第二个是攻击的帧.暂定为3帧.刀剑兵的攻击数组
            3,4,3
        };
        /**
         *玩家跟随者帧的序列
         */
        private int[] knife_Up_FrameSequences = {1,3,2,3};
        private int[] knife_Up_Stop = {3};
        private int[] knife_Left_FrameSequences ={5,7,6,7};
        private int[] knife_Left_Stop ={7};
        private int[] knife_Right_FrameSequences ={9,11,10,11};
        private int[] knife_Right_Stop = {11};
        private int[] knife_Down_FrameSequences = {1,3,2,3};
        private int[] knife_Down_Stop = {3};
        
        private int[] bow_Up_FrameSequences = {1,3,2,3};
        private int[] bow_Up_Stop = {3};
        private int[] bow_Left_FrameSequences ={4,6,5,6};
        private int[] bow_Left_Stop ={6};
        private int[] bow_Right_FrameSequences ={7,9,8,9};
        private int[] bow_Right_Stop = {9};
        private int[] bow_Down_FrameSequences = {1,3,2,3};
        private int[] bow_Down_Stop = {3};
        
        private long servant_start_time;
        int servant_direction;//跟随者当前的移动方向
        private Random random_servant;//
        private Random knife_random;//暂时随机变量
        
        private int servant_fire_face;//刀剑兵的攻击面向1向上2向下,3向左,4向右,5,向左上,6向右上,7向左下,8向右下
        
        private int fire_sign;//跟随者多久开始攻击的标量
        
        //private Image servant_fire_frame;//当刀剑兵进行攻击的时,用来替换图片
        //private Image primal_servant;//最初跟随者画片
        
        private long servant_start_times;//帧的播放速度
        
        HeroServant(Image image,int imagewidth,int imageheight){
            super(image, imagewidth, imageheight);
            defineReferencePixel(imagewidth/2, imageheight/2);
            ini_array();
            hero_servant_property[4] = hero_servant_space;
            hero_servant_property[2] = 40;
            random_servant = new Random();
            knife_random = new Random();
        }
        
        void ini_array(){
            for(int i = 0;i<PROPERTY;i++){
                hero_servant_property[i] = 0;
            }
            this.setVisible(false);
        }
        //初始化重要属性
        void ini_import_property(){
            hero_servant_property[0] = 5;
            hero_servant_property[1] = 0;
            hero_servant_property[2] = 40;
            hero_servant_property[3] = 0;
            hero_servant_property[4] = 40;
            hero_servant_property[5] = 0;
            hero_servant_property[6] = 2;
            hero_servant_property[7] = 0;
            this.setVisible(true);
        }
        /**
         *更新跟随者
         */
        void update_servant(int yview,Hero hero){
            servant_fire();
            if(hero_servant_property[3] == 1){//此时跟随者不能动
                if(System.currentTimeMillis() - servant_start_times >300){//这里控制攻击帧的播放
                    servant_start_times = System.currentTimeMillis();
                    move(0,0);
                    //servant_direction = 0;
                    nextFrame();
                }
                if(getFrame() == 2){//帧动画已经播放完
                    hero_servant_property[3] = 0;

⌨️ 快捷键说明

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