?? enemytank.java
字號:
if(newBornTimer*23-1>=0){
setFrame(newBornTimer*23-1);
}}
catch(Exception e){
System.out.println("Enemythink");
}
}
} else{
changeDirection(direction);
if(direction!=BattleField.NONE){
setTankFrame();
}
}
}
////////////////////////////////////////////////////////////////////////////
//--------------------------------- REVISIONS ------------------------------
// Date Name Tracking # Description
// --------- ------------------- ------------- ----------------------
// 15JAN2008 James Shen Initial Creation
////////////////////////////////////////////////////////////////////////////
/**
* Operation be done in each tick.
*/
public void tick(){
if(immobilizedStartTime>0){
long tickTime=System.currentTimeMillis();
if(tickTime-immobilizedStartTime>immobilizedPeriod){
immobilizedStartTime=0;
}
}else{
super.tick();
}
}
////////////////////////////////////////////////////////////////////////////
//--------------------------------- REVISIONS ------------------------------
// Date Name Tracking # Description
// --------- ------------------- ------------- ----------------------
// 18JAN2008 James Shen Initial Creation
////////////////////////////////////////////////////////////////////////////
/**
* Intialize the player tank after been destoryed or first start.
*/
public void initTank(){
status=STATUS_NEW_BORN;
switch(type){
case TYPE_SIMPLE:
case TYPE_SMART:
speed=ResourceManager.TILE_WIDTH/6;
blood=1;
break;
case TYPE_FAST:
blood=1;
speed=ResourceManager.TILE_WIDTH/2;
break;
case TYPE_HEAVY:
speed=ResourceManager.TILE_WIDTH/6;
blood=4;
break;
}
}
////////////////////////////////////////////////////////////////////////////
//--------------------------------- REVISIONS ------------------------------
// Date Name Tracking # Description
// --------- ------------------- ------------- ----------------------
// 18JAN2008 James Shen Initial Creation
////////////////////////////////////////////////////////////////////////////
/**
* Set if the tank has prize.
* @param hasPrize true,has prize.
*/
public void setHasPrize(boolean hasPrize){
this.hasPrize=hasPrize;
}
////////////////////////////////////////////////////////////////////////////
//--------------------------------- REVISIONS ------------------------------
// Date Name Tracking # Description
// --------- ------------------- ------------- ----------------------
// 16JAN2008 James Shen Initial Creation
////////////////////////////////////////////////////////////////////////////
/**
* Player has collected {@see Powerup.BOMB}. Enemies should explode immediately.
*/
public static void explodeAllEmenies() {
for (int i = 1; i < POOL_SIZE; ++i) {
Tank tank = TANK_POOL[i];
if (tank.isVisible()){
((EnemyTank)tank).blood=1;
tank.explode();
}
}
immobilizedStartTime=0;
}
////////////////////////////////////////////////////////////////////////////
//--------------------------------- REVISIONS ------------------------------
// Date Name Tracking # Description
// --------- ------------------- ------------- ----------------------
// 16JAN2008 James Shen Initial Creation
////////////////////////////////////////////////////////////////////////////
/**
* Get the count of all visible enemy tanks.
* @return the count of all visible enemy tanks.
*/
public static int getVisibleEnemyTanks(){
int count=0;
for(int i=1;i<POOL_SIZE;i++){
if(TANK_POOL[i].isVisible()){
count++;
}
}
return count;
}
////////////////////////////////////////////////////////////////////////////
//--------------------------------- REVISIONS ------------------------------
// Date Name Tracking # Description
// --------- ------------------- ------------- ----------------------
// 16JAN2008 James Shen Initial Creation
////////////////////////////////////////////////////////////////////////////
/**
* Create a new enemy tank.
* @param type the type of enemy tank.
* @return an enemy tank or null.
*/
public static EnemyTank newEnemyTank(int type){
EnemyTank enemyTank=getFreeEnemyTank(type);
if(enemyTank!=null){
enemyTank.initTank();
enemyTank.setVisible(true);
}
return enemyTank;
}
////////////////////////////////////////////////////////////////////////////
//--------------------------------- REVISIONS ------------------------------
// Date Name Tracking # Description
// --------- ------------------- ------------- ----------------------
// 16JAN2008 James Shen Initial Creation
////////////////////////////////////////////////////////////////////////////
/**
* Set new tank frame based on type,direction,hasPrize.
*/
protected void setTankFrame(){
switchImage=!switchImage;
int offset=switchImage ? 0: 1;
int offset1=hasPrize ?2:0;
int frame=direction*23+offset+offset1+type*4+(blood-1)*2;
if(type==TYPE_HEAVY && hasPrize){
frame=direction*23+offset+type*4+8;
}
try{
if(frame>=0 || frame<92){
setFrame(frame);
}}
catch(Exception e){
//System.out.println("enemy:"+frame+","+blood);
}
}
////////////////////////////////////////////////////////////////////////////
//--------------------------------- REVISIONS ------------------------------
// Date Name Tracking # Description
// --------- ------------------- ------------- ----------------------
// 16JAN2008 James Shen Initial Creation
////////////////////////////////////////////////////////////////////////////
/**
* Explode a tank.
*/
protected void explode() {
if(type==TYPE_HEAVY && hasPrize && blood==4){
GameScene.canPutPowerup=true;
hasPrize=false;
}
blood--;
if(blood==0){
super.explode();
Score.show(getX(),getY(),score);
//this global variable approach is not that good.
GameScene.enemyTankRemains--;
if(hasPrize){
GameScene.canPutPowerup=true;
}
GameScene.enemyTanksCount[type]++;
}
}
////////////////////////////////////////////////////////////////////////////
//--------------------------------- REVISIONS ------------------------------
// Date Name Tracking # Description
// --------- ------------------- ------------- ----------------------
// 16JAN2008 James Shen Initial Creation
////////////////////////////////////////////////////////////////////////////
/**
* Get a free enemy tank based on given type.
* @param type the type of enemy tank.
* @return an enemy tank or null.
*/
private static EnemyTank getFreeEnemyTank(int type){
EnemyTank enemyTank=null;
int left=0,right=0;
switch(type){
case TYPE_SIMPLE:
left=1;right=7;
break;
case TYPE_FAST:
left=8;right=11;
break;
case TYPE_SMART:
left=12;right=15;
break;
case TYPE_HEAVY:
left=16;right=19;
break;
}
for(int i=left;i<=right;i++){
enemyTank=(EnemyTank)TANK_POOL[i];
if(!enemyTank.isVisible()){
battleField.initEnemyTankPos(enemyTank);
enemyTank.setVisible(true);
if(overlapsTank(enemyTank)){
enemyTank.setVisible(false);
enemyTank=null;
continue;
}
return enemyTank;
}
}
return null;
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -