📄 foe.java
字号:
if(hero.hero_property[9]==0){//此时没有雇佣兵时则出现
hero.hero_property[11] = foe_property[14];//奖励给刀剑兵或是弓箭兵
hero.hero_property[9] = 1;
hero.hero_property[22] = 1;
}
ini_array();
}
}
/**
*剧情NPC
*若要碰撞则出现购买画面
*/
public void check_npc_hit(Hero hero){
if(collidesWith(hero, false) && foe_property[14]==0){
foe_property[14] = 1;//表示玩家已经与NPC接触
StarFrame = System.currentTimeMillis();
}
if(foe_property[14]==1){
if(System.currentTimeMillis() - StarFrame > 2000){
foe_property[10] = 1;//表示此时可以显示购买画面
foe_property[14] = 0;
StarFrame = System.currentTimeMillis();
}
}
}
/**
*汉民与玩家接触后生成奖励物
*此时只有当汉民出现在更新
*汉民向下离开
*/
void check_hanmin_hit(Hero hero){
if(this.collidesWith(hero, false) && !is_over){
is_over = true;
heroaward.setImage(award_image, award_image.getWidth(), award_image.getHeight());
heroaward.set_display();
heroaward.set_point(getX(),getY());
heroaward.set_award_sort(foe_property[14]);
System.out.println("汉民离开,奖励品为:"+foe_property[14]);
int[] hanmin_array = {1,2};
setFrameSequence(hanmin_array);
foe_property[4] = 0;//X方向的速度
foe_property[5] = 2;//Y方向的速度
}
}
//-----------------------------------------------------------------静物和障碍物------------
/**
*检测与弓箭的碰撞.
*bowsort false表示为敌人弓箭.true表示玩家的弓箭
*返回True表示已经射中.弓箭消失
*/
boolean check_rock_hit_bow(Image image,int image_x,int image_y,Hero hero,boolean bowsort){
boolean hit_image = false;
if((foe_property[9] <= 8 || foe_property[9] == 11) && bowsort && this.foe_property[2]>0){//foe_property[9] == 7 ||
if(collidesWith(image,image_x, image_y, false)){//检测箭支与石块的碰撞
foe_property[2] -= hero.hero_property[3];
hit_image = true;
}
}
return hit_image;
}
/**
*检测与玩家的碰撞
*/
public void check_rock_hit_hero(Hero hero,int yview){
int tem_hero_x = hero.get_hero_x();
int tem_hero_y = hero.get_hero_y();
if(collidesWith(hero, false)){//检测玩家与石块的碰撞
//System.out.println("玩家与石块碰撞");
if(foe_property[9] == 9){//是流沙则伤害玩家
//这里面要加上,只有在一定的时间内才伤害玩家吧?
hero.hero_property[0]-=1;
}else{// if(hero.hero_property[25] == 0)其它类型则阻止玩家前进
if((tem_hero_y + hero.hero_image_h)>(yview+FlyGenCavans.Screen_H)){//当前面有障碍物,且玩家已经在底边
if(tem_hero_x > FlyGenCavans.Screen_W/2){
hero.setPosition((tem_hero_x-getWidth()/2),tem_hero_y);
}else
hero.setPosition((tem_hero_x+this.getWidth()/2), tem_hero_y);
}else{//其它
if(tem_hero_y > (getY()-hero.hero_image_h+10) && tem_hero_y < (getY()+getHeight()-5)){//左右 tem_hero_x > getX() && (tem_hero_x+hero.hero_image_w) <getX()
if(tem_hero_x >this.getX()){
hero.setPosition(getX() + getWidth(), tem_hero_y);
}else{
hero.setPosition(getX()-hero.hero_image_w, tem_hero_y);
}
}else{
if((tem_hero_y +hero.hero_image_h-5) <=getY()){
hero.setPosition(tem_hero_x, (getY()-hero.hero_image_h));
}else{
hero.setPosition(tem_hero_x, getY()+getHeight());
}
}
}
}
//hero.hero_property[25] = 1;
} //else{
//hero.hero_property[25] = 0;
// }
if(hero.hero_property[9]==1 && hero.hero_property[22]==0){//当有跟随者时
int tem_servant_x = hero.hero_servant.getX();
int tem_servant_y = hero.hero_servant.getY();
if(collidesWith(hero.hero_servant,false)){//跟随者与障碍相碰
if((tem_servant_x + hero.hero_servant.getWidth()) > (yview+FlyGenCavans.Screen_H)){//当前面有障碍物,且跟随者已经在底边
if(tem_servant_x > FlyGenCavans.Screen_W/2){
hero.hero_servant.setPosition((tem_servant_x-this.getWidth()),tem_servant_y);
}else
hero.hero_servant.setPosition((tem_servant_x+this.getWidth()), tem_servant_y);
}else{//其它
if(tem_servant_y > (getY()-hero.hero_servant.getHeight()+10) && tem_servant_y < (getY()+getHeight()-5)){//左右 tem_hero_x > getX() && (tem_hero_x+hero.hero_image_w) <getX()
if(tem_servant_x >this.getX()){
hero.hero_servant.setPosition(getX() + getWidth(), tem_servant_y);
}else{
hero.hero_servant.setPosition(getX()-hero.hero_servant.getWidth(), tem_servant_y);
}
}else{
if((tem_servant_y +hero.hero_servant.getHeight()-5) <=getY()){
hero.hero_servant.setPosition(tem_servant_x, (getY()-hero.hero_servant.getHeight()));
}else{
hero.hero_servant.setPosition(tem_servant_x, getY()+getHeight());
}
}
}
}
}
}
/**
*检测精灵与障碍物的碰撞
*/
public void check_rock_hit_foe(Foe foe){
if(collidesWith(foe, false) && foe_property[13] == 0){//检测敌人与石块的碰撞
//System.out.println("敌人与石块碰撞");
if(foe.foe_property[11] ==1){//向上运动
foe.set_foe_speeds(2);//set_foe_speeds(2);
}else if(foe.foe_property[11] == 2){//若此时为向下运动
foe.set_foe_speeds(1);
}else if(foe.foe_property[11] == 3){//若此时为向左运动
foe.set_foe_speeds(4);
}else
foe.set_foe_speeds(3);
this.foe_property[13] = 1;
} else{
foe_property[13] = 0;
}
}
/**
*给出相应的奖励
*根据具体的属性来进行设置
*/
public void hero_prizes(){
if(foe_property[9] == 7 || foe_property[9] == 8 || foe_property[9] == 11){
if(foe_property[2] <= 0 && !is_over){//生命值为0时进入
is_over = true;
if(foe_property[9]==7){//石块精灵
heroaward.setImage(award_image, award_image.getWidth(), award_image.getHeight());
heroaward.set_display();
heroaward.set_award_sort(foe_property[14]);
heroaward.set_point(getX(), getY());
}
//这里是不是要加上不同精灵的死亡帧
if(foe_property[9]==11)//帐篷精灵
setFrameSequence(sprite_die);
else{
ini_array();
}
}
}
}
//-----------------------------------------------------------------------------------------
public class HeroAward extends Sprite{//奖励类
int award_sort;//奖励类别
public HeroAward(Image image,int imagewidth,int imageheight){
super(image, imagewidth, imageheight);
//award_sort = sort;
this.setVisible(false);
}
/**
*检测玩家是否与奖励品碰撞
*/
boolean check_hit(Hero hero){
if(collidesWith(hero, false)){
setVisible(false);
return true;
}
return false;
}
/**
*设置奖励精灵的位置
*/
void set_point(int x,int y){
this.setPosition(x, y);
}
/**
*若玩家吃掉奖励品,设置玩家相应的奖励
*@pragram 1表示奖励金钱.2表示奖励穿心箭.3表示奖励多重箭.4表示奖励超威箭.
* 5表示奖励超距箭.6表示奖励速射箭.7表示奖励召唤玩家的马匹.8表示奖励补血
*9表示跟随者奖励
*/
void set_award_sort(Hero hero){
if(check_hit(hero)){
switch(award_sort){
case 1:
hero.hero_property[26] = 1;
hero.award_money_num = Math.abs(random.nextInt()%41)+10;
System.out.println("奖励玩家金钱数为:"+hero.award_money_num);
break;
case 2:
if(hero.hero_property[12]==0)//此属性没有设置,则设置.设置之后则不能设置
hero.hero_property[12] = 1;
break;
case 3:
if(hero.hero_property[12]==0)
hero.hero_property[12] = 2;
break;
case 4:
if(hero.hero_property[13]==0)
hero.hero_property[13]=1;
break;
case 5:
if(hero.hero_property[14]==0)
hero.hero_property[14]=1;
break;
case 6:
if(hero.hero_property[15]==0)
hero.hero_property[15] = 1;
break;
case 7:
if(hero.hero_property[16]==0)
hero.hero_property[16]=1;
break;
case 8:
hero.hero_property[17] = 1;
break;
case 9://跟随者1弓箭
if(hero.hero_property[9]!=1){
hero.hero_property[9]=1;
hero.hero_property[11]=1;//弓箭兵
hero.hero_property[22]=1;//标志玩家跟随者还没有生成
}
break;
case 10://跟随者2刀剑
if(hero.hero_property[9]!=1){
hero.hero_property[9]=1;
hero.hero_property[11]=2;//刀剑兵
hero.hero_property[22]=1;//标志玩家跟随者还没有生成
}
break;
}
hero.hero_property[6]+=50;
hero.is_change = true;//设置玩家显示变身动画
}
}
void update(Hero hero,int yview){
//updatemove();
if(getY() > yview+FlyGenCavans.Screen_H){
setVisible(false);
}
set_award_sort(hero);
}
public void updatemove(int x,int y){
move(x, y);
}
void set_display(){
setVisible(true);
}
void set_award_sort(int sort){
award_sort = sort;
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -