Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. function randomSign() {
  2.   let a = Math.random();
  3.   if (a < 0.5) {
  4.     return 1;
  5.   }
  6.   return -1;
  7. }
  8.  
  9. function distance(x1, y1, x2, y2) {
  10.   return Math.sqrt(Math.pow(x1 - x2, 2) + Math.pow(y1 - y2, 2));
  11. }
  12.  
  13. let ground = 60;
  14.  
  15. let x = 50;
  16. let y = 0;
  17.  
  18. let gravity = 2;
  19.  
  20. let xVelocity = 0;
  21. let yVelocity = 0;
  22.  
  23. let bounceY = 0.9;
  24. let bounceX = 0.8;
  25.  
  26. let scoreLeft = 0;
  27. let scoreRight = 0;
  28.  
  29. let ellapsedTime = 0;
  30.  
  31. foo = setInterval(() => {
  32.   ellapsedTime += 60;
  33.   if (ellapsedTime > 10000) {
  34.     sbot.sendArray([
  35.       {
  36.         m: 'userset',
  37.         set: { name: `${botname} [score: ${scoreRight}:${scoreLeft}]` },
  38.       },
  39.     ]);
  40.     ellapsedTime = 0;
  41.   }
  42.  
  43.   yVelocity += gravity;
  44.  
  45.   x += xVelocity;
  46.   y += yVelocity;
  47.  
  48.   if (y > ground) {
  49.     y = ground;
  50.     yVelocity = -bounceY * yVelocity;
  51.     xVelocity = bounceX * xVelocity;
  52.   }
  53.  
  54.   if (y < 0) {
  55.     y = 0;
  56.     yVelocity = -bounceY * yVelocity;
  57.   }
  58.  
  59.   if (x < 0) {
  60.     x = 0;
  61.     xVelocity = -bounceX * xVelocity;
  62.     scoreLeft += 1;
  63.   }
  64.  
  65.   if (x > 100) {
  66.     x = 100;
  67.     xVelocity = -bounceX * xVelocity;
  68.     scoreRight += 1;
  69.   }
  70.  
  71.   MPP.client.sendArray([{ m: 'm', x: x.toString(), y: y.toString() }]);
  72. }, 60);
  73.  
  74. MPP.client.on('m', function(msg) {
  75.   if (distance(x, y, msg.x, msg.y) < 10) {
  76.     xVelocity = -Math.sign(msg.x - x) * 5;
  77.     yVelocity = 15;
  78.   }
  79. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement