You are browsing as a guest. Sign up (or log in) to start making projects!

2h 7m 26s logged

Devlog #2 (a terminal snake game)
I’m back with my Rust project based learning journey (creating a rust project for the first time to help me out with another big project I’m thinking about)

TL;DR: I got input and basic game state done, a character in the terminal can move

Full version: Anyways, this devlog I got quite a bit done! I first started creating a simple Position struct, moved to create a simple Game class, then created Input matching using crossterm terminal library built in Events where I was getting confused between an “associated” fn vs a method and got into this thinking loop because of Result<Option<Command>> but basically you need to read it from inside out, if that helps! Also I can’t be more grateful for THE GOAT KEYWORD…drumroll…match! I don’t understand why other languages don’t have this, it’s way easier to handle enums this way! After being done with input, I added a input handling function to my game file to update player_pos. Then going back to main, I added a loop and made sure all the pieces fit together. I then did my first test where I saw movement working! but there were some issues that I resolved in later commits, like the character being in different places b/c of not clearing the screen before every redraw and adding a delay so that my CPU doesn’t BLOW UP from the loop. I still need to fix one thing though: the loop breaks even without me pressing the quit button after some time, so I need to figure out what’s doing that. I also need to make sure the terminal window size and character updating is synced. In the next devlog I’ll try to add some food and hopefully start adding some snake growing logic! Glad that I’ve got to learn crossterm, and hope to learn async and tokio, etc with rust in the future…

sorry for the yap, nevertheless, I think I took a bit long to create basic movement but I’m satisfied since it’s my first time. Also I uploaded a gif bc for some reason .mkv upload didn’t work

0
5

Comments 0

No comments yet. Be the first!