Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function randomSign() {
- let a = Math.random();
- if (a < 0.5) {
- return 1;
- }
- return -1;
- }
- function distance(x1, y1, x2, y2) {
- return Math.sqrt(Math.pow(x1 - x2, 2) + Math.pow(y1 - y2, 2));
- }
- let ground = 60;
- let x = 50;
- let y = 0;
- let gravity = 2;
- let xVelocity = 0;
- let yVelocity = 0;
- let bounceY = 0.9;
- let bounceX = 0.8;
- let scoreLeft = 0;
- let scoreRight = 0;
- let ellapsedTime = 0;
- foo = setInterval(() => {
- ellapsedTime += 60;
- if (ellapsedTime > 10000) {
- sbot.sendArray([
- {
- m: 'userset',
- set: { name: `${botname} [score: ${scoreRight}:${scoreLeft}]` },
- },
- ]);
- ellapsedTime = 0;
- }
- yVelocity += gravity;
- x += xVelocity;
- y += yVelocity;
- if (y > ground) {
- y = ground;
- yVelocity = -bounceY * yVelocity;
- xVelocity = bounceX * xVelocity;
- }
- if (y < 0) {
- y = 0;
- yVelocity = -bounceY * yVelocity;
- }
- if (x < 0) {
- x = 0;
- xVelocity = -bounceX * xVelocity;
- scoreLeft += 1;
- }
- if (x > 100) {
- x = 100;
- xVelocity = -bounceX * xVelocity;
- scoreRight += 1;
- }
- MPP.client.sendArray([{ m: 'm', x: x.toString(), y: y.toString() }]);
- }, 60);
- MPP.client.on('m', function(msg) {
- if (distance(x, y, msg.x, msg.y) < 10) {
- xVelocity = -Math.sign(msg.x - x) * 5;
- yVelocity = 15;
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement