📄 powerup.java
字号:
//--------------------------------- REVISIONS ------------------------------
// Date Name Tracking # Description
// --------- ------------------- ------------- ----------------------
// 18JAN2008 James Shen Initial Creation
////////////////////////////////////////////////////////////////////////////
/**
* Check if bullet hit Player's home,if so, display the destoryed home.
*/
public static boolean isHomeDestroyed(){
boolean bRet=false;
for(int i=1;i<POOL_SIZE;i++){
if(POWERUP_POOL[i].isVisible() &&
POWERUP_POOL[i].getType()==Powerup.HOME_DESTROYED ){
bRet=true;
break;
}
}
return bRet;
}
////////////////////////////////////////////////////////////////////////////
//--------------------------------- REVISIONS ------------------------------
// Date Name Tracking # Description
// --------- ------------------- ------------- ----------------------
// 18JAN2008 James Shen Initial Creation
////////////////////////////////////////////////////////////////////////////
/**
* Check if bullet hit Player's home,if so, display the destoryed home.
*/
public static boolean isHittingHome(Bullet bullet){
boolean bRet=false;
Powerup home=null;
for(int i=1;i<POOL_SIZE;i++){
if(POWERUP_POOL[i].isVisible() &&
POWERUP_POOL[i].getType()==Powerup.HOME ){
home=POWERUP_POOL[i];
}
}
if(home!=null){
bRet=bullet.collidesWith(home,false);
if(bRet){
home.setType(Powerup.HOME_DESTROYED);
}
}
return bRet;
}
////////////////////////////////////////////////////////////////////////////
//--------------------------------- REVISIONS ------------------------------
// Date Name Tracking # Description
// --------- ------------------- ------------- ----------------------
// 17JAN2008 James Shen Initial Creation
////////////////////////////////////////////////////////////////////////////
/**
* Create a new power up in the battle field.
* @param type the type of the powerup.
*/
public static void putNewPowerup(int type){
for(int i=1;i<POOL_SIZE;i++){
if(!POWERUP_POOL[i].isVisible()){
POWERUP_POOL[i].setType(type);
battleField.initPowerupPos(POWERUP_POOL[i]);
POWERUP_POOL[i].setVisible(true);
POWERUP_POOL[i].startTime=System.currentTimeMillis();
break;
}
}
}
////////////////////////////////////////////////////////////////////////////
//--------------------------------- REVISIONS ------------------------------
// Date Name Tracking # Description
// --------- ------------------- ------------- ----------------------
// 17JAN2008 James Shen Initial Creation
////////////////////////////////////////////////////////////////////////////
/**
* Operation be done in each tick.
*/
public void tick(){
if(type==NOTHING || !isVisible()) return;
long tickTime = System.currentTimeMillis();
long refreshPeriod=MILLIS_PER_TICK;
//invulnerable powerup is controlled by the player tank.
if(type!=INVULNERABLE &&type!=HOME && type!=HOME_DESTROYED){
if(tickTime-startTime>livePeriod){
setFrame(NOTHING);
setVisible(false);
return;
}
}else{
refreshPeriod=MILLIS_PER_TICK/10;
}
if(timeTaken>=refreshPeriod){
showNextFrame=!showNextFrame;
if(type==INVULNERABLE){
if(showNextFrame){
setFrame(0);
}else{
setFrame(1);
}
}else if(type==HOME || type==HOME_DESTROYED){
setFrame(type);
}else{
if(showNextFrame){
setFrame(type);
}else{
setFrame(NOTHING);
}
}
timeTaken = System.currentTimeMillis() - tickTime;
} else{
timeTaken+=1;
}
}
////////////////////////////////////////////////////////////////////////////
//--------------------------------- REVISIONS ------------------------------
// Date Name Tracking # Description
// --------- ------------------- ------------- ----------------------
// 17JAN2008 James Shen Initial Creation
////////////////////////////////////////////////////////////////////////////
/**
* Check if player's tank move above the powerup.
* @param tank player's tank.
*/
public static void checkPlayerTank(PlayerTank tank){
Powerup powerup;
for(int i=1;i<POOL_SIZE;i++){
if(POWERUP_POOL[i].isVisible()){
powerup=POWERUP_POOL[i];
if(powerup.collidesWith(tank,false)){
tank.upgrade(powerup);
if(!(powerup.type==powerup.HOME ||
powerup.type==Powerup.HOME_DESTROYED)){
powerup.setVisible(false);
Score.show(tank.getX(),tank.getY(),Score.SCORE_500);
tank.addScore(500);
}
}
}
}
}
////////////////////////////////////////////////////////////////////////////
//--------------------------------- REVISIONS ------------------------------
// Date Name Tracking # Description
// --------- ------------------- ------------- ----------------------
// 15JAN2008 James Shen Initial Creation
////////////////////////////////////////////////////////////////////////////
/**
* Get the invulnerable powerup. When player collects this powerup. it shows
* invulnerable animation.
* @return the invulnerable powerup.
*/
public static Powerup getInvulnerable(){
return POWERUP_POOL[0];
}
////////////////////////////////////////////////////////////////////////////
//--------------------------------- REVISIONS ------------------------------
// Date Name Tracking # Description
// --------- ------------------- ------------- ----------------------
// 16JAN2008 James Shen Initial Creation
////////////////////////////////////////////////////////////////////////////
/**
* Player has collected {@see Powerup.BOMB}. Enemies should explode immediately.
*/
public static void removeAllPowerups() {
for (int i = 1; i < POOL_SIZE; ++i) {
Powerup powerup = POWERUP_POOL[i];
powerup.setVisible(false);
}
}
////////////////////////////////////////////////////////////////////////////
//--------------------------------- REVISIONS ------------------------------
// Date Name Tracking # Description
// --------- ------------------- ------------- ----------------------
// 15JAN2008 James Shen Initial Creation
////////////////////////////////////////////////////////////////////////////
/**
* Set the layerManager for powerups.
*/
public static void setLayerManager(LayerManager manager) {
layerManager = manager;
if (layerManager != null){
for (int i = 0; i < POOL_SIZE; i++)
layerManager.append(POWERUP_POOL[i]);
}
}
////////////////////////////////////////////////////////////////////////////
//--------------------------------- REVISIONS ------------------------------
// Date Name Tracking # Description
// --------- ------------------- ------------- ----------------------
// 15JAN2008 James Shen Initial Creation
////////////////////////////////////////////////////////////////////////////
/**
* Set the Battle field for powerups.
*/
public static void setBattleField(BattleField field) {
battleField = field;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -