2008年2月26日碰撞算法

来源:互联网 发布:同济医学院知乎 编辑:程序博客网 时间:2024/06/13 09:58
  1. 修改了图片后,一定要刷新一下工程再运行。
  2. 碰撞算法
    public static boolean intersectRect(int r1x1, int r1y1, int r1x2, int r1y2,
    int r2x1, int r2y1, int r2x2, int r2y2) {
    return r2x1 < r1x2 && r2y1 < r1y2 && r2x2 > r1x1 && r2y2 > r1y1;
    }
    *   Detect   rectangle   intersection  
                *    
                *   @param   r1x1   left   co-ordinate   of   first   rectangle  
                *   @param   r1y1   top   co-ordinate   of   first   rectangle  
                *   @param   r1x2   right   co-ordinate   of   first   rectangle  
                *   @param   r1y2   bottom   co-ordinate   of   first   rectangle  
                *   @param   r2x1   left   co-ordinate   of   second   rectangle  
                *   @param   r2y1   top   co-ordinate   of   second   rectangle  
                *   @param   r2x2   right   co-ordinate   of   second   rectangle  
                *   @param   r2y2   bottom   co-ordinate   of   second   rectangle  
                *   @return   True   if   there   is   rectangle   intersection  
                */  
              private   boolean   intersectRect(int   r1x1,   int   r1y1,   int   r1x2,   int   r1y2,    
                                                                          int   r2x1,   int   r2y1,   int   r2x2,   int   r2y2)   {  
      if   (r2x1   >=   r1x2   ||   r2y1   >=   r1y2   ||   r2x2   <=   r1x1   ||   r2y2   <=   r1y1)   {  
              return   false;  
      }   else   {  
              return   true;  
      }  
    }
原创粉丝点击