Код: Выделить всё
public void update(float dt, SpriteBatch sb) {
moveEnemy(dt);
drawEnemy(sb);
}
private void drawEnemy(SpriteBatch sb) {
enemySprite.draw(sb);
}
private void moveEnemy(float dt) {
float eX = enemySprite.getX();
float eY = enemySprite.getY();
position.set(eX, eY);
if(pathPoints.size > 0) {
destination.set(pathPoints.peek().x * sizeX, (Gdx.graphics.getHeight() - sizeY) - (pathPoints.peek().y * sizeY));
if(Math.round(eX) == destination.x && Math.round(eY) == destination.y) {
destination = pathPoints.pop();
}
dir.set(destination.x, destination.y).sub(eX, eY).nor();
velocity.set(dir).scl(speed);
movement.set(velocity).scl(dt);
position.add(movement);
enemySprite.setPosition(position.x, position.y);
}
}