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

@ -22,8 +22,7 @@ class Ball {
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) {
@ -60,10 +59,10 @@ class Ball {
this.velY = -this.velY;
}
if(this.x >= width) {
if (this.x >= width) {
left.scored();
restart();
} else if(this.x < 0) {
} else if (this.x < 0) {
right.scored();
restart();
}
@ -74,11 +73,11 @@ class Ball {
class Paddle {
constructor(side) {
this.side = side;
this.w = 4;//15;
this.h = 30;//80;
this.y = height / 2 - this.h/2;
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.target = height / 2 - this.h / 2;
this.score = 99;
this.hasLost = false;
}
@ -86,8 +85,8 @@ class Paddle {
reset() {
this.follow = null;
this.hasLost = false;
this.target = height / 2 - this.h/2;
this.y = height / 2 - this.h/2;
this.target = height / 2 - this.h / 2;
this.y = height / 2 - this.h / 2;
this.move();
}
@ -101,19 +100,17 @@ class Paddle {
}
if (this.score < value) {
this.score++;
}
else {
} else {
this.score = value;
}
}
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) {
@ -126,16 +123,17 @@ class Paddle {
}
var updateTimeout = null;
function update() {
var d = new Date();
var lastStep = Date.now();
left.move();
right.move();
if(d.getHours() != left.score) {
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;
}
@ -212,6 +210,7 @@ function stop() {
}
var pauseTimeout = null;
function pause() {
stop();
left.scored();