Advertisement
Guest User

Untitled

a guest
Aug 19th, 2019
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. const Nav = lib.Nav;
  2.  
  3. const distance = (a, b) => {
  4. let dx = (a.x - b.x);
  5. let dy = (a.y - b.y);
  6.  
  7. return Math.sqrt((dx ** 2) + (dy ** 2));
  8. };
  9.  
  10. class MyBot extends Bot {
  11. create() {
  12. this.nav = new Nav(this);
  13. this.drive(1);
  14. this.shoot();
  15. this.rotateTurret(1);
  16. }
  17.  
  18. update() {
  19. if (!this.target || this.at(this.target.position)) {
  20. this.target = this.randomWaypoint();
  21. }
  22.  
  23. this.nav.turnTo(this.target.position);
  24. }
  25.  
  26. randomWaypoint() {
  27. let x = Math.random() * this.world.width;
  28. let y = Math.random() * this.world.height;
  29.  
  30. let waypoint = { position: {x, y}};
  31. this.setMarker(waypoint.position);
  32. return waypoint;
  33. }
  34.  
  35. at(position) {
  36. return distance(this.position, position) < 10;
  37. }
  38. }
  39.  
  40. module.exports = MyBot;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement