📄 cscene.java
字号:
/**
* <p>Project Name: Bowling 3D</p>
* <p>Platform: Sony Ericsson K700i</p>
* <p>Copyright: Copyright (c) 2004</p>
* <p>Company: Gameloft Shanghai</p>
* <p>Description: Manage scene which include all the objects in the game scene.
* It implements load/ release scene data, render scene, camera control, update
* objects’data and do collision detection.</p>
* @author Tao Qing
*/
import java.util.*;
import javax.microedition.lcdui.Graphics;
class CScene {
/*static define atart*/
/**
* <p>The constant's one bit stands for one bowling pin's status,
* setting 1 measns the pin is stand,
* setting 0 means the pin is falled.
* From left to right stands for #1 pin to #10 pin. </p>
*
* <p>So constant (ALL_PINS_STAND) 0x3ff stands for ten pins are all stand
* and constant (ALL_PINS_FALL) 0x0 stands none pin is stand.</p>
*/
public static final int ALL_TENPINS_STAND = 0x3ff; // 0...0 1111111111
/**
* Constant stands for all pins are falled.
*
* @see ALL_PINS_STAND
*/
public static final int ALL_TENPINS_FALL = 0x0; // 0...0 0000000000
/** lane width */
public static final byte TOTAL_TENPIN_NUMBER = 10;
/** Base Line */
public static final int BASE_LINE = 2300 * def.DEFAULT_EXTEND; //changed to public by Milo
/** distance between two pins nearby */
private static final int PIN_DISTANCE = 32 * def.DEFAULT_EXTEND;
/** lane data on heavy oil area */
private static final int HEAVY_OIL_AREA = 500 * def.DEFAULT_EXTEND;
/** lane data on light oil area */
private static final int LIGHT_OIL_AREA = 1000 * def.DEFAULT_EXTEND;
//friction modulus
/** friction modulus on light oil area */
public static final int LFRICTION_MODULUS = 2;
/** friction modulus on unoil area */
public static final int UFRICTION_MODULUS = 2;
//the reducing velocity of ball in gutter
public static final int GUTTER_REDUCTION = 70;
/**the falling acceleration of the pin*/
private static final int ACCELERATION_FALLING = 75;//25;//150; //Milo 10-12
private static final int ANGLE_PERFRAME = 300;//100; //600; //Milo 10-12
private static final int SLOW_ACTION_GRADE = 4; //Milo 10-12
/** the relative zero postion*/
public static final int ZERO_POSITION_X = def.DISPLAY_WIDTH / 3;
public static final int ZERO_POSITION_Y = def.DISPLAY_HEIGHT - 30;
//add elements here
/**the total time of ball movement*/
private int m_time;
//the destination position of ball (the collision point between ball & tenpins)
private int m_ballDestinationPositionX;
private int m_ballDestinationPositionY;
/**the flag whether it is the first time that ball collides the pin*/
private boolean m_firstCollision;
/**the flag whether ball has collided the pin*/
private boolean m_hasBeenCollided;
/** movement finished flag */
private boolean m_bMovementFinished;
//the flag to judge whether the ball into Tenpin Area
private boolean m_isInTenpinArea;
//default tenpin landing position;[i][0]:X on coordinate [i][1]:Y on coordinate
private int[][] m_tenpinLandingPosition = new int[10][2];
//the Player
public CPlayer m_player; // Milo call different constructor
//
private int m_accelerationFalling;
private int m_anglePerframe;
private boolean m_isSwitch;
// private int[][] m_tempTenpinVelocity = new int[10][2];
// private int[] m_tempBallVelocity = new int[2];
private boolean m_isAfterCollision = false;
//this position will be used to draw the play
public int[] m_playerPosition = new int[3];
public int[] m_playerRotation = new int[3];
public int[] m_stagePosition = {
0, 0, 0};
//the Ball
private CBall m_ball;
//the tenpins
public CTenpin[] m_tenpin = new CTenpin[10];
/** the total number of the frame */
private int m_nFrame = 0;
/** the instance for Render 3D model */
public CRender3D m_render3D; //Milo;forRender3D
/** the instance for Render 2D model */
// public CRender2D m_render2D; //Milo;forRender3D
/** the old eye of Render 3D */
private int[] m_oldEye = {
0, 0, 0}; //Milo;forRender3D
/** the old eye of Render 3D */
private int[] m_oldLookat = {
0, -100, 0}; //Milo;forRender3D
// default eye setting
private final int[] m_defEyePos = {
0, -350, 180};
private final int[] m_defEyeLookAt = {
0, 100, -20};
// anchor setting
private int[] m_ancBase = {
0, 500, 50};
private final int[] m_ancRot = {
0, 0, 0};
public int m_ancPos = 0;
// player anim
private int m_frameIndex = 0;
private final int m_frameCount = 65;
private int[] m_ballRenderRotation = {
0, 0, 0}; //new int[3];
private int[] m_ballRenderPosition = {
0, 0, 0}; //new int[3];
private boolean m_eyeLock = false;
/** store the current tenpin State*/
private int m_currentTenpinState = 0;
//add lane setting here
public CScene() {
}
/**
* load all OBJECT in game scene: ball, player, tenpin and scene.
* @return boolean Load successful or not.
*/
public boolean Load() {
try {
m_render3D.LoadModelsInfo(); //Milo;forRender3D
m_render3D.LoadAllModels(); //Milo;forRender3D
for (int i = 0; i < 3; ++i)
m_oldLookat[i] = m_render3D.m_lookat[i];
}
catch (Exception e) {
//m_error += "CON" + e.toString();
e.printStackTrace();
}
return true;
}
/**
* Release all object in game scene.
*/
public void Release() {
}
/**
* Render game scene.
*/
public void RenderScene(int flag) {
int i = 0;
int[] rotation = {
0, 0, 0}; //new int[3];
int[] position = {
0, 200, 0}; //new int[3];
try {
m_render3D.RenderModel(0, 0, 0, null, null);
//render ball
//m_render3D.RenderModel(2, 0, 0, position, rotation); //Milo;forRender3D
m_ball.m_ballRollingArray[0] += 100; //* def.sin(450) / def.VALUE_MULTIPLE_TEN;//m_ball.m_ballRollingDegree * def.sin(450) / def.VALUE_MULTIPLE_TEN;;
//m_ball.m_ballRollingArray[0] %= 3600;
m_ball.m_ballRollingArray[1] += 100; //(100 +m_ball.m_ballRollingDegree * def.sin(450) / def.VALUE_MULTIPLE_TEN);
//m_ball.m_ballRollingArray[1] %= 3600;
m_ball.m_ballRollingArray[2] += 0; //100;//100;//(100 + m_ball.m_ballRollingDegree * 50);
//m_ball.m_ballRollingArray[2] %= 3600; //ACCORDING TO THE VECLCITY OF X,Y
rotation[0] = m_ball.m_ballRollingArray[0]; //20;//900 * m_ball.m_ballRollingDegree * def.sin(450) / def.VALUE_MULTIPLE_TEN;
rotation[1] = m_ball.m_ballRollingArray[1]; //60;//20 * m_ball.m_ballRollingDegree * def.sin(450) / def.VALUE_MULTIPLE_TEN;///rotation[0];
//if (m_ball.m_ballRotationDirection == 0)
//rotation[2] = -m_ball.m_ballRollingArray[2]; //900;// * m_ball.m_ballRollingDegree;
//else
rotation[2] = m_ball.m_ballRollingArray[2]; //900;// * m_ball.m_ballRollingDegree;
position[0] = (m_ball.m_currentBallPosition[0] - def.LANE_WIDTH / 2)
/ def.DEFAULT_EXTEND;
position[1] = m_ball.m_currentBallPosition[1] / def.DEFAULT_EXTEND;
position[2] = m_ball.m_currentBallPosition[2] / def.DEFAULT_EXTEND;
//if (flag != 3)
m_render3D.RenderModel(2, 0, 0, position, rotation); //Milo;forRender3D
if (flag == 2
&
m_ball.m_currentBallPosition[1] <
(def.LANE_LENGTH - 200 * def.DEFAULT_EXTEND)) {
if (m_eyeLock != true) {
m_oldEye[0] = m_render3D.m_eye[0];
m_oldEye[1] = m_render3D.m_eye[1];
m_oldEye[2] = m_render3D.m_eye[2];
int[] tempLookat = {
m_render3D.m_lookat[0],
m_render3D.m_lookat[1], m_render3D.m_lookat[2]};
m_render3D.m_lookat[0] = m_oldLookat[0];
m_render3D.m_lookat[1] = m_oldLookat[1];
m_render3D.m_lookat[2] = m_oldLookat[2];
m_oldLookat[0] = tempLookat[0];
m_oldLookat[1] = tempLookat[1];
m_oldLookat[2] = tempLookat[2];
}
m_render3D.m_eye[0] = position[0];
m_render3D.m_eye[1] = position[1] - 300;
m_render3D.m_eye[2] = position[2] + 80;
//m_render3D.m_lookat[1] = m_render3D.m_eye[1]+300;
UpdateCamera();
m_eyeLock = true;
}
else if (m_eyeLock == true) {
m_render3D.m_eye[0] = m_oldEye[0];
m_render3D.m_eye[1] = m_oldEye[1];
m_render3D.m_eye[2] = m_oldEye[2];
int[] tempLookat = {
m_oldLookat[0], m_oldLookat[1],
m_oldLookat[2]};
m_oldLookat[0] = m_render3D.m_lookat[0];
m_oldLookat[1] = m_render3D.m_lookat[1];
m_oldLookat[2] = m_render3D.m_lookat[2];
m_render3D.m_lookat[0] = tempLookat[0];
m_render3D.m_lookat[1] = tempLookat[1];
m_render3D.m_lookat[2] = tempLookat[2];
//m_render3D.m_lookat[1] = m_oldEye[1] + 300;
UpdateCamera();
m_eyeLock = false;
}
//render player
//m_render3D.RenderModel(1, 0, 0, m_playerPosition, null); //Milo;forRender3D
//render tenpins
int check = 0x0001;
for (i = 0; i < 10; ++i) {
/*if (i == 0){
System.out.println("Tenpin 0 Angle XYvY is "+ m_tenpin[i].m_tenpinAngle[2]);
System.out.println("Tenpin 0 Angle Z is "+ m_tenpin[i].m_tenpinAngle[0]);
System.out.println("m_tenpin[i].m_tenpinRotation"+m_tenpin[i].m_rollingArea);
}*/
rotation[0] = 0; //-900;//m_tenpin[i].m_tenpinAngle[2];//m_tenpin[i].m_tenpinAngle[2];//0;//m_tenpin[i].m_tenpinAngle[0];// * def.sin(450) /def.VALUE_MULTIPLE_TEN;
rotation[1] = m_tenpin[i].m_tenpinAngle[2]; //rotation[0];
rotation[2] = m_tenpin[i].m_tenpinAngle[0]; //0; //m_tenpin[i].m_tenpinRotation;
if (flag == 2) {
if ( ( (m_currentTenpinState & check) >> i == 1)) {
if (m_tenpin[i].m_tenpinState != CTenpin.TENPIN_STATE_OUTSIDE) {
position[0] = (m_tenpin[i].m_tenpinPosition[0] -
def.LANE_WIDTH / 2)
/ def.DEFAULT_EXTEND;
position[1] = m_tenpin[i].m_tenpinPosition[1]
/ def.DEFAULT_EXTEND;
position[2] = (m_tenpin[i].m_tenpinPosition[2] +
m_tenpin[i].m_tenpinJumpHeight)
/ def.DEFAULT_EXTEND;
// CTenpin.TENPIN_RADIUS * ((def.sin(m_tenpin[i].m_tenpinAngle[0])) / def.VALUE_MULTIPLE_TEN ) + m_tenpin[i].m_tenpinJumpHeight)/ def.DEFAULT_EXTEND;
m_render3D.RenderModel(1, 0, 0, position, rotation); //Milo;forRender3D
}
}
check = check << 1;
}
else if (flag == 3) {
if (m_tenpin[i].m_tenpinState != CTenpin.TENPIN_STATE_OUTSIDE) { //== CTenpin.TENPIN_STATE_STAND) {
position[0] = (m_tenpin[i].m_tenpinPosition[0] - def.LANE_WIDTH / 2)
/ def.DEFAULT_EXTEND;
position[1] = m_tenpin[i].m_tenpinPosition[1]
/ def.DEFAULT_EXTEND;
position[2] = (m_tenpin[i].m_tenpinPosition[2] +
m_tenpin[i].m_tenpinJumpHeight)
/ def.DEFAULT_EXTEND;
// / CTenpin.TENPIN_RADIUS * (def.sin(m_tenpin[i].m_tenpinAngle[0]) / def.VALUE_MULTIPLE_TEN))/ def.DEFAULT_EXTEND;
m_render3D.RenderModel(1, 0, 0, position, rotation); //Milo;forRender3D
//System.out.println("XXXXXXXXXXXXXXXXXXXXXXTENPIN " + i +"XXXXXXXXANGLE-Z" + m_tenpin[i].m_tenpinAngle[0]);
}
}
else if (flag == 1) {
if (m_tenpin[i].m_tenpinState == CTenpin.TENPIN_STATE_STAND) {
position[0] = (m_tenpin[i].m_tenpinPosition[0] - def.LANE_WIDTH / 2)
/ def.DEFAULT_EXTEND;
position[1] = m_tenpin[i].m_tenpinPosition[1]
/ def.DEFAULT_EXTEND;
position[2] = (m_tenpin[i].m_tenpinPosition[2] +
m_tenpin[i].m_tenpinJumpHeight)
/ def.DEFAULT_EXTEND;
//(CTenpin.TENPIN_RADIUS * (def.sin(m_tenpin[i].m_tenpinAngle[0])) / def.VALUE_MULTIPLE_TEN ))/ def.DEFAULT_EXTEND;
m_render3D.RenderModel(1, 0, 0, position, rotation); //Milo;forRender3D
}
}
}
//RenderShadow(); //???Milo
//RenderStrip(); //???Milo
}
catch (Exception e) {
//m_error = "MODEL_tenpin" + e.toString() + m_tenpin[i];
e.printStackTrace();
}
}
/**
* Update all object status, properties and movement. //???milo is it step()
*/
public int UpdateScene(int roundStage) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -