//------------------------------------------------------------------------------
// 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;
//--------------------------------- IMPORTS ------------------------------------
import java.io.*;
import java.util.*;
import javax.microedition.lcdui.*;
import javax.microedition.lcdui.game.*;
//[------------------------------ 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 GameCanvas implements Runnable{
////////////////////////////////////////////////////////////////////////////
//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 = 1;
/**
* 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 Image imgGameover=
resourceManager.getImage(ResourceManager.GAME_OVER_SMALL);
/**
* pause image
*/
private static Image imgPause=
resourceManager.getImage(ResourceManager.PAUSE);
/**
* black number image from 0 to 9
*/
private static Image imgNumberBlack=
resourceManager.getImage(ResourceManager.NUMBER_BLACK);
/**
* enemy icon
*/
private static Image imgEnemyIcon=
resourceManager.getImage(ResourceManager.ENEMY_ICON);
/**
* first player icon
*/
private static Image imgIP=
resourceManager.getImage(ResourceManager.IP);
/**
* flag image
*/
private static Image 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 period, 2 minutes
*/
private final static long putPowerupPeriod=120000;
/**
* display game over or pause
*/
private static Sprite gameStatus=null;
/**
* timer control when game over to display game over image,from bottom
* to the middle of the screen.
*/
private long gameOverStartTime=0;
/**
* after this period, display the score screen,default 4 seconds.
*/
private final static long gameOverPeriod=4000;
////////////////////////////////////////////////////////////////////////////
//--------------------------------- REVISIONS ------------------------------
// Date Name Tracking # Description
// --------- ------------------- ------------- ----------------------
// 19JAN2008 James Shen Initial Creation
////////////