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

📄 hero.java

📁 这是一款竖版射击手机游戏
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
/*
 * Hero.java
 *
 * Created on 2006年4月15日, 下午5:16
 *
 * 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.Graphics;
import javax.microedition.lcdui.game.*;
import javax.microedition.lcdui.Image;
import java.util.Random;
import java.io.*;

/**
 *
 * @author Administrator
 */
public class Hero extends Sprite {
    
    /** Creates a new instance of Hero */
    public int hero_live_num = 2;
    public static int hero_image_w;
    public static int hero_image_h;
    public static boolean Is_Continue = false;//标志是否要继续玩家的生命
    private long Start_Continue_Time;//要继续游戏必需在规定的时间内按下规定的按键方能进行,这里计下开始的时间
    
    public int hero_ph;//玩家的生命值
    private int hero_arrow_sort;//弓箭的类型
    private int hero_arrow_gunshot;//弓箭的射程
    private int hero_arrow_power;//弓箭的杀伤力
    private int hero_rocket_num;//玩家火箭的最大使用次数
    private int hero_arrow_speed;//弓箭的速度
    private int hero_speed;//玩家的移动速度
    private int hero_rocket_power;//玩家火箭的杀伤力
    private int hero_rocket_radius;//玩家火箭的杀伤半径
    public int hero_currently_live_num;//玩家当前剩余生命数
    public int hero_servant_space;//玩家跟随者移动范围即是玩家的杀伤半径
    
    private int horse_live_num=5;
    
    private long frame_start;
    /**
     *玩家的属性397203247
     */
    private static final int PROPERTY = 29;
    public int[] hero_property = new int[PROPERTY];//各各参数参照文档说明
    
    /**
     *玩家的帧序列
     */
    //private int[] Up_FrameSequence = {9,10,11};
    private int[] Up_Stop = new int[1];//{22};
    //private int[] Left_FrameSequence = {0,1,2};
    private int[] Left_Stop = new int[1];//{6};
    //private int[] Right_FrameSequence = {3,4,5};
    private int[] Right_Stop = new int[1];// {6};
    //private int[] Down_FrameSequence = {6,7,8};
    private int[] Down_Stop = new int[1];// {22};
    private int[][] Fire_FrameSequence = {//左中右
        {13,14,15},{16,17,18},{19,20,21}
    };
    private int[] Hero_FrameSequence;//
    private int[] Hero_Fire_FrameSequence;//攻击帧
    private int[] hero_walk_framesequence = {//上下左右3788
        17,22,18,22,
                17,22,18,22,
                6,7,8,9,10,11,
                6,7,8,9,10,11,
    };
    private int[] hero_fire_framesequence = {//变身前的攻击帧左中右;;;;上下左右
        //攻击方向为左
        //23,24,24,
        //23,24,24,
        34,35,35,
                34,35,35,
                13,14,14,
                36,37,37,//要翻转
                //攻击方向为中
                22,21,21,
                22,21,21,
                4,5,5,
                4,5,5,//要翻转
                //攻击方向为右,全部翻转
                //23,24,24,
                //23,24,24,
                34,35,35,
                34,35,35,
                36,37,37,//这个不用翻转
                13,14,14
    };
    private int[] hero_change_walk_framesequence ={//上下左右
        2,1,3,1,
                2,1,3,1,
                26,27,28,29,30,31,
                26,27,28,29,30,31
    };
    private int[] hero_change_fire_framesequence = {//变身后的攻击帧左中右;;;;上下左右
        //攻击方向为左
        19,20,20,
                19,20,20,
                32,33,33,
                12,25,25,//要翻转
                //攻击方向为中
                0,1,1,
                0,1,1,
                15,16,16,
                15,16,16,//要翻转
                //攻击方向为右,全部翻转
                19,20,20,
                19,20,20,
                12,25,25,//不用翻转
                32,33,33
    };
    private int[] Change_FrameSequence = {//变身帧
        38,38,38
    };
    //public int hero_property[24] = 1;//移动的方向
    public boolean hero_fire;//标志玩家是否要开火
    private int hero_fire_num;//一定时间后开火
    private boolean is_move = true;
    public boolean is_change =false;//标志玩家是否要变身
    private boolean is_play_frame=false;//标志是否要播放玩家变身帧
    //-----------------------------------------------------跟随者信息-------
    public HeroServant hero_servant;
    public Image servant_image;
    public static Foe servant_attack_target;//让跟随者去行攻击的对象
    //----------------------------------------------------------------------
    
    public int award_money_num;//要奖励玩家的金钱数
    
    
    public Hero(Image image,int width,int height,int hero_live,int hero_ph,int arrow_sort,int arrow_gunshot,int arrow_power,int rocket_num,int arrow_speed,int speed,int rocket_power,int rocket_radius) {
        super(image, width, height);
        defineReferencePixel(width/2, height/2);
        ini_array();
        this.hero_image_h = height;
        this.hero_image_w = width;
        this.hero_live_num = hero_live;//玩家的生命次数
        this.hero_ph = hero_ph;
        this.hero_arrow_sort = arrow_sort;
        this.hero_arrow_gunshot = arrow_gunshot;
        this.hero_arrow_power = arrow_power;
        this.hero_rocket_num = rocket_num;
        this.hero_arrow_speed = arrow_speed;
        this.hero_speed = speed;
        this.hero_rocket_power = rocket_power;//火箭的杀伤力
        this.hero_rocket_radius = rocket_radius;//火箭的杀伤半径
        hero_fire = false;
        this.hero_currently_live_num = this.hero_live_num;
    }
    
    public void ini_array(){
        for(int i = 0;i<PROPERTY;i++){
            hero_property[i] = 0;
        }
    }
    /**
     *得到玩家的坐标
     */
    public int get_hero_x(){
        return getX();
    }
    public int get_hero_y(){
        return getY();
    }
    /**
     *初始化玩家的必要属性
     */
    public void ini_import_property(){
        hero_property[0] = this.hero_ph;
        hero_property[1] = this.hero_arrow_sort;
        hero_property[2] = this.hero_arrow_gunshot;
        hero_property[3] = this.hero_arrow_power;
        hero_property[4] = this.hero_rocket_num;
        hero_property[8] = 2;//初始化为箭向上射击
        hero_property[9] = 0;
        hero_property[10] = 0;
        hero_property[11] = 0;
        hero_property[12] = 0;
        hero_property[13] = 0;
        hero_property[14] = 0;
        hero_property[15] = 0;
        hero_property[16] = 0;
        hero_property[17] = 0;
        hero_property[18] = this.hero_arrow_speed;
        hero_property[19] = 0;
        hero_property[20] = this.hero_speed;
        hero_property[21] = 5;
        hero_property[22] = 0;
        hero_property[23] = 0;
        hero_property[24] = 1;
        hero_property[25] = 0;
        hero_property[26] = 0;
        hero_property[27] = hero_rocket_power;
        hero_property[28] = hero_rocket_radius;
        
        Hero_FrameSequence = hero_walk_framesequence;
        Hero_Fire_FrameSequence = hero_fire_framesequence;
        Up_Stop[0] =hero_walk_framesequence[3];
        Left_Stop[0] =hero_walk_framesequence[8];
        Right_Stop[0] = hero_walk_framesequence[8];
        Down_Stop[0] = hero_walk_framesequence[3];
        
        hero_servant_space = 50;
        //this.hero_currently_live_num = this.hero_live_num;
    }
    
