My collision problem!!!!!!

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

publicvoid 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{

...

publicvoid 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{

...

publicvoid updateBound(int x,int y){

tile_bound.setRect(x,y,_width,_height);

}

...

}

class Scene{

...

publicboolean 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.

[3028 byte] By [zainuluka] at [2007-9-28 7:54:11]
# 1

Are you sure you check every tile? Try outputing some values before you check collisions, that may shed some light.

Just as a side note, if I were doing this game, I would make some cool interface like Collidable or Intersectable (probably the former), and have Tile and Character implement it. Abstraction is fun, isn't it?

danperkinsa at 2007-7-9 19:07:46 > top of Java-index,Other Topics,Java Game Development...