?? hero.java
字號:
/*
* 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 + -