Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const Nav = lib.Nav;
- const distance = (a, b) => {
- let dx = (a.x - b.x);
- let dy = (a.y - b.y);
- return Math.sqrt((dx ** 2) + (dy ** 2));
- };
- class MyBot extends Bot {
- create() {
- this.nav = new Nav(this);
- this.drive(1);
- this.shoot();
- this.rotateTurret(1);
- }
- update() {
- if (!this.target || this.at(this.target.position)) {
- this.target = this.randomWaypoint();
- }
- this.nav.turnTo(this.target.position);
- }
- randomWaypoint() {
- let x = Math.random() * this.world.width;
- let y = Math.random() * this.world.height;
- let waypoint = { position: {x, y}};
- this.setMarker(waypoint.position);
- return waypoint;
- }
- at(position) {
- return distance(this.position, position) < 10;
- }
- }
- module.exports = MyBot;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement