From 40921d2fcda1478cebe113b12b023f554e58689c Mon Sep 17 00:00:00 2001 From: Paradox Programming <41707197+theParadox42@users.noreply.github.com> Date: Thu, 9 May 2019 22:49:17 -0600 Subject: [PATCH] Added mobile controls --- p/games/javascript/p5/pongp5/mySketch.js | 32 ++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/p/games/javascript/p5/pongp5/mySketch.js b/p/games/javascript/p5/pongp5/mySketch.js index 6b3c63c..2eaa340 100644 --- a/p/games/javascript/p5/pongp5/mySketch.js +++ b/p/games/javascript/p5/pongp5/mySketch.js @@ -685,6 +685,26 @@ Player.prototype.control = function(){ if(this.cz>this.z){ xs *= -1; } + if(detectmob()&&mouseIsPressed){ + if(mouseX<100){ + if(mouseY<100){ + this.cvx-=xs; + this.cvy-=0.5; + } else if(mouseY>height-100){ + this.cvx-=xs; + this.cvy+=0.5; + } + } else if(mouseX>width-100){ + if(mouseY<100){ + this.cvx+=xs; + this.cvy-=0.5; + } else if(mouseY>height-100){ + this.cvx+=xs; + this.cvy+=0.5; + } + } + return true; + } if(this.mode==="all"){ if(keys.d||keys[RIGHT_ARROW]){ this.cvx+=xs; @@ -1212,6 +1232,18 @@ var game = function(){ clicked = false; } } + + if(detectmob()){ + push(); + fill(0, 0, 0, 128); + strokeWeight(5); + stroke(0, 0, 0, 200); + rect(0, 0, 100, 100); + rect(0, height-100, 100, 100); + rect(width-100, height-100, 100, 100); + rect(width-100, 0, 100, 100); + pop(); + } }; var setGraphics = function(){ AIBackground();