⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 powerup.java

📁 还记得儿时在游戏机上玩坦克大战吗?如今这种经典游戏不在游戏机上玩了
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
//------------------------------------------------------------------------------
//                         COPYRIGHT 2008 GUIDEBEE
//                           ALL RIGHTS RESERVED.
//                     GUIDEBEE CONFIDENTIAL PROPRIETARY
///////////////////////////////////// REVISIONS ////////////////////////////////
// Date       Name                 Tracking #         Description
// ---------  -------------------  ----------         --------------------------
// 17JAN2008  James Shen                 	      Initial Creation
////////////////////////////////////////////////////////////////////////////////
//--------------------------------- PACKAGE ------------------------------------
//Permission is hereby granted, free of charge, to any person obtaining a copy
//of this software and associated documentation files (the "Software"), to deal
//in the Software without restriction, including without limitation the rights
//to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
//copies of the Software, and to permit persons to whom the Software is
//furnished to do so, subject to the following conditions:
//
//The above copyright notice and this permission notice shall be included in all
//copies or substantial portions of the Software.
//
//The Software shall be used for Good, not Evil.
//
//THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
//SOFTWARE.
//Any questions, feel free to drop me a mail at james.shen@guidebee.biz.
package com.pstreets.game.battlecity;

//--------------------------------- IMPORTS ------------------------------------
import javax.microedition.lcdui.*;
import javax.microedition.lcdui.game.*;
//[------------------------------ MAIN CLASS ----------------------------------]
////////////////////////////////////////////////////////////////////////////////
//--------------------------------- REVISIONS ----------------------------------
// Date       Name                 Tracking #         Description
// --------   -------------------  -------------      --------------------------
// 17JAN2008  James Shen                 	      Initial Creation
////////////////////////////////////////////////////////////////////////////////
/**
 * Power up class which can upgrade player's tank.
 * <p>
 * <hr><b>&copy; Copyright 2008 Guidebee, Inc. All Rights Reserved.</b>
 * @version     1.00, 17/01/08
 * @author      Guidebee, Inc.
 */
public final class Powerup extends Sprite implements Actor{
    
    /**
     * invulnerable animation.
     */
    public static final int INVULNERABLE=1;
    
    /**
     * Player's home
     */
    public static final int HOME=2;
    
    /**
     * Player's home been destroyed.
     */
    public static final int HOME_DESTROYED=3;
    
    /** 
     * Tank symbol gives an extra life. 
     */
    public static final int TANK = 4;
    
    /** 
     * Clock freezes all enemy tanks for a period of time. 
     */
    public static final int CLOCK = 5;
    
    /** 
     * Shovel adds steel walls around the base for a period of time. 
     */
    public static final int SHOVEL = 6;
    
    /** 
     * Bomb destroys all visible enemy tanks. 
     */
    public static final int BOMB = 7;
    
    /** 
     * Star improves player's tank. maxium 8 grades.
     */
    public static final int STAR = 8;
    
    /** 
     * Shield makes player's tank invulnerable to attack for a period of time. 
     */
    public static final int SHIELD = 9;
    
    /**
     * Tank should know about the battle field.
     */
    private static BattleField battleField;
    
    /**
     * Tank should know about the layer manager.
     */
    private static LayerManager layerManager;
    
    /** 
     * No image. 
     */
    private static final int NOTHING = 10;
    
    /**
     * maximun number of power ups in the battle field.
     */
    private static final int POOL_SIZE = 10;
    
    /**
     * This pool store all powerups.
     */
    private static Powerup POWERUP_POOL[];
    
    /**
     * time monitored to avoid the powerup flashes too fast.
     */
    private long timeTaken = MILLIS_PER_TICK;
    
    /**
     * minimum time period between each flash
     */
    private static final int MILLIS_PER_TICK = 50; 
    
    /**
     * initial the powerup pool.
     */
    static {
        POWERUP_POOL = new Powerup[POOL_SIZE];
        for(int i=0;i<POOL_SIZE;i++){
            POWERUP_POOL[i]=new Powerup(NOTHING);
            POWERUP_POOL[i].setVisible(false);
        }
        POWERUP_POOL[0].type=INVULNERABLE;
    }

    /**
     * the type of the powerup
     */
    private int type=NOTHING;
    
    /**
     * varible to toggle the powerup image to make it animation.
     */
    private boolean showNextFrame=false;
    
    /**
     * the start time of the powup.
     */
    private long startTime=0;
    /**
     * the poweup live time, default 3 minutes.
     */
    private static long livePeriod=180000;
    
    ////////////////////////////////////////////////////////////////////////////
    //--------------------------------- REVISIONS ------------------------------
    // Date       Name                 Tracking #         Description
    // ---------  -------------------  -------------      ----------------------
    // 17JAN2008  James Shen                 	          Initial Creation 
    ////////////////////////////////////////////////////////////////////////////
    /**
     * Set the new type for the poweup.
     * @param type new type.
     */
    public void setType(int type){
        this.type=type;
    }
    
    ////////////////////////////////////////////////////////////////////////////
    //--------------------------------- REVISIONS ------------------------------
    // Date       Name                 Tracking #         Description
    // ---------  -------------------  -------------      ----------------------
    // 17JAN2008  James Shen                 	          Initial Creation 
    ////////////////////////////////////////////////////////////////////////////
    /**
     * return the type for the poweup.
     * @return the type of the powerup.
     */
    public int getType(){
        return this.type;
    }
    
    ////////////////////////////////////////////////////////////////////////////
    //--------------------------------- REVISIONS ------------------------------
    // Date       Name                 Tracking #         Description
    // ---------  -------------------  -------------      ----------------------
    // 17JAN2008  James Shen                 	          Initial Creation 
    ////////////////////////////////////////////////////////////////////////////
    /**
     * Constructor.
     * @param type the type of the powerup.
     */
    private Powerup(int type) {
        super(ResourceManager.getInstance().getImage(ResourceManager.BONUS),
                ResourceManager.TILE_WIDTH,ResourceManager.TILE_WIDTH);
        defineReferencePixel(ResourceManager.TILE_WIDTH/8,
                ResourceManager.TILE_WIDTH/8);
        this.type=type;
    }
    
    ////////////////////////////////////////////////////////////////////////////

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -