Skip to content

Commit

Permalink
add player touch input
Browse files Browse the repository at this point in the history
  • Loading branch information
nickrhalvorsen committed Sep 7, 2018
1 parent 4b28af0 commit 21cd0fc
Showing 1 changed file with 26 additions and 9 deletions.
35 changes: 26 additions & 9 deletions framework/games/snake.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ var highScore = 0;

var foodX;
var foodY;
var touchX;
var touchY;

function setup() {
var canv = createCanvas(windowWidth, windowHeight);
Expand All @@ -19,15 +21,30 @@ function setup() {
}

//TODO Player Movement...
/**
function touchMove(x, y) {
touchX = x * windowWidth;
touchY = y * windowHeight;
}**/

//Used for testing
function mousePressed() {
dir = "up";

function touchStart(x, y) {
console.log(x + " " + y);
if(y > x) {
if(1-x > y) {
if(dir !== "right") {
dir = "left";
}
} else {
if(dir !== "up") {
dir = "down";
}
}
} else {
if(1-x > y) {
if(dir !== "down") {
dir = "up";
}
} else {
if(dir !== "left") {
dir = "right";
}
}
}
}

function draw() {
Expand Down

0 comments on commit 21cd0fc

Please sign in to comment.