Rust Journey – Snake Clone – Day 2 and 3

Day 2

My second day with this project was focused on partially refactoring the code.

I created different modules for the game, snake, and food entities. Also created a module for the direction enum… despite not being needed.

It took quite a while to move code from here to there and solve every complaint from the compiler. Then, I implemented a few getters and setters and removed the pub keyword from the struct members.

The worst part was passing the RendererWindow declared in main to a function implemented for the game type. Oh boy… it was solved using the &mut keyword but I felt like throwing spaghetti at the wall.

I finished with housekeeping. Adding license, updating gitignore, and deleting a few IDE files.

Day 3

My first task was fixing a bug related to the snake’s movement. When a quarter-circle was performed with the arrow keeps it was possible to get the snake heading to its own body.

Later I implemented a few new features: wall render, wall collision, snake body collision, and game over/reset.

I had no hard time implementing anything on day 3.

Final Notes

The 3rd day was a breeze. Probably because it was just programming and I didn’t deal with anything related to Rust syntax and semantics. The 2nd day, however… was a learning experience.

What’s next? graphics? main menu? maybe learn how to read and write a file for high-score records? Soon…