📄 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 + -