?? foe.java
字號:
/*
* Foe.java
*
* Created on 2006年4月18日, 下午4:29
*
* 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.*;
import javax.microedition.lcdui.game.*;
import javax.microedition.lcdui.Image;
import java.util.*;
import java.util.Random;
import java.io.*;
/**
*
* @author Administrator
* property
*/
public class Foe extends Sprite{
/**
*產生隨機移動的數字
*/
protected Random random;//改變移動方向的隨機變量
protected Random random1;//具體要改變的是哪個方向的移動
private static final int FOE_PROPERTY = 15;//精靈通用屬性數
public int[] foe_property = new int[FOE_PROPERTY];//具體說明參照文檔
private int foe_aggress_area;//精靈攻擊范圍
private int foe_aggress_face;//精靈攻擊面
private int foe_live_num;//精靈生命值
private int foe_speed;//精靈移動速度
private int foe_power;//精靈殺傷力
private int foe_arrow_speed;//精靈弓箭的移動速度
private int foe_direction;//精靈面向(即攻擊的方向)
private int foe_sort;//精靈類型具體參見文檔
private int foe_move_direction;//精靈的移動方向
private int foe_move_sort;//精靈的移動方式
//private Image foe_old;//暫存敵人的圖片
/**
*精靈幀順序
*/
private int[] Up_FrameSequences = {7,6,8,6};
private int[] Foe_Up_Stop = {6};
private int[] Left_FrameSequences ={4,3,5,3};
private int[] Foe_Left_Stop ={3};
private int[] Right_FrameSequences ={5,3,4,3};
private int[] Foe_Right_Stop = {3};
private int[] Down_FrameSequences = {1,0,2,0};
private int[] Foe_Down_Stop = {0};
private int[][] Foe_Fire = {//開火幀動畫
{4,4,4},{4,4,4},{7,7,7},{7,7,7}
};
/**
*刀劍兵的幀順列
*/
private int[] Knife_Up = {13,17,14,17};
private int[] Knife_Down = {1,0,3,0};
private int[] Knife_Left = {7,6,8,6};
private int[] Knife_Right = {7,6,8,6};
//刀劍兵的攻擊面向1向上2向下,3向左,4向右,5,向左上,6向右上,7向左下,8向右下
private int[] Knife_Fire ={
15,16,15,//底
4,5,4,
11,12,11,//左下
11,12,11,//右下
0,1,0,//上
0,1,0,
9,10,9,//中
9,10,9
};
/**
*駑步兵的幀序列
*/
private int[] Nu_infantry_Up = {8,11,9,11};
private int[] Nu_infantry_Down = {1,0,2,0};
private int[] Nu_infantry_Left = {5,4,6,4};
private int[] Nu_infantry_Right = {5,4,6,4};
private int[] Nu_infantry_Die = {12,12,12};
private int[] Nu_infantry_fire ={//有四個攻擊方向上,下,左下,右下
10,10,10,
3,3,3,
7,7,7,
7,7,7
};
/**
*弓騎兵的幀序列
*/
private int[] Gongqibing_Up ={1,0,2,0};
private int[] Gongqibing_Left ={4,5};
private int[] GongqibingFire = {//有三個攻擊方.下,左下,右下
3,3,3,
6,6,6,
6,6,6
};
private int[][] Foe_All_FrameSequence = {
{//面向上
3,2,1,
3,2,1,
3,2,1,
3,2,1,
},
{//面向下
1,2,3,
1,2,3,
1,2,3,
1,2,3
},
{//面向左下
5,6,5,
5,6,5,
5,6,5,
6,5,5
},
{//面向右下
6,5,6,
6,5,6,
6,5,6,
6,5,6
}
};
//Boss調轉馬頭幀動畫
private int[] boss_change_direction = {0,0,0};
//精靈死亡
private int[] sprite_die = {1,1,1};
//標識Boss是否已經完成調轉動畫
private boolean is_change_over;
private int old_face_direction;
private boolean is_move = false;//標志精靈是否還在移動
private int sprite_fire;//精靈進行攻擊的變量
private long StartTime;//計時標量
private long StarFrame;//幀速度
public boolean is_over;//標記精靈是否已經死亡
private int tem_randoms;//是否改變當前的速度和方向
//-----------------------------------------玩家獎勵類------------
public HeroAward heroaward;
public Image award_image;
//---------------------------------------------------------------
//public boolean Is_over;
//private Hero hero;
/** Creates a new instance of Foe
*@parameter foesort:精靈的類型.aggress_area:精靈的攻擊范圍.live_num:精靈的生命值.speed:精靈移動的速度
*power:攻擊力.arrow_speed:精靈箭支速度.direction:精靈的面向.aggress_face:攻擊面.move_direction:精靈的移動方向
*foe_move 精靈的移動方式;
*
*/
public Foe(Image image,int imagewidth,int imageheight,int foesort,int aggress_area,int live_num,int speed,int power,int arrow_speed,int direction,int aggress_face,int move_direction,int foe_move) {
super(image,imagewidth,imageheight);
heroaward = new HeroAward(image, imagewidth, imageheight);
defineReferencePixel(imagewidth/2, imageheight/2);
ini_array();
foe_aggress_area = aggress_area;
foe_live_num = live_num;
foe_speed = speed;
foe_power = power;
foe_arrow_speed = arrow_speed;
foe_direction = direction;
foe_sort = foesort;
foe_aggress_face = aggress_face;
foe_move_direction = move_direction;
this.foe_move_sort = foe_move;
this.random = new Random();
this.random1 = new Random();
//hero = hero;
//ini_property();//初始化精靈的基本屬性
is_change_over = false;
}
public void ini_array(){
for(int i=0;i<FOE_PROPERTY;i++){
foe_property[i] = 0;
}
setVisible(false);
}
/**
*測試
*/
public void display_property(){
for(int i = 0;i<FOE_PROPERTY;i++){
System.out.println("foe_property["+i+"]=="+foe_property);
}
System.out.println();
}
/**
*初始化屬性
*/
public void ini_property(){
foe_property[0] = foe_aggress_area;
foe_property[1] = foe_aggress_face;
//foe_property[3] = 1;
foe_property[2] = foe_live_num;
foe_property[6] = foe_power;
foe_property[7] = foe_arrow_speed;
foe_property[8] = foe_direction;
foe_property[9] = foe_sort;
foe_property[11] = foe_move_direction;
foe_property[12] = foe_move_sort;
StartTime = System.currentTimeMillis();//在這里開始計時
StarFrame = System.currentTimeMillis();
is_over = false;
this.setVisible(true);
}
/**
*初始化開始計時的時間
*/
public void set_starttime(long againtime){
StartTime = againtime;
}
/**
*精靈的移動函數
*/
public void foe_move(){
this.move(foe_property[4], foe_property[5]);
}
/**
*設置精靈的起始坐標
*/
public void set_foe_point(int currentx,int currenty){
setPosition(currentx, currenty);
}
/**
*設置精靈的移動速度
*/
public void set_foe_speed(){
if(foe_property[3] == 1){//精靈能夠移動時進入
switch(foe_property[11]){
case 1://上
change_direction(1);
foe_property[4] = 0;
foe_property[5] = (-1) * foe_speed;
break;
case 2://下
change_direction(2);
foe_property[4] = 0;
foe_property[5] = foe_speed;
// System.out.println("當前方向為向下");
//在這里設置精靈發射攻擊時間的速度為0?????
break;
case 3://左
change_direction(3);
foe_property[4] = (-1) * foe_speed;
foe_property[5] = 0;
break;
case 4://右
change_direction(4);
foe_property[4] = foe_speed;
foe_property[5] = 0;
break;
}
}
}
public void set_foe_speeds(int direction){
if(foe_property[3] == 1){//精靈能夠移動時進入
switch(direction){
case 1://上
change_direction(1);
foe_property[4] = 0;
foe_property[5] = (-1) * foe_speed;
break;
case 2://下
change_direction(2);
foe_property[4] = 0;
foe_property[5] = foe_speed;
//System.out.println("當前方向為向下");
//在這里設置精靈發射攻擊時間的速度為0?????
break;
case 3://左
change_direction(3);
foe_property[4] = (-1) * foe_speed;
foe_property[5] = 0;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -