Rust Journey – Snake Clone – Day 5

It’s been some busy weeks for me. So I had to slow down my side projects.

Well, I finished the implementation for highscores. Returning a struct with strings is way harder than I anticipated. I used another approach, fetching the values when needed.

I am not happy with the final implementation, but I can always refactor it when I fully understand the language and its concepts.

Oh, I forgot to mention it in the previous post. I got the debugger running and it was one of my goals.

I also moved the project to Linux. Had a hard time setting up the SFML/CSFML dependencies, but everything went ok after I changed the crate dependency to the rust-sfml git repository.

Final Notes

Well, not much was achieved. But I finally got the highscores working. I am just going to implement graphics and sound and then finally call the project done.

Hope the next iteration happens soon.

Rust Journey – Snake Clone – Day 4

I started this iteration by fixing a few bugs and then proceed to add the screens for the different game states(game over, main menu, high scores). It was a quick and dirty iteration just before calling it a day. But since everything happened within 24 hours I am mentioning it.

Then, I created modules for every screen and improved the code to remove any duplicate code and redundancy. Now every screen module is composed of two main functions: render and handler. The further first dealt with key codes but soon it changed to all events.

I committed my changes and started working with the high scores, both recording the values into a file and also fetching it. I got everything working, except the high score display. Dealing with Strings or str within structs or returning was a mess. I went into many lifetime issues when working with it.

I decided to ditch everything related to the high-scores and start over. No git commit was done.

Final Notes

I like to have small iterations to get something working followed by a refactor, but this time I had to rethink my strategy. I understand the causes of the issues I ran into, but I am still learning the language to know how to deal with it.

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…