?? footballclass.java
字號(hào):
break;
case 4:
this.strikeNext_Four(SpriteElse);
System.out.println("頭部碰撞");
break;
}
return true;
}
else
{
if(this.Football_X<10+this.Football.getWidth()/2){
this.strikeNext_One();
System.out.println("左側(cè)碰撞");
return true;
}else
if(this.Football_X > this.footballGameGanvas.getmyWidth()-10-this.Football.getWidth()/2){
this.strikeNext_Two();
System.out.println("右側(cè)碰撞");
return true;
}
}
return false;
}
//檢測(cè)到與天花板碰撞后的效果
public void strikeNext_Zero(){
this.NextFootball_X = 2* this.Football_X - this.PreFootball_X;
this.NextFootball_Y = this.PreFootball_Y;
}
//如果檢測(cè)到碰撞,并且類項(xiàng)為1,左側(cè)碰撞,則調(diào)用這個(gè)函數(shù)
public void strikeNext_One(){
this.NextFootball_X = this.PreFootball_X;
this.NextFootball_Y = 2*this.Football_Y - this.PreFootball_Y;
this.Football_distance_X = -this.Football_distance_X;
}
//如果檢測(cè)到碰撞,并且類項(xiàng)為2,右側(cè)碰撞,則調(diào)用這個(gè)函數(shù)
public void strikeNext_Two(){
this.NextFootball_X = this.PreFootball_X;
this.NextFootball_Y = 2*this.Football_Y - this.PreFootball_Y;
this.Football_distance_X = -this.Football_distance_X;
}
//如果檢測(cè)到碰撞,并且類項(xiàng)為3,地板碰撞,游戲結(jié)束,則調(diào)用這個(gè)函數(shù)
public void strikeNext_Three(){
//進(jìn)行地面摩擦的計(jì)算,因?yàn)榈孛婺Σ粒率筙方向的速度減少
if(this.Football_distance_X > GROUNDFORCE){
this.Football_distance_X -= GROUNDFORCE;
}else
if(this.Football_distance_X < -GROUNDFORCE){
this.Football_distance_X +=GROUNDFORCE;
}
//計(jì)算下一幀的對(duì)齊點(diǎn)坐標(biāo)
this.NextFootball_X = this.Football_X + this.Football_distance_X;
this.NextFootball_Y = this.PreFootball_Y;
//this.state = false;
}
public void setForce(float Force){
this.Force = Force;
}
//如果檢測(cè)到碰撞,并且類項(xiàng)為4,頭部碰撞,則調(diào)用這個(gè)函數(shù)
public void strikeNext_Four(Sprite SpriteElse){
//獲取人的對(duì)齊點(diǎn)坐標(biāo)
float TempX = SpriteElse.getRefPixelX();
float TempY = SpriteElse.getRefPixelY();
//判斷碰撞的大體位置,并根據(jù)大體位置求出反彈方向
if(TempX > this.Football_X-this.Football.getWidth()/6 && TempX < this.Football_X+this.Football.getWidth()/6)
this.Football_distance_X = -this.Football_distance_X;
else
if(TempX <= this.Football_X -this.Football.getWidth()/6 && TempX >this.Football_X-this.Football.getWidth()){
if(this.Football_distance_X>0){
this.Football_distance_X = MAXX/2;
}else
this.Football_distance_X = -this.Football_distance_X+MINX;
}else
if(TempX >= this.Football_X +this.Football.getWidth()/6 && TempX < this.Football_X + this.Football.getWidth()){
if(this.Football_distance_X<0){
this.Football_distance_X = -MAXX/2;
}else
this.Football_distance_X = -this.Football_distance_X-MINX;
}else
if(TempX < this.Football_X ){
// if(this.Football_distance_X > 0){
this.Football_distance_X = MAXX;
//
// if(this.Football_distance_X < -MAXX){
// this.Football_distance_X = -MAXX;
// }
}else
{this.Football_distance_X = -MAXX;
// if(this.Football_distance_X < 0){
// this.Football_distance_X = -this.Football_distance_X;
// }else
// this.Football_distance_X += MINX;
// System.out.println("+++++++++++");
// if(this.Football_distance_X > MAXX){
// this.Football_distance_X = MAXX;
// }
}
if(this.Football_distance_X < -MAXX){
this.Football_distance_X = -MAXX;
}
if(this.Football_distance_X > MAXX){
this.Football_distance_X = MAXX;
}
//求碰撞后的下一幀的點(diǎn)
this.NextFootball_Y = this.PreFootball_Y - this.Force;
this.NextFootball_X = this.Football_X + this.Football_distance_X;
this.Football_distanceR_Y = this.Football_diatanceR_Y_;
}
// public void strikeNext_Four(Sprite SpriteElse){
//
// float TempX = SpriteElse.getRefPixelX();
// float TempY = SpriteElse.getRefPixelY();
// float TempRadian0;
// float TempRadian1;
// float TempRadian2;
// float TempLenth;
// float Temp_XLenth;
// if(TempY < this.Football_Y && TempY < this.PreFootball_Y){
// TempRadian0 = (this.Football_Y - this.PreFootball_Y )/(this.PreFootball_X - this.Football_X);
// TempRadian1 = (TempY - this.Football_Y)/(this.Football_X - TempX);
// TempRadian2 = 2*TempRadian1 - TempRadian0;
// TempLenth = (float)Math.sqrt((this.PreFootball_X-this.Football_X)*(this.PreFootball_X-this.Football_X)+
// (this.PreFootball_Y-this.Football_Y)*(this.PreFootball_Y-this.Football_Y));
// Temp_XLenth = (float)this.mathComputeCos(TempRadian2)*TempLenth;
// this.NextFootball_X = (this.Force)*(this.Football_X + Temp_XLenth)/5;
// this.NextFootball_Y = (this.Force)*(this.Football_Y-(float)Math.sqrt(TempLenth*TempLenth - Temp_XLenth*Temp_XLenth))/5;
//
// }
// /*if(this.Direction_X){ //向左運(yùn)動(dòng)
// if((this.Football_X-TempX)/(2*this.Football_R) < 0.5){
// this.NextFootball_X = 2* this.Football_X - this.PreFootball_X;
// this.NextFootball_Y = this.Football_Y;
// }else{
// if(this.Football_X-TempX)/(2*this.Football_R) > 0.85){
//
// }
// this.NextFootball_X =
// }
// }*/
// }
/*public static int sqrt2(int i) {
int k = i / 2;
int last = 0;
while (Math.abs(k*k-i)>1 && last != k) {
last = k;
k = (k + i/k)/2;
}
return k;
}*/
//
// public double mathComputeCos(float radian){
// if(radian < 0.52){
// return 0.933;
// }else if(radian < 0.785 || radian > 5.500){
// return 0.800;
// }else if(radian < 1.047 || radian > 5.237){
// return 0.600;
// }else if(radian < 1.571 || radian > 4.713){
// return 0.300;
// }else if(radian < 2.094 || radian > 4.190){
// return -0.300;
// }else if(radian < 2.356 || radian > 3.928){
// return -0.600;
// }else if(radian < 2.618 || radian > 3.666){
// return -0.800;
// }else if(radian <= 3.142 || radian > 3.142){
// return -0.933;
// }else
// return 0.000;
// }
// //只計(jì)算0-3.14弧度的反正玄,使用前一定要檢測(cè)弧度范圍
// public double mathComputeATan(float value){
// if(value < -1.732){
// return 1.833;
// }else if(value < -1.000){
// return 2.225;
// }else if(value < -0.577){
// return 2.487;
// }else if(value < 0.000){
// return 2.880;
// }else if(value > 1.732){
// return 1.309;
// }else if(value > 1.000){
// return 0.916;
// }else if(value > 0.577){
// return 0.654;
// }else if(value >= 0.00){
// return 0.262;
// }else
// return 0.000;
// }
//
//
// //用于檢測(cè)下一步的球心是否躍過(guò)屏幕的最高處,如果躍出,就隱藏football,并進(jìn)行特殊的處理,直到足球的y點(diǎn)重新大于0
// public void isHigh(){
//
// }
//
//
// //以下為測(cè)試函數(shù)
// private int a=0;
// private int b=0;
// public void test(){
// this.Football.setRefPixelPosition(a,b);
// a++;
// b++;
// }
}
?? 快捷鍵說(shuō)明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -