📄 cscene.java
字号:
m_isInTenpinArea = true;
m_nFrame = 0; //added by Milo 09-22
}
}
else {
System.out.println("BEFORE COLLISION");
onCollision();
m_nFrame++;
System.out.println("AFTER COLLISION" + m_nFrame);
}
if (m_ball.isIntoBallOutSide()) {
m_ball.intoBallOutSide();
}
if (m_ball.isIntoBallInvalid()) {
m_ball.m_ballState = CBall.BALL_INVALID;
}
if (m_ball.m_ballState == CBall.BALL_INVALID && isNoPinMoving()) {
m_bMovementFinished = true;
System.out.println("AFTER MOVEMENT");
for (int i = 0; i < 10; ++i)
System.out.println("****************************tenpinStatus++" + i +
"is: " + m_tenpin[i].m_tenpinState);
}
System.out.println("****************************Total frames is: " +
m_nFrame);
}
}
catch (Exception ex) {
System.out.println(ex.toString());
}
}
private void ballOnTrack() {
switch (m_ball.m_ballState) {
case CBall.BALL_ONLANE: {
if (m_ball.m_currentBallPosition[1] <
(HEAVY_OIL_AREA)) { // + LIGHT_OIL_AREA / 3)) {
/*if (isWeakBall) {
if (ballCurrPositionX <=
Constant.WEAKBALL_LEFT_FIRST_AREA * SIZE_EXTENDED)
ballCurrPositionX += ballVelocityX -
Constant.DELTA_1 * positionModification / SIZE_EXTENDED;
else if (ballCurrPositionX >
Constant.WEAKBALL_LEFT_FIRST_AREA * SIZE_EXTENDED &&
ballCurrPositionX <=
Constant.WEAKBALL_LEFT_SECOND_AREA * SIZE_EXTENDED)
ballCurrPositionX += ballVelocityX -
Constant.DELTA_2 * positionModification / SIZE_EXTENDED;
else if (ballCurrPositionX >=
Constant.WEAKBALL_RIGHT_FIRST_AREA * SIZE_EXTENDED &&
ballCurrPositionX <=
Constant.WEAKBALL_RIGHT_SECOND_AREA * SIZE_EXTENDED)
ballCurrPositionX += ballVelocityX +
Constant.DELTA_2 * positionModification / SIZE_EXTENDED;
else if (ballCurrPositionX >
Constant.WEAKBALL_RIGHT_SECOND_AREA * SIZE_EXTENDED)
ballCurrPositionX += ballVelocityX +
Constant.DELTA_1 * positionModification / SIZE_EXTENDED;
else
ballCurrPositionX += ballVelocityX;
}
else*/
m_ball.m_currentBallPosition[0] += m_ball.m_ballVelocityX;
m_ball.m_currentBallPosition[1] += m_ball.m_ballVelocityY;
}
else {
/*if (bSpinSelect) {
bSpinSelect = false;
}*/
switch (m_ball.m_ballCurveType) {
case CBall.LINEAR_BALL:
case CBall.SAUCER_BALL: {
/*if (isWeakBall) {
if (ballCurrPositionX <=
Constant.WEAKBALL_LEFT_FIRST_AREA * SIZE_EXTENDED)
ballCurrPositionX += ballVelocityX -
Constant.DELTA_1 * positionModification / SIZE_EXTENDED;
else if (ballCurrPositionX >
Constant.WEAKBALL_LEFT_FIRST_AREA * SIZE_EXTENDED &&
ballCurrPositionX <=
Constant.WEAKBALL_LEFT_SECOND_AREA * SIZE_EXTENDED)
ballCurrPositionX += ballVelocityX -
Constant.DELTA_2 * positionModification / SIZE_EXTENDED;
else if (ballCurrPositionX >=
Constant.WEAKBALL_RIGHT_FIRST_AREA * SIZE_EXTENDED &&
ballCurrPositionX <=
Constant.WEAKBALL_RIGHT_SECOND_AREA * SIZE_EXTENDED)
ballCurrPositionX += ballVelocityX +
Constant.DELTA_2 * positionModification / SIZE_EXTENDED;
else if (ballCurrPositionX >
Constant.WEAKBALL_RIGHT_SECOND_AREA * SIZE_EXTENDED)
ballCurrPositionX += ballVelocityX +
Constant.DELTA_1 * positionModification / SIZE_EXTENDED;
else
ballCurrPositionX += ballVelocityX;
}
else*/
m_ball.m_currentBallPosition[0] += m_ball.m_ballVelocityX;
m_ball.m_currentBallPosition[1] += m_ball.m_ballVelocityY;
//System.out.println(" *************** ball moving position: " + ballCurrPositionX / SIZE_EXTENDED);
}
break;
case CBall.CURVE_BALL: {
if (m_ball.m_currentBallPosition[1] <= HEAVY_OIL_AREA) {
m_ball.m_currentBallPosition[1] += m_ball.m_ballVelocityY;
m_ball.m_currentBallPosition[0] += m_ball.m_ballVelocityX;
}
if ( (m_ball.m_currentBallPosition[1] > HEAVY_OIL_AREA)
&& (m_ball.m_currentBallPosition[1] <= LIGHT_OIL_AREA)) {
m_ball.m_currentBallPosition[1] += m_ball.m_ballVelocityY;
m_ball.m_currentBallPosition[0] += m_ball.m_ballVelocityX
+ (m_ball.m_ballLAccelerationX >> 1);
m_ball.m_ballVelocityX += m_ball.m_ballLAccelerationX;
}
if (m_ball.m_currentBallPosition[1] > LIGHT_OIL_AREA) {
m_ball.m_currentBallPosition[1] += m_ball.m_ballVelocityY;
m_ball.m_currentBallPosition[0] += m_ball.m_ballVelocityX
+ (m_ball.m_ballUAccelerationX >> 1);
m_ball.m_ballVelocityX += m_ball.m_ballUAccelerationX;
}
}
break;
}
}
break;
}
case CBall.BALL_OUTSIDE:
//bSpinSelect = false;
m_ball.m_currentBallPosition[1] += m_ball.m_ballGutterVelocity;
break;
}
}
// ************************************************************
/**
* Check each pin wheater collide with bowling ball
* First calculate currentposition of bowlin ball then
* check if it collided a pin, finally deal with each
* bowling pin according to its status
*/
private void onCollision() {
try {
int[] ps = new int[10];
for (int i = 0; i < 10; i++) {
ps[i] = m_tenpin[i].m_tenpinState; //pinStatus[i];
}
boolean[] is_Collisioned = new boolean[10];
for (int i = 0; i < 10; ++i)
is_Collisioned[i] = false;
for (int i = 0; i < 10; i++) {
if (ps[i] == CTenpin.TENPIN_STATE_MOVING && is_Collisioned[i] == false) {
boolean isPinCollision = false;
int j = whoIsNearest(i); //8/11
if (j >= 0) {
System.out.println(i + "| BEFORE PIN-COLLISION with | "
+ j);
isPinCollision = onTenpinCollision(i, j); //8/11
System.out.println("AFTER PIN-COLLISION");
}
if (!isPinCollision) {
//if (m_isAfterCollision == false){ //Milo 09-23
tenpinWithoutCollision(i); //09/02
//System.out.println("the PinCollisionTenpin ID is: " + i);
//}
//else{
// m_isAfterCollision = false;
//}
}
else {
//tenpinWithoutCollision(j); //09/07
tenpinWithoutCollision(i); //09/06 && 09-08 Milo
is_Collisioned[j] = true;
}
}
}
boolean isBallCollision = false;
m_firstCollision = false;
if (m_ball.m_ballState == CBall.BALL_ONLANE) {
for (int i = 0; i < 10; i++) {
if (m_tenpin[i].m_tenpinState == CTenpin.TENPIN_STATE_OUTSIDE) { //Milo
continue;
}
System.out.println( "| BEFORE BALL-COLLISION | ");
if (isBallCollision = onBallCollision(i)) { //
System.out.println( "| AFTTER BALL-COLLISION | ");
//System.out.println("the BallCollisionTenpin ID is: " + i);
//System.out.println("the CurrentBallPositionX is: " +
// m_currentBallPositionX);
if (isFirstCollision()) {
m_firstCollision = true;
m_hasBeenCollided = true;
}
else {
m_firstCollision = false;
}
break;
}
}
if (!isBallCollision) {
m_ball.m_currentBallPosition[0] += m_ball.m_ballVelocityX;
m_ball.m_currentBallPosition[1] += m_ball.m_ballVelocityY;
}
}
if (m_ball.m_ballState == CBall.BALL_OUTSIDE) {
m_ball.m_currentBallPosition[1] += m_ball.m_ballVelocityY; //???Milo Ball should be moved
}
}
catch (Exception ex) {
System.out.println(ex.toString());
}
}
/**
* who is the nearest living pin by pin k
* @param k the number of the pin
*
* @return who
* The nearest ball
*/
private int whoIsNearest(int k) {
try {
int dis = java.lang.Integer.MAX_VALUE;
int temp = 0;
int who = -1;
for (int i = 0; i < 10; i++) {
if (m_tenpin[i].m_tenpinState != CTenpin.TENPIN_STATE_OUTSIDE
&& k != i) {
//System.out.println("BEFORE distanceP2P" );
temp = def.distanceP2P(m_tenpin[i].m_tenpinPosition[0],
m_tenpin[i].m_tenpinPosition[1],
m_tenpin[k].m_tenpinPosition[0],
m_tenpin[k].m_tenpinPosition[1]);
//System.out.println("AFTER distanceP2P");
if (temp < dis) {
dis = temp;
who = i;
}
}
}
//System.out.println(" distanceP2P | dis = " + dis + " | who = " + who);
return who;
}
catch (Exception ex) {
System.out.println(ex.toString());
return -1;
}
}
// ************************************************************
/**
* Deal with pin1 collide with pin2
*
* @param pin1 to strike pin2
* @param pin2 to be stroke by pin1
* @return if pin1 collided with pin2 return true, else false.
*/
private boolean onTenpinCollision(int pin1, int pin2) {
boolean ret = false;
if (m_tenpin[pin1].m_tenpinState != CTenpin.TENPIN_STATE_MOVING
|| m_tenpin[pin2].m_tenpinState == CTenpin.TENPIN_STATE_OUTSIDE) {
return ret;
}
if (m_tenpin[pin2].m_tenpinState == CTenpin.TENPIN_STATE_STAND) { //!= moving
System.out.println("!!! BEFORE TENPIN COLLISION WITH STILL TENPIN ");
ret = isStillTenpinCollision(pin1, pin2);
System.out.println("TENPIN COLLISION WITH STILL TENPIN ");
}
else {
if (m_tenpin[pin2].m_tenpinState == CTenpin.TENPIN_STATE_DEAD){
System.out.println("!!! BEFORE TENPIN COLLISION WITH DEAD TENPIN ");
ret = isDeadTenpinCollision(pin1, pin2);
System.out.println("TENPIN COLLISION WITH DEAD TENPIN ");
}
else{
System.out.println("!!! BEFORE TENPIN COLLISION WITH MOVING TENPIN ");
ret = isMovingTenpinCollision(pin1, pin2);
System.out.println("TENPIN COLLISION WITH MOVING TENPIN ");
}
}
//add outside judging HERE
/* if(m_tenpin[pin1].m_tenpinPosition[0] < 0 || m_tenpin[pin1].m_tenpinPosition[0] > LANE_WIDTH){
m_tenpin[pin1].m_tenpinState = CTenpin.TENPIN_STATE_OUTSIDE;
}
if(m_tenpin[pin1].m_tenpinPosition[pin1] < 18000 * def.DEFAULT_EXTEND ||m_tenpin[pin1].m_tenpinPosition[0] > (LANE_LENGTH+300 * def.DEFAULT_EXTEND)){
m_tenpin[pin1].m_tenpinState = CTenpin.TENPIN_STATE_OUTSIDE;
}*/
return ret;
}
// ************************************************************
/**
* Test if one movement finished
*
* @return wheather one movement is finished
*/
public boolean isFinished() {
return m_bMovementFinished;
}
/**
* deal with such situation that two balls collided, one moving, the other still
*
* @param x the x weight of the vector which stands for that of the connected line between the centers of both balls
* @param y the y weight of the vector
* @param vx the velocity in x direction of the moving ball
* @param vy the velocity in y direction of the moving ball
* @param mm the mass of the moving ball
* @param ms the mass of the still ball
* @return int[4] v, v[0] and v[1] stand for the velocitys in x, y direction of the still ball after collision <p>
* v[2] and v[3] stand for the velocitys of the moving ball after collision
*/
private static int[] collisionTenpinWithStillTenpin(int x, int y, int vx, int vy,
int mm, int ms) {
int[] v = new int[4];
int angleC;
if (x != 0) {
angleC = def.atan(def.abs(def.VALUE_MULTIPLE_TEN * y / x));
angleC = def.convertInto360(x, y, angleC) - 900;
if (angleC < 0) {
angleC += 3600;
}
}
else {
angleC = y >= 0 ? 0 : 1800;
}
int angle = def.abs( (angleC / 900 % 2 == 0 ? 0 : 900) - angleC % 900);
int cos = def.cos(angle);
if (def.abs(angleC) > 900 && def.abs(angleC) < 2700) {
cos = -cos;
}
int sin = def.sin(angle);
if (def.abs(angleC) > 1800 && def.abs(angleC) < 3600) {
sin = -sin;
}
int cosX = vx > 0 ? cos : -cos;
int sinX = vx > 0 ? -sin : sin;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -