Update app.js

pull/1886/head
pidajo 2022-06-06 14:11:00 +02:00 committed by GitHub
parent fe5c293c46
commit bb1f8d6c2b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 83 additions and 84 deletions

View File

@ -1,119 +1,116 @@
class Ball {
constructor(collision) {
this.collision = collision;
this.w = 4;
this.h = this.w;
this.y = height / 2 - this.h / 2;
this.x = width / 2 - this.w / 2;
constructor(collision) {
this.collision = collision;
this.w = 4;
this.h = this.w;
this.y = height / 2 - this.h / 2;
this.x = width / 2 - this.w / 2;
this.oldX = this.x;
this.oldY = this.y;
this.velX = 6;
this.velY = 3.5 + Math.random();
}
this.velX = 6;
this.velY = 3.5 + Math.random();
}
reset() {
this.y = height / 2 - this.h / 2;
this.x = width / 2 - this.w / 2;
this.velX = 6;
this.velY = 3.5 + Math.random();
}
reset() {
this.y = height / 2 - this.h / 2;
this.x = width / 2 - this.w / 2;
this.velX = 6;
this.velY = 3.5 + Math.random();
}
checkCollision(that, isLeft) {
checkCollision(that, isLeft) {
let test = false;
if (isLeft) {
test = this.x <= that.w + this.w && this.y > that.y && this.y < that.y + that.h;
}
else {
} else {
test = this.x >= that.x + this.w && this.y > that.y && this.y < that.y + that.h;
}
if (test) {
this.velX = -this.velX;
if (test) {
this.velX = -this.velX;
this.velY = (3.5 + 2 * Math.random()) * this.velY / Math.abs(this.velY);
if (isLeft) {
right.follow = this;
right.follow = this;
left.follow = null;
} else {
left.follow = this;
} else {
left.follow = this;
right.follow = null;
}
}
}
}
}
}
move() {
if (this.velX > 0) {
this.checkCollision(right, false);
} else {
this.checkCollision(left, true);
move() {
if (this.velX > 0) {
this.checkCollision(right, false);
} else {
this.checkCollision(left, true);
}
this.x += this.velX;
this.y += this.velY;
this.x += this.velX;
this.y += this.velY;
if (this.y <= this.h) {
this.y = this.h;
if (this.y <= this.h) {
this.y = this.h;
this.velY = -this.velY;
}
}
if (this.y >= height - this.h) {
this.y = height - this.h;
if (this.y >= height - this.h) {
this.y = height - this.h;
this.velY = -this.velY;
}
}
if(this.x >= width) {
left.scored();
if (this.x >= width) {
left.scored();
restart();
} else if(this.x < 0) {
right.scored();
} else if (this.x < 0) {
right.scored();
restart();
}
}
}
}
}
class Paddle {
constructor(side) {
this.side = side;
this.w = 4;//15;
this.h = 30;//80;
this.y = height / 2 - this.h/2;
this.follow = null;
this.target = height / 2 - this.h/2;
this.score = 99;
constructor(side) {
this.side = side;
this.w = 4; //15;
this.h = 30; //80;
this.y = height / 2 - this.h / 2;
this.follow = null;
this.target = height / 2 - this.h / 2;
this.score = 99;
this.hasLost = false;
}
}
reset() {
this.follow = null;
reset() {
this.follow = null;
this.hasLost = false;
this.target = height / 2 - this.h/2;
this.y = height / 2 - this.h/2;
this.move();
}
this.target = height / 2 - this.h / 2;
this.y = height / 2 - this.h / 2;
this.move();
}
scored() {
scored() {
let d = new Date();
let value = 0;
if (this.side == "left") {
value = d.getHours();
value = d.getHours();
} else {
value = d.getMinutes();
value = d.getMinutes();
}
if (this.score < value) {
this.score++;
}
else {
} else {
this.score = value;
}
}
}
move() {
move() {
if (this.follow && ! this.hasLost) {
if (this.follow && !this.hasLost) {
var dy = this.follow.y - this.y - this.h / 2;
this.y += dy / 2;
}
else {
} else {
this.y += (this.target - this.y) / 10;
}
if (this.y < 0) {
@ -122,25 +119,26 @@ class Paddle {
if (this.y > height - this.h) {
this.y = height - this.h;
}
}
}
}
var updateTimeout = null;
function update() {
var d = new Date();
var d = new Date();
var lastStep = Date.now();
left.move();
right.move();
if(d.getHours() != left.score) {
left.move();
right.move();
if (d.getHours() != left.score) {
right.follow = null;
right.hasLost = true;
}
if(d.getMinutes() != right.score) {
}
if (d.getMinutes() != right.score) {
left.follow = null;
left.hasLost = true;
}
}
ball.move();
ball.move();
redraw();
var nextStep = 40 - (Date.now() - lastStep);
//console.log(nextStep);
@ -212,6 +210,7 @@ function stop() {
}
var pauseTimeout = null;
function pause() {
stop();
left.scored();
@ -235,7 +234,7 @@ Bangle.setUI("clock");
//setup play area
var height = g.getHeight(),
width = g.getWidth();
width = g.getWidth();
var top = 0;
g.reset();