getComponentDirectionFromMe method
Implementation
Direction getComponentDirectionFromMe(GameComponent? comp) {
Rect rectToMove = rectConsideringCollision;
double centerXPlayer = comp?.center.x ?? 0;
double centerYPlayer = comp?.center.y ?? 0;
double centerYEnemy = rectToMove.center.dy;
double centerXEnemy = rectToMove.center.dx;
double diffX = centerXEnemy - centerXPlayer;
double diffY = centerYEnemy - centerYPlayer;
if (diffX.abs() > diffY.abs()) {
return diffX > 0 ? Direction.left : Direction.right;
} else {
return diffY > 0 ? Direction.up : Direction.down;
}
}