Skip to content

Instantly share code, notes, and snippets.

@botrosg
Created August 23, 2017 01:31
Show Gist options
  • Save botrosg/d2bb38eaefda08add617a96af5c33f14 to your computer and use it in GitHub Desktop.
Save botrosg/d2bb38eaefda08add617a96af5c33f14 to your computer and use it in GitHub Desktop.

Revisions

  1. botrosg created this gist Aug 23, 2017.
    7 changes: 7 additions & 0 deletions ball - hit left and right wall
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,7 @@
    if(this.x - 5 < 0) { // hitting the left wall
    this.x = 5;
    this.x_speed = -this.x_speed;
    } else if(this.x + 5 > canvas.width) { // hitting the right wall
    this.x = canvas.width - this.radius;
    this.x_speed = -this.x_speed;
    }