📄 cscene.java
字号:
switch (roundStage) {
case CGamePlay.ROUND_INIT:
//setStandingStatusForRender();
//renderInitScene(); //09-10 by Milo
m_render3D.m_eye[0] = m_defEyePos[0];
m_render3D.m_eye[1] = m_defEyePos[1];
m_render3D.m_eye[2] = m_defEyePos[2];
m_render3D.m_lookat[0] = m_defEyeLookAt[0];
m_render3D.m_lookat[1] = m_defEyeLookAt[1];
m_render3D.m_lookat[2] = m_defEyeLookAt[2];
m_render3D.UpdateCamera();
break;
case CGamePlay.PLAYER_POSITION_CONFIRM:
renderInitScene();
m_render3D.RenderModel(3, 0, 0, m_playerPosition, m_playerRotation);
break;
case CGamePlay.CAMERA_MOVEIN_ANIM:
m_render3D.m_eye[1] += 5;
m_render3D.m_eye[2] -= 1;
m_render3D.m_lookat[2] += 1;
m_render3D.UpdateCamera();
renderInitScene();
if (m_playerPosition[1] - m_render3D.m_eye[1] > 20)
m_render3D.RenderModel(3, 0, 0, m_playerPosition, m_playerRotation);
if (m_render3D.m_lookat[2] >= 0) {
m_ancPos = 0;
return 1;
}
break;
case CGamePlay.AIM_SPOT_CONFIRM:
renderInitScene();
m_ancPos += 6;
if (m_ancPos >= 180)
m_ancPos = 0;
if (m_ancPos >= 90)
m_ancBase[0] = 135 - m_ancPos;
else
m_ancBase[0] = m_ancPos - 45;
m_render3D.RenderModel(1, 0, 0, m_ancBase, m_ancRot); //changed by Milo 09-10 4
break;
case CGamePlay.PLAYER_POWER_CONFIRM:
renderInitScene();
m_render3D.RenderModel(1, 0, 0, m_ancBase, m_ancRot); //changed by Milo 09-10 4
break;
case CGamePlay.PLAYER_ACCURACY_CONFIRM:
renderInitScene();
m_render3D.RenderModel(1, 0, 0, m_ancBase, m_ancRot); //changed by Milo 09-10 4
break;
case CGamePlay.CAMERA_MOVEOUT_ANIM:
m_render3D.m_eye[1] -= 5;
m_render3D.UpdateCamera();
renderInitScene();
if (m_playerPosition[1] - m_render3D.m_eye[1] > 20)
m_render3D.RenderModel(3, 0, 0, m_playerPosition, m_playerRotation);
if (m_render3D.m_eye[1] <= -400)
return 1;
break;
case CGamePlay.ROTATION_POWER_CONFIRM:
renderInitScene();
m_render3D.RenderModel(3, 0, m_frameIndex, m_playerPosition,
m_playerRotation);
m_frameIndex += 3;
if (m_frameIndex >= m_frameCount) {
m_frameIndex = 0;
return 1;
}
break;
case CGamePlay.BALL_RUNNING:
setCamera(true);
renderRunningScene();
break;
case CGamePlay.ROUND_FINISH:
setCamera(false);
renderFinishingScene();
break;
case CGamePlay.MATCH_FINISH:
renderFinishingScene();
}
return 0;
}
/**
* Update camera pos and direction according to game status
*/
public void UpdateCamera() {
m_render3D.UpdateCamera(); //Milo;forRender3D
}
/**
* init()
*/
public void init() {
m_render3D = new CRender3D(); //Milo;forRender3D
m_render3D.SetupEnv(); //Milo;forRender3D
//m_render2D = new CRender2D(); //Milo;forRende2D
// m_render2D.loadData();
initBallInScene();
m_time = 0;
m_firstCollision = false;
m_hasBeenCollided = false;
m_bMovementFinished = false;
m_isInTenpinArea = false;
m_player = new CPlayer(); // Milo call different constructor
m_player.m_strength = CPlayer.MAX_PLAYER_STRENGTH;
m_player.m_rotation = CPlayer.MAX_PLAYER_ROTATION;
m_playerPosition[0] = def.PLAYER_POSITION_X;
m_playerPosition[1] = def.PLAYER_POSITION_Y;
m_playerPosition[2] = 0;
m_playerRotation[0] = def.PLAYER_ROTATION_X;
m_playerRotation[1] = def.PLAYER_ROTATION_Y;
m_playerRotation[2] = def.PLAYER_ROTATION_Z;
try {
for (int i = 0; i < 10; ++i) {
m_tenpin[i] = new CTenpin();
m_tenpin[i].init();
m_tenpin[i].m_tenpinID = i;
}
}
catch (Exception e) {
e.printStackTrace();
System.out.println(e.getMessage());
}
m_nFrame = 0;
setTenpinLandingPosition();
m_accelerationFalling = ACCELERATION_FALLING;
m_anglePerframe = ANGLE_PERFRAME;
m_isSwitch = true;
}
private void initBallInScene() {
m_ball = new CBall(def.DEFAULT_BALL_RADIUS, def.DEFAULT_BALL_WEIGHT);
/*m_currentBallPositionX = 0;
m_currentBallPositionY = 0;
m_currentBallPositionZ = 0;*/
/*for (int i = 0; i < 3; ++i) {
m_ball.m_currentBallPosition[i] = 0;
}*/
m_ballDestinationPositionX = 0;
m_ballDestinationPositionY = 0;
m_ball.initBall();
/* m_ball.m_ballVelocityX = 0;
m_ball.m_ballVelocityY = 0;
m_ball.m_ballGutterVelocity = 0;
m_ball.m_ballLAccelerationX = 0;
m_ball.m_ballLAccelerationY = 0;
m_ball.m_ballUAccelerationX = 0;#
m_ball.m_ballUAccelerationY = 0;
m_ball.m_ballState = CBall.BALL_INVALID;
m_ball.m_ballCurveType = CBall.LINEAR_BALL;
m_ball.m_ballRotationDirection = 0;
m_ball.m_ballRollingDegree = 0;*/
}
/**
* return the Ball instance
*/
public CBall getBall() {
return m_ball;
}
/**
* return the Tenpin group instance
*/
public CTenpin[] getTenpin() {
return m_tenpin;
}
public int getTenpinState() {
int ret = 0;
int m = 0x0001;
for (int i = 0; i < 10; ++i) {
if (m_tenpin[i].m_tenpinState == CTenpin.TENPIN_STATE_STAND) {
ret += (m << i);
m = 0x0001;
}
}
return ret;
}
private int getFirstStandingTenpinID() {
int ret = -1;
for (int i = 0; i < 10; ++i) {
if (m_tenpin[i].m_tenpinState == CTenpin.TENPIN_STATE_STAND) {
ret = i;
break;
}
}
return ret;
}
public int[] getDestinationPosition(int aimSpot) {
int[] ret = {
-1, -1, -1};
int tenpinPositionX;
int step = def.LANE_WIDTH;
int record = -1; //default tenpin for shoting is the 6th tenpin
try {
for (int i = 0; i < 10; ++i) {
tenpinPositionX = m_tenpin[i].m_tenpinPosition[0];
if (aimSpot < 40 && aimSpot > 15) {
if (step > (aimSpot * def.DEFAULT_EXTEND) - tenpinPositionX
&& (aimSpot * def.DEFAULT_EXTEND - tenpinPositionX) > 0) {
step = (aimSpot * def.DEFAULT_EXTEND) - tenpinPositionX;
record = i;
}
}
else if (aimSpot > 40 && aimSpot < 75) {
if (step > tenpinPositionX - (aimSpot * def.DEFAULT_EXTEND)
&& (tenpinPositionX - aimSpot * def.DEFAULT_EXTEND) > 0) {
step = tenpinPositionX - (aimSpot * def.DEFAULT_EXTEND);
record = i;
}
}
//ret = m_tenpin[record].m_tenpinPosition; //EXCEPTION WHEN ALL TENPIN FALL ???Milo
//System.out.println("the nearest tenpin Position:" + ret[0]
//+ " " + ret[1] + " " + ret[2]);
}
//if (record == -1 && aimSpot <= 45){
//m_tenpin[6].m_tenpinPosition; //EXCEPTION WHEN ALL TENPIN FALL ???Milo
//}
if (record == -1 && aimSpot > 45)
for (int i = 0; i < 3; ++i)
ret[i] = -2; //m_tenpin[9].m_tenpinPosition; //EXCEPTION WHEN ALL TENPIN FALL ???Milo
if (record != -1)
ret = m_tenpinLandingPosition[record]; //EXCEPTION WHEN ALL TENPIN FALL ???Milo
}
catch (Exception ex) {
System.out.println(ex.toString());
}
return ret;
}
/**
* DEBUG: set the init status when ball was thrown
*/
public void setInitBallState(int playerPower, int aimSpot,
int playerPositionX) {
m_time = (def.BALL_MOVMENT_FASTEST_TIME - (playerPower)
* def.BALL_MOVMENT_TIME_MODIFICATION); //???Milo / def.DEFAULT_EXTEND
System.out.println("time is:" + m_time);
//m_ball.computeRotationSpeed(rotationPower); //???Milo useless???
m_ball.m_currentBallPosition[0] = (playerPositionX * def.DEFAULT_EXTEND +
def.LANE_WIDTH / 2);
m_ball.m_currentBallPosition[1] = 0;
m_ball.m_currentBallPosition[2] = def.DEFAULT_BALL_RADIUS;
int destinationPosition[] = new int[3]; //X,Y,Z axis
destinationPosition = getDestinationPosition(aimSpot);
if (destinationPosition[0] == -1 && destinationPosition[1] == -1 &&//Milo 09-23
destinationPosition[2] == -1) {
m_ballDestinationPositionX = (20 - aimSpot)* def.DEFAULT_EXTEND;
m_ballDestinationPositionY = def.LANE_LENGTH;
}
else if (destinationPosition[0] == -2 && destinationPosition[1] == -2 &&
destinationPosition[2] == -2) {
m_ballDestinationPositionX = def.LANE_WIDTH + ((aimSpot - 65)* def.DEFAULT_EXTEND);//;
m_ballDestinationPositionY = def.LANE_LENGTH;
}
else {
m_ballDestinationPositionX = destinationPosition[0];
m_ballDestinationPositionY = destinationPosition[1];
}
m_ball.m_ballVelocityX = (m_ballDestinationPositionX -
m_ball.m_currentBallPosition[0])
/ (m_time);
m_ball.m_ballVelocityY = ( (m_ballDestinationPositionY -
m_ball.m_currentBallPosition[1]))
/ (m_time); //0.1s & * def.DEFAULT_EXEND
m_ball.m_ballGutterVelocity = m_ball.m_ballVelocityY * GUTTER_REDUCTION
/ def.DEFAULT_EXTEND;
m_ball.m_ballState = CBall.BALL_ONLANE;
System.out.println("the startBallosition is:"
+ m_ball.m_currentBallPosition[0] + " "
+ m_ball.m_currentBallPosition[1]);
}
public void step(boolean isSlowAction) {
try {
if (isSlowAction == true && m_isSwitch == true) {
m_accelerationFalling = ACCELERATION_FALLING / SLOW_ACTION_GRADE;
m_anglePerframe = ANGLE_PERFRAME / SLOW_ACTION_GRADE;
/*for (int i = 0; i < 10; ++i) {
for (int j = 0; j < 2; ++j) {
// m_tempTenpinVelocity[i][j] = m_tenpin[i].m_tenpinVelocity[j];
m_tenpin[i].m_tenpinVelocity[j] = m_tenpin[i].m_tenpinVelocity[j] /
SLOW_ACTION_GRADE;
}
}
//m_tempBallVelocity[0] = m_ball.m_ballVelocityX;
m_ball.m_ballVelocityX = m_ball.m_ballVelocityX / SLOW_ACTION_GRADE;
// m_tempBallVelocity[1] = m_ball.m_ballVelocityY;
m_ball.m_ballVelocityY = m_ball.m_ballVelocityY / SLOW_ACTION_GRADE;*/
m_isSwitch = false;
}
else{
if (m_isSwitch == true){
m_accelerationFalling = ACCELERATION_FALLING ;
m_anglePerframe = ANGLE_PERFRAME;
/*for (int i = 0; i < 10; ++i) {
for (int j = 0; j < 2; ++j) {
//m_tempTenpinVelocity[i][j] = m_tenpin[i].m_tenpinVelocity[j];
m_tenpin[i].m_tenpinVelocity[j] = m_tenpin[i].m_tenpinVelocity[j] *
SLOW_ACTION_GRADE;
}
}
// m_tempBallVelocity[0] = m_ball.m_ballVelocityX;
m_ball.m_ballVelocityX = m_ball.m_ballVelocityX * SLOW_ACTION_GRADE;
//m_tempBallVelocity[1] = m_ball.m_ballVelocityY;
m_ball.m_ballVelocityY = m_ball.m_ballVelocityY * SLOW_ACTION_GRADE;
m_isSwitch = false;*/
}
}
if (m_bMovementFinished == false) { //m_ballState != BALL_INVALID) {
if (!m_isInTenpinArea) {
ballOnTrack();
m_nFrame++; //added by Milo 09-22
if (m_ball.m_currentBallPosition[1]
+ m_ball.m_ballVelocityY > def.LANE_LENGTH) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -