Hello,
I need some help since I want to make blocks for a human actor(Meaning that I have a sprite that looks like a human). For I want to add blocks, I created a method that doesn't allow me to move through objects :
I've got the same method for finding Y coordinates of the block but there is a difference : For I want to compare the distance between the actor's feet (25px beneath the original center of the sprite) I would like to change the center for the getObjectsInRange method. Thank you in advance!
public int checkWhereCannotMoveX()
{
List <Block> nearObstacle = getObjectsInRange(60, Block.class);
int value = 0;
Block nearestObstacle = null;
double nearestDistance = 60;
double distance;
for (int i = 0; i < nearObstacle.size(); i++)
{
distance = getDistance(nearObstacle.get(i));
if (distance < nearestDistance)
{
nearestObstacle = nearObstacle.get(i);
nearestDistance = distance;
}
}
if(nearestObstacle != null){
Block block = nearestObstacle;
int blockX = block.getX() - getX();
int blockY = block.getY() - getY();
if(blockX < 35 && blockX > 0){if(blockY < 60 && blockY > -10){value = 1;}}
else if(blockX > -35 && blockX < 0){if(blockY < 60 && blockY > -10){value = 2;}}
}
return value;
}