#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    65
    Rep Power
    2

    2d array collision


    collision between player and ground
    Code:
    public void levelWCollision(Player p)
    	{
    	for(int i = 0; i < rect.size(); i++)
    {
          if(p.getBounds().intersects(this.rect.get(i))){
               flag = true;
              break;
          }
        else
           flag = false;
    }
    }
    	System.out.println(flag);
    if(flag )
       System.out.println("hi");
    else
    System.out.println("bye");
    
    }
    now flag prints:
    true
    false
    false
    false
    ...

    it should prints true, true, true, true, true, bc player is touching the ground rect from arraylist.
    Last edited by game2d; May 10th, 2013 at 01:16 AM.

IMN logo majestic logo threadwatch logo seochat tools logo