aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMark Powers <markppowers0@gmail.com>2018-12-11 20:19:23 -0500
committerMark Powers <markppowers0@gmail.com>2018-12-11 20:19:23 -0500
commit378578dfdd101a954f8798fa80acf160e4b29138 (patch)
tree8e93f13097e484c610fc06e021dde3149828afdb /src
parentdde52c79899a3f325a4036588301b35c47494196 (diff)
Update to include coords
Diffstat (limited to 'src')
-rwxr-xr-xsrc/html/snake.html17
1 files changed, 10 insertions, 7 deletions
diff --git a/src/html/snake.html b/src/html/snake.html
index dfc1cf1..3c66e1e 100755
--- a/src/html/snake.html
+++ b/src/html/snake.html
@@ -37,6 +37,8 @@
var t = 0;
var apple = {};
var isGameOver = false;
+ var mouseX =0;
+ var mouseY = 0;
console.log(apple);
setRandomCoords(apple);
console.log(apple);
@@ -59,6 +61,7 @@
font(20);
color("black");
ctx.fillText("Score: "+score,20,450);
+ ctx.fillText(mouseX + " " + mouseY, 20, 500);
color("orange");
// ctx.fillRect(210, 410, 390, 590)
@@ -127,16 +130,16 @@
}
}
function mousePush(e){
- var x = e.clientX - 420;
- var y = e.clientY - 510;
- console.log(x, y);
+ mouseX = e.clientX - 420;
+ mouseY = e.clientY - 510;
+ console.log(mouseX, mouseY);
- if(Math.sqrt(x*x+y*y) > 95){
+ if(Math.sqrt(mouseX*mouseX+mouseY*mouseY) > 95){
return;
}
- if(Math.abs(x) > Math.abs(y)){
- if(x < 0){
+ if(Math.abs(mouseX) > Math.abs(mouseY)){
+ if(mouseX < 0){
vx = -1;
vy = 0;
} else{
@@ -144,7 +147,7 @@
vy = 0;
}
} else {
- if(y < 0){
+ if(mouseY < 0){
vx = 0;
vy = -1;
} else{