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.