?? cball.java
字號:
/**
* <p>Title: class CBall</p>
* <p>Description: Includes properties of bowling ball and controls the ball’s movement.</p>
* <p>Copyright: Copyright (c) 2004</p>
* <p>Company: Gameloft ShangHai</p>
* @author Tao Qing, Wei XIA
* @version 1.0
*/
class CBall {
//state of ball
public static final byte BALL_INVALID = 0x00;
public static final byte BALL_ONLANE = 0x01;
public static final byte BALL_OUTSIDE = 0x02; //OUTSIDE
//Types of Ball
/** linear ball */
public static final int LINEAR_BALL = 0x00;
/** saucer ball */
public static final int SAUCER_BALL = 0x01;
/** curve ball */
public static final int CURVE_BALL = 0x03;
//Properties of CBall
public int m_radius;
public int m_weight;
public int m_rotationSpeed; //Milo
//the current position when ball is moving
/* private int m_currentBallPositionX;
private int m_currentBallPositionY;
private int m_currentBallPositionZ;*/
public int[] m_currentBallPosition = new int[3];
//the Velocity of ball
public int m_ballVelocityX;
public int m_ballVelocityY;
//the velocity of ball in gutter
public int m_ballGutterVelocity;
//acceleration
/** ball acceleration on x coordinate on light oil area*/
public int m_ballLAccelerationX;
/** ball acceleration on y coordinate on light oil area */
public int m_ballLAccelerationY;
/** ball acceleration on x coordinate on unoil area */
public int m_ballUAccelerationX;
/** ball acceleration on y coordinate on unoil area */
public int m_ballUAccelerationY;
//state of ball
public byte m_ballState = BALL_INVALID;
///** ball curve type: linear, saucer or curve */
public int m_ballCurveType;
/** ball spin direction: clockwise or anti-clockwise */
public int m_ballRotationDirection;
/** ball rolling degree */
public int m_ballRollingDegree;
/** ball rolling degree */
public int[] m_ballRollingArray = {0,0,0};
/**
* Constructor of Ball Class
*/
public CBall() {
m_radius = 0;
m_weight = 0;
m_rotationSpeed = 0;
}
public CBall(int radius, int weight) {
m_radius = radius;
m_weight = weight;
m_rotationSpeed = 0;
}
/**
* DEBUG: calculate & set the Rotation Speed of the Ball
*/
public void computeRotationSpeed(int rotationPowerLevel) {
//accrding to player’s rotation power level, compared to the properties of Ball Class,
//calculate the rotation speed of the ball //Milo
m_rotationSpeed = rotationPowerLevel;
}
// ************************************************************
/**
* Get the ball status info. <p>
* BallSpinDirection depends on No.14th, 15th bits of ballStatus<p>
* BallType depends on No.12th,13th bits of ballStatusInfo<p>
* BallStartAngle depends on No. 4-11th bits<p>
* And ballRollingDegree depends on No. 0-3th bits.
* If ballSpinDirection == 0 means clockwise, otherwise anti-clockwise.
*
* @param ballStatusInfo Status word of ball
*/
public void setBallType(int ballStatusInfo) {
// get the ball type value
m_ballCurveType = (ballStatusInfo & 0x000000c0) >> 6;
// get the ball spin direction
m_ballRotationDirection = (ballStatusInfo & 0x00000020) >> 5;
// get the ball rolling degree
m_ballRollingDegree = (ballStatusInfo & 0x0000001f);
switch (m_ballCurveType) {
case LINEAR_BALL:
case SAUCER_BALL: {
m_ballLAccelerationX = 0;
m_ballLAccelerationY = 0;
m_ballUAccelerationX = 0;
m_ballUAccelerationY = 0;
}
break;
case CURVE_BALL: {
if (m_ballRotationDirection == 0) {
m_ballLAccelerationX = def.sqrt(m_ballRollingDegree) *
CScene.LFRICTION_MODULUS;
m_ballLAccelerationY = 0;
m_ballUAccelerationX = def.sqrt(m_ballRollingDegree) *
CScene.UFRICTION_MODULUS;
m_ballUAccelerationY = 0;
}
else {
m_ballLAccelerationX = - (def.sqrt(m_ballRollingDegree) *
CScene.LFRICTION_MODULUS);
m_ballLAccelerationY = 0;
m_ballUAccelerationX = - (def.sqrt(m_ballRollingDegree) *
CScene.UFRICTION_MODULUS);
m_ballUAccelerationY = 0;
}
break;
}
default:
break;
}
}
public boolean isIntoBallOutSide() {
if (m_ballState == BALL_ONLANE &&
(m_currentBallPosition[0] < 0 || m_currentBallPosition[0] > def.LANE_WIDTH) &&
!isIntoBallInvalid()) {
return true;
}
return false;
}
public void intoBallOutSide() {
m_ballState = BALL_OUTSIDE;
m_ballVelocityX = 0;
if (m_currentBallPosition[0] < 0) {
m_currentBallPosition[0] = -def.DEFAULT_BALL_RADIUS; //what's the 13? Milo 09-23
}
else {
m_currentBallPosition[0] = def.LANE_WIDTH + def.DEFAULT_BALL_RADIUS;//what's the 13? Milo 09-23
}
}
public boolean isIntoBallInvalid() {
if (m_ballState != BALL_INVALID &&
(m_currentBallPosition[1] < 0 ||
m_currentBallPosition[1] > def.LANE_LENGTH + def.LANE_WIDTH ||
(m_ballVelocityX == 0 && m_ballVelocityY == 0))) {
return true;
}
return false;
}
public void initBall(){
m_currentBallPosition[0] = 0;
m_currentBallPosition[1] = 0;
m_currentBallPosition[2] = 0;
m_ballRollingArray[0] = 0;
m_ballRollingArray[1] = 0;
m_ballRollingArray[2] = 0;
m_ballVelocityX = 0;
m_ballVelocityY = 0;
m_ballGutterVelocity = 0;
m_ballLAccelerationX = 0;
m_ballLAccelerationY = 0;
m_ballUAccelerationX = 0;
m_ballUAccelerationY = 0;
m_ballState = BALL_INVALID;
m_ballCurveType = LINEAR_BALL;
m_ballRotationDirection = 0;
m_ballRollingDegree = 0;
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -