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

Add variable speed on long press #4

Merged
merged 8 commits into from
Oct 4, 2023

Conversation

brehen
Copy link
Contributor

@brehen brehen commented Oct 4, 2023

Hi!

This fixes #3 :-)

This is the commit that changes the game logic:
4bc8fc4

The rest of the commits are mainly from running Clippy and Rustformatter on the project and finding some places to improve readability. These changes might be more preference based and might not match what you've intended. Let me know if that's the case, and I can remove the changes that don't match with the project vision. 😄

For the game logic itself, there's a limitation in ncurses, in so that it is not able to detect when the user keeps the key down by themselves. In order to do a reliable speed-up on keypress, another library for interacting with the terminal would be needed. For example tui-rs or crossterm, but that's a major refactor.

So what I ended up doing was effectively setting the speed to be 25 instead of 100 when the user presses down a key for longer, and when it stops pressing it, the getch function will match on Err() and set the speed back to 1. This is sort of a "hack", and it doesn't look incredibly pretty in my terminal, but it works! 😄

@RupakBiswas-2304
Copy link
Member

@brehen Thank you for your valuable contribution !!

@RupakBiswas-2304 RupakBiswas-2304 merged commit 12ae48a into Tentacall:main Oct 4, 2023
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Variable speed of the snake
2 participants