From 2eade7a21bab0ffb2bb6d22cfdc4648e7c85ad12 Mon Sep 17 00:00:00 2001 From: Nathan Kunicki Date: Mon, 21 Dec 2015 16:48:55 +0000 Subject: [PATCH] Fixed bug in pong bounds handling --- .gitignore | 1 - examples/pong/pong.js | 4 ++-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index 8683cf7..84a398b 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ .idea/ .DS_Store -dist/ node_modules/ \ No newline at end of file diff --git a/examples/pong/pong.js b/examples/pong/pong.js index 80dee6a..65a3d63 100644 --- a/examples/pong/pong.js +++ b/examples/pong/pong.js @@ -49,11 +49,11 @@ window.onload = function () { this.pos.add(this.state.speed.clone().multiply(pong.lastFrameDelta)); - if ((this.pos.x + baseSize > width) || (this.pos.x < 0)) { + if ((this.pos.x + baseSize > width && this.state.speed.x > 0) || (this.pos.x < 0 && this.state.speed.x < 0)) { this.state.speed.x = -this.state.speed.x; } - if ((this.pos.y + baseSize > height) || (this.pos.y < 0)) { + if ((this.pos.y + baseSize > height && this.state.speed.y > 0) || (this.pos.y < 0 && this.state.speed.y < 0)) { this.state.speed.y = -this.state.speed.y; }