From 804a23f4d0b67dc758fde0212aea4ac0e2976565 Mon Sep 17 00:00:00 2001 From: Agastya Chandrakant Date: Wed, 21 Dec 2016 00:14:34 +0530 Subject: [PATCH] Update snake.js updated dir function so that left arrow won't move the snake in left direction and kill it while it is moving in the right direction and vice-versa. --- challenges/CC_03_Snake_game_p5.js/snake.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/challenges/CC_03_Snake_game_p5.js/snake.js b/challenges/CC_03_Snake_game_p5.js/snake.js index d6f28a27fd..d84e8c2acc 100644 --- a/challenges/CC_03_Snake_game_p5.js/snake.js +++ b/challenges/CC_03_Snake_game_p5.js/snake.js @@ -22,8 +22,12 @@ function Snake() { } this.dir = function(x, y) { - this.xspeed = x; - this.yspeed = y; + if(this.xspeed != -1*x) { + this.xspeed = x; + } + if(this.yspeed != -1*y) { + this.yspeed = y; + } } this.death = function() {