    /**
     *设置玩家的坐标
     */
    public void set_hero_point(int current_x,int current_y){
        setPosition(current_x, current_y);
    }
    /**
     *@parameter yview 当前屏幕的顶点坐标.foe 进入攻击范围的敌人.g 画笔
     */
    public void update(int yview,Graphics g){
        if(hero_property[12]==1){//穿心箭
            hero_property[1] = 1;//更改当前弓箭的类型
            hero_property[12] = -1;//改变当前属性的值
        }
        if(hero_property[12]==2){//多重箭
            hero_property[1] = 2;//更改当前弓箭的类型
            hero_property[12] = -1;
        }
        if(hero_property[13] == 1){//让玩家的箭的威力加倍
            hero_property[3] *=2;
            hero_property[13] = -1;
        }
        if(hero_property[14] == 1 && hero_property[1] !=1){//让玩家的射程加倍
            hero_property[14] = -1;
            hero_property[2] *=2;
        }
        if(hero_property[15] == 1){//让玩家弓箭速度加倍
            hero_property[15] = -1;
            hero_property[18] *=2;
        }
        if(hero_property[16] == 1){//召唤马匹
            hero_property[19] = horse_live_num;
            hero_property[20] *=2;
            this.Hero_FrameSequence = this.hero_change_walk_framesequence;
            this.Hero_Fire_FrameSequence = this.hero_change_fire_framesequence;
            Up_Stop[0] =this.Hero_FrameSequence[3];
            Left_Stop[0] =this.Hero_FrameSequence[8];
            Right_Stop[0] = this.Hero_FrameSequence[8];
            Down_Stop[0] = this.Hero_FrameSequence[3];
            hero_property[16] = -1;
        }
        if(hero_property[19]<=0 && hero_property[16]==-1){
            hero_property[16] =0;
            hero_property[20] /=2;
            this.Hero_FrameSequence = this.hero_walk_framesequence;
            this.Hero_Fire_FrameSequence = this.hero_fire_framesequence;
            Up_Stop[0] =this.Hero_FrameSequence[3];
            Left_Stop[0] =this.Hero_FrameSequence[8];
            Right_Stop[0] = this.Hero_FrameSequence[8];
            Down_Stop[0] = this.Hero_FrameSequence[3];
        }
        if(hero_property[26] == 1){
            hero_property[26] = 0;
            hero_property[5] +=award_money_num;//增加玩家的金钱数
        }
        if(hero_property[17] == 1){//加生命值
            hero_property[0] = hero_ph;
            hero_property[17] = 0;
        }
        if(hero_property[22] == 1 && hero_property[9] == 1){//生成玩家跟随者
            hero_property[22] = 0;
            //hero_property[24] = 50;//跟随者可移动的范围
            if(hero_property[11] == 1){//弓箭跟随者
                hero_servant = new HeroServant(FlyGenCavans.gongjian_servant, 22,22);
                hero_servant.setPosition(getX() - getWidth(), getY());
                //hero_servant.ini_import_property();
            }else if(hero_property[11] == 2){//刀箭跟随者
                hero_servant = new HeroServant(FlyGenCavans.daojian_servant, 20, 29);
                hero_servant.setPosition(getX() + getWidth()/2, getY()-getHeight());
            }
                hero_servant.ini_import_property();
        }
        if(hero_property[9]==1){
            hero_servant.update_servant(yview, this);
            hero_servant.paint(g);
        }
        if(is_change){//播放变身动画
            //System.out.println("开始变身!!!!!!!");
            this.setFrameSequence(Change_FrameSequence);
            frame_start = System.currentTimeMillis();
            this.is_play_frame = true;
            this.hero_property[24] = 1;
            this.is_change = false;
        }
        if(is_play_frame){
            if(System.currentTimeMillis()-frame_start > 50){
                nextFrame();
                frame_start = System.currentTimeMillis();
            }
            if(this.getFrame()==2){
                is_play_frame =false;
            }
        }
        set_hero_fire();
    }
    /**
     *向上运动
     */
    public void up_movie(int yview){
        if(!is_play_frame){
            if(hero_property[24] !=1 || !is_move){
                change_direction(1);
            } else
                move(0,-hero_property[20]);
            if(getY() < yview + 45){
                setPosition(getX(), yview+45);
            }
            nextFrame();
        }
    }
    /**
     *向下运动
     */
    public void down_movie(int yview){
        if(!is_play_frame){
            if(hero_property[24] != 2 || !is_move){
                change_direction(2);
            } else
                this.move(0, hero_property[20]);
            if(getY() > yview + 158){
                setPosition(getX(),(yview + 158));
            }
            nextFrame();
        }
    }
    /**
     *向左运动
     */
    public void left_movie(){
        if(!is_play_frame){
            if(hero_property[24] != 3 || !is_move){

⌨️ 快捷键说明

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