bool hasCollision(GameLevel level, int x1, int y1, int x2, int y2, int xOff, int yOff) {
Tile relative1 = getRelativeTile(level, x1, y1, 0xOff, -1yOff);
Tile relative2 = getRelativeTile(level, x2, y2, 0xOff, -1yOff);
return relative1 != null && relative1.getType() == 0
|| relative2 != null && relative2.getType() == 0;
}
bool hasCollision(GameLevel level, int x1, int y1, int x2, int y2, int xOff, int yOff) {
Tile relative1 = getRelativeTile(level, x1, y1, 0, -1);
Tile relative2 = getRelativeTile(level, x2, y2, 0, -1);
return relative1 != null && relative1.getType() == 0
|| relative2 != null && relative2.getType() == 0;
}
bool hasCollision(GameLevel level, int x1, int y1, int x2, int y2, int xOff, int yOff) {
Tile relative1 = getRelativeTile(level, x1, y1, xOff, yOff);
Tile relative2 = getRelativeTile(level, x2, y2, xOff, yOff);
return relative1 != null && relative1.getType() == 0
|| relative2 != null && relative2.getType() == 0;
}
This does three things to get the code down. First, I get rid of a smack
variable that is unused. Second, for those fields that get set the same regardless of how the constructor is called, I initialize those at declaration time. So the constructors don't need to do so. Third, I call one constructor from the other call one constructor from the other. This allows me to set default values for the parameters. And it means that we don't have to repeat the snap logic in both constructors.
This does three things to get the code down. First, I get rid of a smack
variable that is unused. Second, for those fields that get set the same regardless of how the constructor is called, I initialize those at declaration time. So the constructors don't need to do so. Third, I call one constructor from the other. This allows me to set default values for the parameters. And it means that we don't have to repeat the snap logic in both constructors.
This does three things to get the code down. First, I get rid of a smack
variable that is unused. Second, for those fields that get set the same regardless of how the constructor is called, I initialize those at declaration time. So the constructors don't need to do so. Third, I call one constructor from the other. This allows me to set default values for the parameters. And it means that we don't have to repeat the snap logic in both constructors.
You have four of these methods. All of them have the same basic pattern. You may want to consider @SimonForsberg's Direction enum pattern @SimonForsberg's Direction enum pattern for this. But even without that, you could make this code considerably simpler.
You have four of these methods. All of them have the same basic pattern. You may want to consider @SimonForsberg's Direction enum pattern for this. But even without that, you could make this code considerably simpler.
You have four of these methods. All of them have the same basic pattern. You may want to consider @SimonForsberg's Direction enum pattern for this. But even without that, you could make this code considerably simpler.