Commit 27b6ed48 authored by Sander Kvenild's avatar Sander Kvenild
Browse files

Keeps bubbles inside canvas

parent 32ad25da
......@@ -23,6 +23,12 @@
flytt() {
this.x = this.x + Math.floor(Math.random() * 10 -5);
this.y = this.y + Math.floor(Math.random() * 10 -5);
// Keep bubbles from going outside of canvas
this.x = this.x - this.r > 0 ? this.x : this.r
this.y = this.y - this.r > 0 ? this.y : this.r
this.x = this.x + this.r < canvas.width ? this.x : canvas.width - this.r
this.y = this.y + this.r < canvas.height ? this.y : canvas.height -this.r
}
vis() {
ctx.beginPath();
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment