Update app.js

master
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; let test = false;
if (isLeft) { if (isLeft) {
test = this.x <= that.w + this.w && this.y > that.y && this.y < that.y + that.h; 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; test = this.x >= that.x + this.w && this.y > that.y && this.y < that.y + that.h;
} }
if (test) { if (test) {
@ -101,8 +100,7 @@ class Paddle {
} }
if (this.score < value) { if (this.score < value) {
this.score++; this.score++;
} } else {
else {
this.score = value; this.score = value;
} }
} }
@ -112,8 +110,7 @@ class Paddle {
if (this.follow && !this.hasLost) { if (this.follow && !this.hasLost) {
var dy = this.follow.y - this.y - this.h / 2; var dy = this.follow.y - this.y - this.h / 2;
this.y += dy / 2; this.y += dy / 2;
} } else {
else {
this.y += (this.target - this.y) / 10; this.y += (this.target - this.y) / 10;
} }
if (this.y < 0) { if (this.y < 0) {
@ -126,6 +123,7 @@ class Paddle {
} }
var updateTimeout = null; var updateTimeout = null;
function update() { function update() {
var d = new Date(); var d = new Date();
var lastStep = Date.now(); var lastStep = Date.now();
@ -212,6 +210,7 @@ function stop() {
} }
var pauseTimeout = null; var pauseTimeout = null;
function pause() { function pause() {
stop(); stop();
left.scored(); left.scored();