⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 footballclass.java

📁 netbean下开发的
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
                    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("左侧碰撞");
                    return true;
            }else
                if(this.Football_X > this.footballGameGanvas.getmyWidth()-10-this.Football.getWidth()/2){
                    this.strikeNext_Two();
                    System.out.println("右侧碰撞");
                    return true;
                }
        }
        return false;
    }

    //检测到与天花板碰撞后的效果
    public void strikeNext_Zero(){
        this.NextFootball_X = 2* this.Football_X - this.PreFootball_X;
        this.NextFootball_Y = this.PreFootball_Y;
    }
    
    //如果检测到碰撞,并且类项为1,左侧碰撞,则调用这个函数
    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;
    }
    
    //如果检测到碰撞,并且类项为2,右侧碰撞,则调用这个函数
    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;
    }
    
    //如果检测到碰撞,并且类项为3,地板碰撞,游戏结束,则调用这个函数
    public void strikeNext_Three(){
        //进行地面摩擦的计算,因为地面摩擦,致使X方向的速度减少
        if(this.Football_distance_X > GROUNDFORCE){
            this.Football_distance_X -= GROUNDFORCE;
        }else
            if(this.Football_distance_X < -GROUNDFORCE){
            this.Football_distance_X +=GROUNDFORCE; 
            }
        //计算下一帧的对齐点坐标
        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;
    }
    //如果检测到碰撞,并且类项为4,头部碰撞,则调用这个函数
    public void strikeNext_Four(Sprite SpriteElse){
        //获取人的对齐点坐标
        float TempX = SpriteElse.getRefPixelX();
        float TempY = SpriteElse.getRefPixelY();
        //判断碰撞的大体位置,并根据大体位置求出反弹方向

        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;
                } 

        //求碰撞后的下一帧的点
        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){   //向左运动
//            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;
//    }
//    //只计算0-3.14弧度的反正玄,使用前一定要检测弧度范围
//    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;
//    }
//
//    
//    //用于检测下一步的球心是否跃过屏幕的最高处,如果跃出,就隐藏football,并进行特殊的处理,直到足球的y点重新大于0
//    public void isHigh(){
//        
//    }
//    
//    
//    //以下为测试函数
//    private int a=0;
//    private int b=0;
//    public void test(){
//                this.Football.setRefPixelPosition(a,b);
//        a++;
//        b++;
//    }


}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -