2013-12-17 4 views
0

Итак, это то, что происходит. Игра продолжает останавливаться, потому что два круга сталкиваются друг с другом, я пытаюсь предотвратить это, убедившись, что идентификатор - это квадрат ID, и я стараюсь, чтобы круги столкнулись друг с другом и просто игнорируйте столкновения, но это не делает этого, и я не знаю, как именно остановить это от столкновения друг с другом и только позволить ему столкнуться с квадратом.Столкновение со спрайтами

В основном я хочу, чтобы круг не сталкивался с другим кругом и позволял ему сталкиваться с квадратом.

Любая помощь будет большим спасибо

game.engine.engine класс

//collision detection class 
    iter = p_group.listIterator(); 
     Sprite spr = null; 
     while (iter.hasNext()) { 
      spr = (Sprite)iter.next(); 

      //remove from list if flagged 
      if (!spr.getAlive()) { 
       iter.remove(); 
       continue; 
      } 

      //is collision enabled for this sprite? 
      if (spr.getCollidable()) { 

       //has this sprite collided with anything? 
       if (spr.getCollided()) { 

        //is the target a valid object? 
        if (spr.getOffender() != null) { 

         /* 
         * External func call: notify game of collision 
         * (with validated offender) 
         */ 
         collision(spr); 

         //reset offender 
         spr.setOffender(null); 
        } 

        //reset collided state 
        spr.setCollided(false); 

       } 
      } 
     } 

это где я проверить столкновения в классе игры, который проходит пакет game.engine.engine.

Game Class

  // all the circles were are set up the same, theres four 
      // circletopleft, circletopright, circlebottomleft 
      // circle bottom left collides with circle top right 
      // theres no diffence between the code of the circles they are all the same 
     /*ball*/circleBottomLeft.setCollidable(true); 
       circleBottomLeft.setIdentifier(CIRCLEID_3); 
        addToGroup(circleBottomLeft); 


        //init ball sprite 
       circleBottomRight.position = new Float2(550, h-550); 
       circleBottomRight.setVelocity(new Float2(10.0f, -9.0f)); 

        //keep ball inside secreen boundary 
       Point size4 = circleBottomRight.getSize(); 
       circleBottomRight.addAnimation(new ReboundBehavior(new RectF 
        (0 , 0 , w-size4.x, h-size4.y),size4,circleBottomRight.getVelocity())); 

     /*ball*/circleBottomRight.setCollidable(true); 
       circleBottomRight.setIdentifier(CIRCLEID_4); 
        addToGroup(circleBottomRight); 


} 


     //collision class extended from game.engine.Engine 
    public void collision(Sprite sprite) { 
    // TODO Auto-generated method stub 
    final int oneMin = 60; 
    final int twoMin = 120; 
    final int threeMin = 180; 
    final int fourMin = 240; 
    final int fiveMin = 300; 
    Sprite other = sprite.getOffender(); 
    Float2 vel = sprite.getVelocity(); 

    switch (sprite.getIdentifier()) { 
    case CIRCLEID_1:  

    vel = sprite.getVelocity(); 
    other.position.y += 1; 
    case CIRCLEID_2: 

     vel = sprite.getVelocity(); 
     other.position.y += 1; 
    case CIRCLEID_3:  
     vel = sprite.getVelocity(); 
     other.position.y += 1; 
    case CIRCLEID_4:  
     vel = sprite.getVelocity(); 
     other.position.y += 1; 

     break; 
    } 

    switch (other.getIdentifier()) { 

    case oneMin: 
     if (this.getElapsedTime() == oneMin) { 

      vel.y = -1; 
      sprite.setVelocity(vel); 
      sprite.position.y += vel.y*2; 

     } 
     break; 
    case twoMin: 
     if (this.getElapsedTime() == twoMin) { 
      vel.y = -1; 
      sprite.setVelocity(vel); 
      sprite.position.y += vel.y*2; 

     } 
     break; 
    case threeMin: 
     if (this.getElapsedTime() == threeMin) { 
      vel.y = -1; 
      sprite.setVelocity(vel); 
      sprite.position.y += vel.y*2; 

     } 
     break; 
    case fourMin: 
     if (this.getElapsedTime() == fourMin) { 
      vel.y = -1; 
      sprite.setVelocity(vel); 
      sprite.position.y += vel.y*2; 

     } 
     break; 
    case fiveMin: 
     if (this.getElapsedTime() == fiveMin) { 
      vel.y = -1; 
      sprite.setVelocity(vel); 
      sprite.position.y += vel.y*2; 

     } 
     break; 

     case SQUARE_ID: 
      //make sure its not touched 
      if (other.getIdentifier() == SQUARE_ID && 
       other.getIdentifier() == CIRCLEID_1 || 
      other.getIdentifier() == CIRCLEID_2 || 
      other.getIdentifier() == CIRCLEID_3 || 
      other.getIdentifier() == CIRCLEID_4) { 
       stop(); 
       Log.d("Game", "Collided, I collided with something"); 
       if (p_paused) { 
        Message msg = handler.obtainMessage(); 
        msg.arg1 = 1; 
        handler.sendMessage(msg); 

он держит остановки, когда сверху два круга сталкивается (417 секунд в игру Theres столкновения, и оно не прикасаться к площади. Это происходит именно тогда, когда круг нижнего левого сталкиваетса с окружностью верхней правой

ответ

0
if (other.getCollided() == true && circleTopLeft.getCollided()  == true || 
      other.getCollided() == true && circleTopRight.getCollided() == true || 
      other.getCollided() == true && circleBottomRight.getCollided() == true || 
      other.getCollided() == true && circleBottomLeft.getCollided() == true) { 

, позвонив, что я был в состоянии проверить столкновения правильно.

Смежные вопросы