僵尸.docx
《僵尸.docx》由会员分享,可在线阅读,更多相关《僵尸.docx(74页珍藏版)》请在冰豆网上搜索。
僵尸
packageFreeIMUST.PvZ_Online.PvZ;
importandroid.graphics.Bitmap;
importandroid.graphics.Canvas;
importandroid.graphics.Paint;
publicabstractclassPlant
{
protectedPvZ_OnlineActivityactivity_=null;
protectedDoublePlayerModeAViewdoublePlayerModeAView_=null;
//植物图片底边中点坐标
protectedintx_=0;
protectedinty_=0;
//贴图的坐标
protectedintxDraw_=0;
protectedintyDraw_=0;
//植物的生命
protectedintlife_=10;
//播放植物动画的帧序列
protectedintframeIndex_=0;
//植物动画的帧数
protectedBitmap[]frameImage_=null;
//植物动画的帧总数
protectedfinalintframeAmount_;
//用于在画布上绘图
protectedPaintpaint_=newPaint();
publicinttype_=0;
protectedintstatus_=0;
publicPlant(intx,inty,intframeAmount)
{
this.x_=x;
this.y_=y;
this.xDraw_=x-40;
this.yDraw_=y-40;
this.frameAmount_=frameAmount;
}
protectedvoidloadImage()
{
//TODO子类必须重写此函数,用于加载植物类及动画图片
}
publicvoiddraw(Canvascanvas)
{
canvas.drawBitmap(frameImage_[frameIndex_],xDraw_,yDraw_,paint_);
frameIndex_=(frameIndex_+1)%frameAmount_;
}
publicvoidattack()
{
}
//-------------------------------------------------------------------------
//SettersandGetters
//-------------------------------------------------------------------------
publicintgetX()
{
returnthis.x_;
}
publicintgetY()
{
returnthis.y_;
}
publicintgetLeftX()
{
returnthis.x_-this.frameImage_[0].getWidth()/2;
}
publicintgetRightX()
{
returnthis.x_+this.frameImage_[0].getWidth()/2;
}
publicintgetLife()
{
returnthis.life_;
}
publicvoidsetLife(intlife)
{
this.life_=life;
}
publicbooleanisDead()
{
returnthis.life_<=0;
}
publicvoidcheckHit()
{
}
publicintgettype()
{
returntype_;
}
}
packageFreeIMUST.PvZ_Online.PvZ;
importFreeIMUST.PvZ_Online.PvZ.PvZ_OnlineActivity.ZombieImageFactory;
importandroid.graphics.Bitmap;
importandroid.graphics.Canvas;
importandroid.graphics.Paint;
publicabstractclassZombie//僵尸
{
publicstaticfinalintState_Normal=0;
publicstaticfinalintState_Attack=1;
publicstaticfinalintState_Normal_Dead=2;
publicstaticfinalintState_Attack_Dead=3;
publicstaticfinalintState_Dead=4;
PvZ_OnlineActivityactivity_=null;
publicintstate_=State_Normal;
publicinttype_=0;
//图片底边中点坐标
protectedintx_=0;
protectedinty_=0;
//贴图的坐标
protectedintxDraw_=0;
protectedintyDraw_=0;
//僵尸的生命
protectedintlife_=10;
protectedintspeed_=-2;
protectedPaintpaint_=newPaint();
protectedbooleanisRemoveable_=false;
protectedintframeNormalAmount_;
protectedintframeAttackAmount_;
protectedBitmap[]frameNormalImage_;
protectedBitmap[]frameAttackImage_;
publicZombie(intx,inty,DoublePlayerModeAViewactivity)
{
this.x_=x;
this.y_=y;
this.xDraw_=x-90;
this.yDraw_=y-80;
this.activity_=activity.activity_;
}
protectedvoidloadImage()
{
//TODO子类必须重写此函数
}
publicvoiddraw(Canvascanvas)
{
}
publicvoidmove()
{
}
publicvoidupdateState()
{
if(this.life_<=0)
{
switch(this.state_)
{
caseState_Normal:
state_=State_Normal_Dead;
break;
caseState_Normal_Dead:
break;
caseState_Attack:
state_=State_Attack_Dead;
break;
caseState_Attack_Dead:
break;
caseState_Dead:
break;
}
}
}
publicvoidcheckHit()
{
}
//-------------------------------------------------------------------------
//SettersandGetters
//-------------------------------------------------------------------------
publicintgetX()
{
returnthis.x_;
}
publicintgetY()
{
returnthis.y_;
}
publicintgetLeftX()
{
returnthis.x_;
}
publicintgetRightX()
{
returnthis.x_;
}
publicintgetLife()
{
returnthis.life_;
}
publicvoidsetLife(intlife)
{
this.life_=life;
}
publicvoidsetState(intstate)
{
this.state_=state;
}
publicintgetState()
{
returnthis.state_;
}
publicbooleanisRemoveable()
{
returnthis.isRemoveable_;
}
publicvoidchange()
{
frameNormalAmount_=22;
frameAttackAmount_=21;
frameNormalImage_=activity_.zombieImageFactory_.getImage(ZombieImageFactory.Zombie_PuTongJiangShi);
frameAttackImage_=activity_.zombieImageFactory_.getImage(ZombieImageFactory.Zombie_PuTongJiangShi_Attack);
}
}
packageFreeIMUST.PvZ_Online.PvZ;
importFreeIMUST.PvZ_Online.PvZ.PvZ_OnlineActivity.PlantImageFactory;
importFreeIMUST.PvZ_Online.PvZ.PvZ_OnlineActivity.ZombieImageFactory;
importandroid.graphics.Bitmap;
importandroid.graphics.Canvas;
publicclassPuTongJiangShiextendsZombie
{
DoublePlayerModeAViewdoublePlayerModeAView_=null;
//行走状态
intframeNormalIndex_=0;
//Bitmap[]frameNormalImage_=null;
//finalintframeNormalAmount_=22;
//行走状态死亡
intframeNormalDeadIndex_=0;
Bitmap[]frameNormalDeadImage_=null;
finalintframeNormalDeadAmount_=10;
//攻击状态
intframeAttackIndex_=0;
//Bitmap[]frameAttackImage_=null;
//finalintframeAttackAmount_=21;
//攻击状态死亡
intframeAttackDeadIndex_=0;
Bitmap[]frameAttackDeadImage_=null;
finalintframeAttackDeadAmount_=11;
//死亡倒地
intframeDeadIndex_=0;
Bitmap[]frameDeadImage_=null;
finalintframeDeadAmount_=10;
//死亡掉落的头部
intframeHeadIndex_=0;
Bitmap[]frameHeadImage_=null;
finalintframeHeadAmount_=12;
intattackCount_=0;
publicPuTongJiangShi(intx,inty,DoublePlayerModeAViewactivity)
{
super(x,y,activity);
this.life_=10;
this.speed_=-1;
doublePlayerModeAView_=activity;
frameNormalAmount_=22;
frameAttackAmount_=21;
loadImage();
}
protectedvoidloadImage()
{
frameNormalImage_=activity_.zombieImageFactory_.getImage(ZombieImageFactory.Zombie_PuTongJiangShi);
frameNormalDeadImage_=activity_.zombieImageFactory_.getImage(ZombieImageFactory.Zombie_PuTongJiangShi_Losthead);
frameAttackImage_=activity_.zombieImageFactory_.getImage(ZombieImageFactory.Zombie_PuTongJiangShi_Attack);
frameAttackDeadImage_=activity_.zombieImageFactory_.getImage(ZombieImageFactory.Zombie_PuTongJiangShi_Attack_Losthead);
frameDeadImage_=activity_.zombieImageFactory_.getImage(ZombieImageFactory.Zombie_PuTongJiangShi_Die);
frameHeadImage_=activity_.zombieImageFactory_.getImage(ZombieImageFactory.Zombie_PuTongJiangShi_Head);
}
publicvoiddraw(Canvascanvas)
{
switch(state_)
{
caseState_Normal:
canvas.drawBitmap(frameNormalImage_[frameNormalIndex_],xDraw_,yDraw_,paint_);
frameNormalIndex_=(frameNormalIndex_+1)%frameNormalAmount_;
break;
caseState_Attack:
canvas.drawBitmap(frameAttackImage_[frameAttackIndex_],xDraw_,yDraw_,paint_);
frameAttackIndex_=(frameAttackIndex_+1)%frameAttackAmount_;
break;
caseState_Normal_Dead:
canvas.drawBitmap(frameNormalDeadImage_[frameNormalDeadIndex_],xDraw_,yDraw_,paint_);
++frameNormalDeadIndex_;;
canvas.drawBitmap(frameHeadImage_[frameHeadIndex_],xDraw_+45,yDraw_,paint_);
frameHeadIndex_=(frameHeadIndex_+1)%frameHeadAmount_;
if(frameNormalDeadIndex_==frameNormalDeadAmount_)
state_=State_Dead;
break;
caseState_Attack_Dead:
canvas.drawBitmap(frameAttackDeadImage_[frameAttackDeadIndex_],xDraw_,yDraw_,paint_);
++frameAttackDeadIndex_;
canvas.drawBitmap(frameHeadImage_[frameHeadIndex_],xDraw_+45,yDraw_,paint_);
frameHeadIndex_=(frameHeadIndex_+1)%frameHeadAmount_;
if(frameAttackDeadIndex_==frameAttackDeadAmount_)
state_=State_Dead;
break;
caseState_Dead:
canvas.drawBitmap(frameDeadImage_[frameDeadIndex_],xDraw_,yDraw_,paint_);
++frameDeadIndex_;
if(frameDeadIndex_==frameDeadAmount_)
this.isRemoveable_=true;
break;
}
}
publicvoidcheckHit()
{
booleanisAttack=false;
for(Plantplant:
doublePlayerModeAView_.plants_)
{
if(plant.getY()==this.getY())
{
if(plant.getX()<=this.getX())
{
if(plant.type_==PlantImageFactory.Plant_MuBei)
continue;
if(State_Dead!
=state_&&State_Normal_Dead!
=state_&&State_Attack_Dead!
=state_)
{
if(plant.getRightX()>=this.getX())
{
isAttack=true;
this.state_=State_Attack;
if(0==attackCount_)
plant.setLife(plant.getLife()-1);
attackCount_=(attackCount_+1)%10;
}
}
}
}
}
if(State_Dead!
=state_&&State_Normal_Dead!
=state_&&State_Attack_Dead!
=state_)
if(!
isAttack)
state_=State_Normal;
}
publicvoidmove()
{
switch(state_)
{
caseState_Normal:
this.x_+=speed_;
this.xDraw_+=speed_;
break;
caseState_Attack:
break;
caseState_Normal_Dead:
this.x_+=speed_;
this.xDraw_+=speed_;
break;
caseState_Attack_Dead:
break;
caseState_Dead:
break;
}
}
publicintgetLeftX()
{
returnthis.x_-frameNormalImage_[0].getWidth()/2;
}
publicintgetRightX()
{
returnthis.x_+frameNormalImage_[0].getWidth()/2;
}
}
packageFreeIMUST.PvZ_Online.PvZ;
importFreeIMUST.