+ 1

Snake is going reverse

Hi. I'm making snake game and snake can go reverse to it's tail. How to fix this? For example, snake is going up and user can make it going down. How to prevent this?

27th Nov 2018, 6:02 PM
Вадим Лукашенко
Вадим Лукашенко - avatar
2 Answers
+ 11
You can add if statements like this: if(next == 'up' && curr != 'down'){ curr = next } but it's hard to help without seeing your code
27th Nov 2018, 6:36 PM
Mert Yazıcı
Mert Yazıcı - avatar
+ 2
thanks for your support, but one guy helped me with idea. I worked a little bit on his code and everything is working now
27th Nov 2018, 7:29 PM
Вадим Лукашенко
Вадим Лукашенко - avatar