Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Snake collision #78

Open
lilplayer6k opened this issue Mar 11, 2021 · 3 comments
Open

Snake collision #78

lilplayer6k opened this issue Mar 11, 2021 · 3 comments

Comments

@lilplayer6k
Copy link

Hey there dear patorjk! i was playing a slightly altered version of your snake game recently and i wanted to ask if there could be a way to fix this weird snake collision bug where the snake could go backwards into itself and make you lose:
image

@patorjk
Copy link
Owner

patorjk commented Mar 12, 2021

That problem doesn't appear to be in the current version of the project:

https://codesandbox.io/s/github/patorjk/JavaScript-Snake?file=/index.html

Looks like this line prevents the problem:

https://github.com/patorjk/JavaScript-Snake/blob/master/js/snake.js#L279

@lilplayer6k
Copy link
Author

that line is already in the code though

@Pikabyte
Copy link

Pikabyte commented Nov 30, 2021

So I was making my own snake game for a school project and happened to notice this funny little thing. Then I decided to see if other snake games had this. It still exists, but it's less than easy to pull off. Basically, because only two inputs are stored, if you manage to input three or more inputs before the next update, you can do a 180.

stillexists

In my project, I solved this by storing them in a list instead. Realistically though, this is a minor issue, and you would only encounter this if you were deliberately trying to.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants