COLLISIONS???? HELP ME PLEASE!!!!!!!

Ok here is all the collsion part of my game…hope someone can help.

Ok this is the main class where everything is controlled


class MyGame{
...
marioCharacter = new MainCharacter(.....some parameters...);
....
//here the background is controlled
bk_level_1 = new Scene(...some parameters...);

...
//test for collision between main character and a particular tile
public void collisionCheck(Scene _level,MainCharacter _char){
      if(_level.collisionTest(_char,173)){
            collision = true;
      }
      else {collision = false;}
}

....

}

This next class is one one for the maincharacter…I will just show how the bounding box is set up every cycle.


class MainCharacter{
...
public void updateBounds(){

      boundX = current_pos.x()+20;
      boundY = current_pos.y()+10;
      boundWidth = tileWidth-28;
      boundHeight = tileHeight-18;
      character_bounds.setRect(boundX,boundY,boundWidth,boundHeight);
}
...
}

The next class two classes are the Scene class and the tile class. The Tile class simple is each tile . here a bounding box is created round the tile.


class Tile{
...
public void updateBound(int x, int y){
         tile_bound.setRect(x,y,_width,_height);
}
...

}


class Scene{
...
public boolean collisionTest(MainCharacter _character,int tileNum){
      return _character.getCharacterBounds().intersects(bkCollection[tileNum].getBound());
}
...
}

ok most of it should be obvious, but it only detects some tiles.
can anyone help. thanks.
If you need anyother info then just ask.

Firstly, loose the caps :o

‘Only detects some tiles’ is pretty vauge. Try and narrow it down to something more specific. Your first test should probably be to draw all of your bounding boxes to test if they really are where you think they are.

The test between 2 bounding, axis aligned boxes should be trivial but theres plenty of references on the 'net if you look. More likely is MyGame::collisionCheck() method being the culprit. Are you just checking for a single hard-coded other object, or is there multiple ones in your level? If multiple, then make sure you’re checking all the tiles you’re overlapping with, not just the one you’re actually on. If theres just the single then definatly investigate your intersects() method in detail…

(oh, and whats with the _variables prefix? Looks like the old C style of labling member variables >:(, but i’ve never seen anyone use it for Java before…)

yes, there are multiply tiles of the same tile used. However I detect collisions on some tiles but not on other…for example…if the level consists of a black background with several clouds each made up of two tiles, say 12, and 13. The when my character movesover a tile it wll detect some number ‘12’ tiles but some number ‘12’ tiles will be undetected.