Rust Journey – Snake Clone – Day 1

Introduction

I have a strong passion for coding, but I often struggle when it comes to starting personal projects using the same languages and tech stack I use in my daily job. However, I believe in the importance of exploring new technologies and exploring different scenarios, so I’m using that as a driving force to learn and expand my skills.

Although it has been a while since I worked on anything involving visual interaction, I remember the immense joy I felt when seeing the results of my code with technologies like Processing or Flash/ActionScript over a decade ago.

With that in mind, I’ve brainstormed a few ideas and settled on a tech stack for my next project.

Why Rust?

The features of Rust have truly captivated my interest. I’ve thoroughly enjoyed every aspect of the language, or at least everything I’ve read about it so far. It seemed like a logical choice for this project, and if I end up not liking it, I can always switch to something else, right?

Why SFML?

I had some prior experience with SDL2, and SFML appeared to share many similarities with it. However, SFML offers the advantage of wrapping everything in classes, while SDL2 requires the use of long and cumbersome functions. Don’t get me wrong, SDL2 is impressive, but its extensive portability wasn’t necessary for this project.

Why not a game engine?

My primary goal is to learn new programming languages and libraries, rather than focusing solely on game development. The game portion of this project serves as a familiar concept that I can work with and learn from. In fact, I don’t want to limit my future projects to game development alone; they could also involve creating my own GUI toolkit or exploring data visualization.

First day progress:

My approach is to tackle this project without relying on tutorials or lessons, although I will make use of documentation and StackOverflow as needed.

To begin, I cloned the rust-sfml repository and followed the instructions. Once I had it up and running, I created a separate repository for my project and added a boilerplate code to create a window and an event listener.

From there, I started implementing the basic features of the game. The process went smoothly, and by the end of the first day, I had a satisfactory prototype that included:

  • A snake rendered on the screen and controlled by arrow keys
  • Food items randomly placed on the screen, which, when consumed, increased the snake’s size and speed

Although there is still a lot more to do, you can track the ongoing progress on the GitHub Repository.

Moving forward, my plan is to focus on the following tasks:

  • Organize the files into modules
  • Implementing hit detection to walls
  • Implementing hit detection to snake’s body
  • Adding game-over functionality, score tracking, and a restart option
  • Implementing an FPS cap and detection mechanism.
  • Improving the snake’s speed code.
  • Enhancing the snake’s movement code.
  • Adding sound effects.
  • Adding actual graphics
  • Learn how to use the debugger
  • Implement automated tests

Final Notes

This project has been an exciting and unique experience for me, and I’m eagerly looking forward to starting other projects as well. Even at this early stage, I can already appreciate the power and potential of Rust as a programming language. I’m still learning and grasping its concepts and syntax, so please bear with any unconventional code you may come across.

Git repository access control with Gitolite

I already used other version control software like CVS and SVN in the past, but Git was one that really got me because I just felt it easy and intuitive.

Besides having a GitHub account I really don’t see the point of paying US$7/month just to have private repositories when you can roll your own VPS for less than that. Obviously, you can install something more similar to GitHub like GitLab, but, in my opinion, Gitolite is easy to use, fast and works; Keep it simple, sucker!

So, I will give the steps to install and configure on Ubuntu Server 16.04. On other distros the paths and steps may differ.

First of all, you should check existing SSH keys or generate a new set on your machine. (To be honest, if you are already using git you should have your keys)

#to check:
ls -al ~/.ssh
#to generate(linux/mac):
ssh-keygen -t rsa

On Windows machines I advise you to install cygwin with net/openssh package. I prefer that way, but you can try with other methods.

Back to our server, now we should install gitolite3 and git-core:

sudo apt-get install git-core gitolite3

Insert your public key configure gitolite. On older versions you need to create a user and run the setup by yourself, keep that in mind if you are using other distro.

Now you can ssh the gitolite user to list the repositories:

ssh gitolite3@yourdomain.com

You can add some rules and keys cloning the gitolite-admin repository.

git clone gitolite3@youtdomain.com:gitolite-admin

You can now add pub keys for other users(or machines) creating files in the keydir directory. For multiple machines you should use the name convention user@machine.pub, like nimlhug@notebook.pub. On the conf/gitolite.conf file you can add users and repositories.

Checkout the official documentation. Apart from being a non resource-intensive, gitolite is a rich and powerful software that you can make use of RegEx, groups, hooks, VREF, wild repos and much more.