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