Hello!
I have everything working, except one thing. Basically, if two direction are pressed (e.g. UP and DOWN), player will always be able to pass. But if only one direction is pressed (e.g. UP), player won’t be able to move unless he’s perfectly aligned on the tile. If I lower my bomberman collision bound, it will look like he’s inside other tiles and I don’t want that.
This is exactly what I want:
If player is on the edge of the tile and tries to go down, but the tile down is blocked and if tile next to it is walkable, bomberman will gently slide onto it.
My points for collision are same as Kev’s (since his article helped me on free moving entities on tile map), top left, top right, bottom left and bottom right. I was experimenting and realized that in order to get that movement, I will have to check if only ONE point is colliding. But, I still don’t know how to recognize in between which tiles is bomberman. I even managed to create that movement, but it only worked when bomberman went up and down.
This is code used in my game for movement:
public boolean moveX(float motionX){
float newX = getX() + motionX;
float newY = getY();
if(isValidLocation(newX, newY)){
Map map = getMap();
PowerUp powerup = (PowerUp) map.getLayer("powerups").getObject((int) (newX / map.getTileWidth()), (int) (newY / map.getTileHeight()));
if(powerup != null){
powerup.activate(this);
}
setPosition(newX, newY);
return true;
}
return false;
}
public boolean moveY(float motionY){
float newX = getX();
float newY = getY() + motionY;
if(isValidLocation(newX, newY)){
Map map = getMap();
PowerUp powerup = (PowerUp) map.getLayer("powerups").getObject((int) (newX / map.getTileWidth()), (int) (newY / map.getTileHeight()));
if(powerup != null){
powerup.activate(this);
}
setPosition(newX, newY);
return true;
}
return false;
}
public boolean isValidLocation(float x, float y){
Map map = getMap();
float tx = x / map.getTileWidth();
float ty = y / map.getTileHeight();
if(map.isBlocked(this, tx, ty)){
return false;
}
if(map.isBlocked(this, tx + size, ty)){
return false;
}
if(map.isBlocked(this, tx, ty + size)){
return false;
}
if(map.isBlocked(this, tx + size, ty + size)){
return false;
}
return true;
}
Thanks, anyone who tries to help, in advance!