📄 cgameplay.java
字号:
/**
* <p>Title: class CGamePlay</p>
* <p>Description: bowling game play. It implements state switch of bowling game,
* game mode manager, in-game interface render, key response, score, level system
* and gambling system.</p>
* <p>Copyright: Copyright (c) 2004</p>
* <p>Company: Gameloft ShangHai</p>
* @author Tao Qing
* @version 1.0
*/
import java.io.IOException;
import javax.microedition.lcdui.*;
//import com.mascotcapsule.micro3d.v3.*;
class CGamePlay {
/*static define atart*/
//the sub states in Game playing
public static final byte ROUND_INIT = 0;
public static final byte PLAYER_POSITION_CONFIRM = 1;
public static final byte CAMERA_MOVEIN_ANIM = 2;
public static final byte AIM_SPOT_CONFIRM = 3;
public static final byte PLAYER_POWER_CONFIRM = 4;
public static final byte PLAYER_ACCURACY_CONFIRM = 5;
public static final byte CAMERA_MOVEOUT_ANIM = 6;
public static final byte ROTATION_POWER_CONFIRM = 7;
public static final byte BALL_RUNNING = 8;
public static final byte ROUND_FINISH = 9;
public static final byte MATCH_FINISH = 10;
//default aim spot was divided into 5 levels.
public static final byte MAX_AIM_SPOT = 5;
//default maximum rounds in one game is 10, m_roundNumber from 0-9
public static final byte MAX_ROUND_NUMBER = 9;
//THE MEASUREMENT OF SCORE BOARD
private static final byte SCORE_BOARD_WIDTH = 20;
private static final byte SCORE_BOARD_HEIGHT = 28;
/*static define end*/
int m_GameState;
boolean m_bPause;
int m_keyCode = def.KEY_EMPTY;
//the state of Game
private byte m_staRound = 0;
//the aim spot of the ball
int m_aimSpot = 0;
//the rotation power of the ball
int m_rotationPower = 0;
//the power of player
int m_playerPower = 0;
//it stores the current number of rounds;the max rounds in a match is 10, so 0-9
byte m_roundNumber = 0;
//this variable decides whether the second ball will be used. true: don't need or has been used
boolean m_isSecondBall = false;
//CScene
CScene m_scene = new CScene();
//Judging whether the round is strike
boolean m_isStrike = false;
//judging whether the slow action was ask
boolean m_isSlowAction = false;
//judging whether the first shot in the 10th round is strike
boolean m_isBonusShot = false;
//the array store the state of tenpin
int m_tenpinState = 0;
//Judging whether the Zoom was open
boolean m_isZooming = false;
//Judging whether the rotation of scene was open
boolean m_isRollingScene = false;
//the rotation degree of the whole scene
int m_rotationSceneX = 0;
int m_rotationSceneY = 0;
// powerbar setting
private Image m_imgPowerbar;
//off set for Score Board
int m_offSet = 0;
boolean m_isScoreBoardChanged = false;
//private int m_Power = 0;
Image m_scoreImage = null;
Image m_offImage = null;
public CGamePlay() {
m_scene.init();
m_scene.Load();
try {
m_imgPowerbar = Image.createImage("/power_bar.png");
}
catch (IOException e) {
e.printStackTrace();
}
iniScoreInfo(m_scene.m_player.m_scoreInfo);
loadScoreImage();
}
/**
* update bowling game state. And determinate what should be render.
*/
public void Update(Graphics g) {
try {
switch (m_staRound) {
case ROUND_INIT:
m_scene.m_render3D.StartRender3D(g); //Milo;forRender3D
m_scene.UpdateScene(m_staRound);
m_scene.m_render3D.EndRender3D(g); //Milo;forRender3D
g.drawString("Press * to start play", 30, 50, Graphics.LEFT
| Graphics.TOP);
//m_scene.display2DModel(g); // added by Milo 09-06
break;
case PLAYER_POSITION_CONFIRM:
m_scene.m_render3D.StartRender3D(g); //Milo;forRender3D
m_scene.UpdateScene(m_staRound);
m_scene.m_render3D.EndRender3D(g); //Milo;forRender3D
showPlayerPositionStage(g);
break;
case CAMERA_MOVEIN_ANIM:
m_scene.m_render3D.StartRender3D(g);
if (m_scene.UpdateScene(m_staRound) == 1)
m_staRound = AIM_SPOT_CONFIRM;
m_scene.m_render3D.EndRender3D(g);
break;
case AIM_SPOT_CONFIRM:
m_scene.m_render3D.StartRender3D(g); //Milo;forRender3D
m_scene.UpdateScene(m_staRound);
m_scene.m_render3D.EndRender3D(g); //Milo;forRender3D
showAimSpotStage(g);
break;
case PLAYER_POWER_CONFIRM:
m_scene.m_render3D.StartRender3D(g); //Milo;forRender3D
m_scene.UpdateScene(m_staRound);
m_scene.m_render3D.EndRender3D(g); //Milo;forRender3D
m_playerPower += 6;
if ( (m_playerPower >= 80 && m_playerPower <= 122)) {
if (m_playerPower % 12 == 0)
g.drawRegion(m_imgPowerbar, 0, 0, 10, 102, 0, 20, 50,
Graphics.TOP | Graphics.LEFT);
else
g.drawRegion(m_imgPowerbar, 10, 0, 10, 102, 0, 20, 50,
Graphics.TOP | Graphics.LEFT);
}
else {
g.drawRegion(m_imgPowerbar, 0, 0, 10, 102, 0, 20, 50,
Graphics.TOP | Graphics.LEFT);
}
if (m_playerPower >= 192)
m_playerPower = 0;
if (m_playerPower > 96)
g.drawRegion(m_imgPowerbar, 20, 3 + m_playerPower - 96, 4,
192 - m_playerPower, 0, 23,
53 + m_playerPower - 96, Graphics.TOP
| Graphics.LEFT);
else
g.drawRegion(m_imgPowerbar, 20, 3 + 96 - m_playerPower, 4,
m_playerPower, 0, 23, 53 + 96 - m_playerPower,
Graphics.TOP | Graphics.LEFT);
showPlayerPowerStage(g);
break;
case PLAYER_ACCURACY_CONFIRM:
m_scene.m_render3D.StartRender3D(g);
m_scene.UpdateScene(m_staRound);
m_scene.m_render3D.EndRender3D(g);
break;
case CAMERA_MOVEOUT_ANIM:
m_scene.m_render3D.StartRender3D(g);
if (m_scene.UpdateScene(m_staRound) == 1)
m_staRound = ROTATION_POWER_CONFIRM;
m_scene.m_render3D.EndRender3D(g);
break;
case ROTATION_POWER_CONFIRM:
m_scene.m_render3D.StartRender3D(g); //Milo;forRender3D
if (m_scene.UpdateScene(m_staRound) == 1)
{
m_staRound = BALL_RUNNING;
m_scene.setRotationPower(m_rotationPower);
}
m_scene.m_render3D.EndRender3D(g); //Milo;forRender3D
showRotationPowerStage(g);
break;
case BALL_RUNNING:
step();
m_scene.m_render3D.StartRender3D(g); //Milo;forRender3D
m_scene.UpdateScene(m_staRound);
m_scene.m_render3D.EndRender3D(g); //Milo;forRender3D
break;
case ROUND_FINISH:
//showCollisionFinish(g); //& showRoundFinish(g);
m_scene.m_render3D.StartRender3D(g); //Milo;forRender3D
m_scene.UpdateScene(m_staRound);
m_scene.m_render3D.EndRender3D(g); //Milo;forRender3D
showCollisionFinish(g); //& showRoundFinish(g);
/*if (m_isScoreBoardChanged == true) {
drawScorlling(g, m_offSet, true, false);
//m_isScoreBoardChanged = false;
}
else {
drawScore(g, false);
}*/ //09-20 Milo
break;
case MATCH_FINISH:
m_scene.m_render3D.StartRender3D(g); //Milo;forRender3D
m_scene.UpdateScene(m_staRound);
m_scene.m_render3D.EndRender3D(g); //Milo;forRender3D
if (m_isScoreBoardChanged == true) {
drawScorlling(g, m_offSet, true, true);
//m_isScoreBoardChanged = false;
}
else {
drawScore(g, true);
}
showMatchFinish(g);
break;
default:
break;
}
//render3DModels(g);
}
catch (Exception e) {
//m_error = "MODEL" + e.toString();
e.printStackTrace();
m_scene.m_render3D.EndRender3D(g); //Milo;forRender3D
}
}
/**
* Respond the key event in game
*/
public void InputTick(int keyCode) {
m_keyCode = keyCode;
//09-06 && 09-20 for slow action
if (m_keyCode == CGameMain.gk_DOWNRIGHT)
{
m_isSlowAction = !m_isSlowAction;
m_scene.setFirstCall(true);
}
switch (m_staRound) {
case ROUND_INIT:
//do init
initRound();
break;
case PLAYER_POSITION_CONFIRM:
setCamera();
playerPositionAdjust();
break;
case AIM_SPOT_CONFIRM:
setCamera();
//aimSpotAdjust();
if (m_keyCode == CGameMain.gk_A) {
m_aimSpot = m_scene.m_ancPos;
if (m_aimSpot > 90)
m_aimSpot = 180 - m_aimSpot;
m_staRound = PLAYER_POWER_CONFIRM;
m_playerPower = 0;
}
break;
case PLAYER_POWER_CONFIRM:
setCamera();
playerPowerAdjust();
break;
case PLAYER_ACCURACY_CONFIRM:
m_staRound = CAMERA_MOVEOUT_ANIM;
break;
case ROTATION_POWER_CONFIRM:
rotationPowerAdjust();
break;
case BALL_RUNNING:
//step();
//();
//isStrike();//???Milo
/*if (m_keyCode == CGameMain.gk_C)
m_staRound = ROUND_FINISH;*/
break;
case ROUND_FINISH:
//calculateScore(); //Milo
getNextStop(); //judging what will be done in next step
break;
case MATCH_FINISH:
dealWithFinish();
default:
break;
}
} //Milo;forRender3D
/**
* DEBUG: Control the position of Player
*/
private void playerPositionAdjust() {
switch (m_keyCode) {
case CGameMain.gk_LEFT:
if ( (m_scene.m_playerPosition[0] - 5) > -(def.LANE_WIDTH / (2 * def.DEFAULT_EXTEND)))
//(-(CScene.LANE_WIDTH / (2 * def.DEFAULT_EXTEND))))
m_scene.m_playerPosition[0] -= 5; //left moving
break;
case CGameMain.gk_RIGHT:
if ( (m_scene.m_playerPosition[0] + 5) < (def.LANE_WIDTH / (2* def.DEFAULT_EXTEND)))
/// (2 * def.DEFAULT_EXTEND))
m_scene.m_playerPosition[0] += 5; //right moving
break;
case CGameMain.gk_A: //confirm go to AIM_SPOT_CONFIRM
m_staRound = CAMERA_MOVEIN_ANIM;
break;
default:
break;
}
//System.out.println(m_playerPositionX);
}
/**
* DEBUG: Control the aim of the ball
*/
/*private void aimSpotAdjust() {
switch (m_keyCode) {
case CGameMain.gk_LEFT:
if (m_aimSpot > -MAX_AIM_SPOT)
--m_aimSpot; //left moving
break;
case CGameMain.gk_RIGHT:
if (m_aimSpot < MAX_AIM_SPOT)
++m_aimSpot; //right moving
break;
case CGameMain.gk_A: //confirm go to ROTATION_POWER_CONFIRM
m_staRound = PLAYER_POWER_CONFIRM;
m_playerPower = 0;
break;
default:
break;
}
//System.out.println(m_aimSpot);
}*/
/**
* DEBUG: Control the rotation power of the ball
*/
private void rotationPowerAdjust() {
switch (m_keyCode) {
case CGameMain.gk_LEFT:
if (m_rotationPower > -CPlayer.MAX_PLAYER_ROTATION) //(-(m_scene.getPlayer().getRotation())))
--m_rotationPower; //decrease the rotation power
break;
case CGameMain.gk_RIGHT:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -