//------------------------------------------------------------------------------
// COPYRIGHT 2007 GUIDEBEE
// ALL RIGHTS RESERVED.
// GUIDEBEE CONFIDENTIAL PROPRIETARY
///////////////////////////////////// REVISIONS ////////////////////////////////
// Date Name Tracking # Description
// --------- ------------------- ---------- --------------------------
// 15JAN2008 James Shen Initial Creation
////////////////////////////////////////////////////////////////////////////////
//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 ------------------------------------
package com.pstreets.game.battlecity.screen;
import java.io.IOException;
import java.util.Random;
import com.mapdigit.game.Layer;
import com.mapdigit.game.LayerManager;
import com.mapdigit.game.Sprite;
import com.pstreets.game.battlecity.ResourceManager;
import com.pstreets.game.battlecity.actors.Actor;
import com.pstreets.game.battlecity.actors.BattleField;
import com.pstreets.game.battlecity.actors.Bullet;
import com.pstreets.game.battlecity.actors.Explosion;
import com.pstreets.game.battlecity.actors.Powerup;
import com.pstreets.game.battlecity.actors.Score;
import com.pstreets.game.battlecity.actors.tank.EnemyTank;
import com.pstreets.game.battlecity.actors.tank.PlayerTank;
import com.pstreets.game.battlecity.actors.tank.Tank;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.os.Handler;
import android.view.KeyEvent;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
//--------------------------------- IMPORTS ------------------------------------
//[------------------------------ MAIN CLASS ----------------------------------]
////////////////////////////////////////////////////////////////////////////////
//--------------------------------- REVISIONS ----------------------------------
// Date Name Tracking # Description
// -------- ------------------- ------------- --------------------------
// 15JAN2008 James Shen Initial Creation
////////////////////////////////////////////////////////////////////////////////
/**
* The scene screen for the game.
* <p>
* <hr><b>© Copyright 2008 Guidebee, Inc. All Rights Reserved.</b>
* @version 1.00, 15/01/08
* @author Guidebee, Inc.
*/
public final class GameScene extends SurfaceView implements Runnable,SurfaceHolder.Callback{
////////////////////////////////////////////////////////////////////////////
//Game content variables,here used class public static member variables.
/**
* enemy tank killed in each level for each tank type.
*/
public static int []enemyTanksCount=new int[4];
/**
* Total enemy tanks in one leve.
*/
private static final int TOTAL_ENEMY_TANKS=20;
/**
* total enemy tanks remains.
*/
public static int enemyTankRemains=TOTAL_ENEMY_TANKS;
/**
* whether can put a poweup, it's because a red tank is been shot dead or
* in the given period.
*/
public static boolean canPutPowerup=false;
////////////////////////////////////////////////////////////////////////////
/**
* The layer manager manage all actors in the game.
*/
private LayerManager layerManager=new LayerManager();
/**
* Player's tank.
*/
private PlayerTank playerTank;
/**
* Resource Manager.
*/
private static ResourceManager resourceManager=ResourceManager.getInstance();
/**
* The battle field object.
*/
private BattleField battleField=null;
/**
* This thread is core game logic.
*/
private volatile Thread animationThread = null;
/**
* time taken and MILLIS_PER_TICK control the game speed
*/
private long timeTaken = 0;
/**
*time taken and MILLIS_PER_TICK control the game speed
*/
private static final int MILLIS_PER_TICK = 100;
/**
* the width of the game scene.
*/
private static int sceneWidth;
/**
* the height of the game scene.
*/
private static int sceneHeight;
/**
* the height of the score bar.
*/
private static int barHeight=32;
/**
* the X origin of the battle field.
*/
private int battleFieldX;
/**
* the Y origin of the battle field.
*/
private int battleFieldY;
/**
* default lives of player
*/
private final static int DEFAULT_PLAYER_LIVE=9;
/**
* maximum game leves.
*/
private static final int TOTAL_GAME_LEVELS=50;
/**
* total actors in the scene.
*/
private int totalLayers=0;
/**
* is game over?
*/
private boolean isGameover=false;
/**
* game over image
*/
private static Bitmap imgGameover=
resourceManager.getImage(ResourceManager.GAME_OVER_SMALL);
/**
* pause image
*/
private static Bitmap imgPause=
resourceManager.getImage(ResourceManager.PAUSE);
/**
* black number image from 0 to 9
*/
private static Bitmap imgNumberBlack=
resourceManager.getImage(ResourceManager.NUMBER_BLACK);
/**
* enemy icon
*/
private static Bitmap imgEnemyIcon=
resourceManager.getImage(ResourceManager.ENEMY_ICON);
/**
* first player icon
*/
private static Bitmap imgIP=
resourceManager.getImage(ResourceManager.IP);
/**
* flag image
*/
private static Bitmap imgFlag=
resourceManager.getImage(ResourceManager.FLAG);
/**
* offset X where start to draw the score bar
*/
private int marginX=0;
/**
* offset Y where start to draw the score bar
*/
private int marginY=0;
/**
* Random object to create random numbers.
*/
private static Random rnd=new Random();
/**
* time control to create new enemy tank
*/
private long enemySpawnStartTime=0;
/**
* minimun spawn timer
*/
private final static long enemySpawnPeriod=2000;
/**
* timer control when to put an poweup in the battle field
*/
private long putPowerupStartTime=0;
/**
* put poweup minimum p
- 1
- 2
前往页