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.

What have I been doing?

Well, it is pretty hard to answer.

No matter how tough you are, the pandemic hit us hard. I was able to manage the two years after I dived into work.
I literally worked as many hours as I worked back when I just started my career. I was thrilled and had an exciting drive. The project I was working on needed many features and during business hours, I rushed to create endpoints and features; by night, I improved tests and documentation.

Soon, stress and panic attacks took over the excitement and drive I had while I coded. One day I simply fell during the shower due to dizziness, and that made me reevaluate the whole situation.
It turned out impossible to dedicate myself to personal projects or any activity I love. At that point, I struggled to do the basics.
Don’t get me wrong, I loved that company and I am completely grateful for such an opportunity. I spent 6 years of my life there and to be honest, I never completed 2 years in a company before because there was always a better open position. I learned a lot and worked with skilled people that were always willing to share knowledge and experience.

The company and the projects suffered a few changes. We moved all our codebase from Azure Functions NodeJS to C#/NetCore6. It’s supposed to be a great learning experience and growth opportunity. But to me, it simply wasn’t.
The stress and panic attacks turned into a burnout and I, for the first time, had no joy in coding. My productivity dropped drastically and I had a hard time keeping focus or finishing my deliverables. It was frustrating to see myself acting like that, I really wanted to be a good employee and programmer.

So I took the decision to check new opportunities, to answer every recruiter on LinkedIn, and to apply to great companies. My mistake was not taking a period for myself but starting to enroll in many recruitment processes. I started a trial process in a company that really knows how to treat its staff, but I messed up… I messed up really hard because I still couldn’t focus and work like before.

Fortunately, I was accepted by another company. They really liked my experience, knowledge, and way to solve problems. It’s been a great experience so far and the level of pressure, stress, and work volume have been completely bearable for my well-being. Well, let’s not forget that 20 days into the new company I got appendicitis and it burst. Maybe it’s my body’s response to everything I went through before, maybe it’s just a coincidence. But I am getting better every day.

I started plentiful projects and/or activities in the past three to four years, some I had to drop, and some I wasn’t motivated to keep on. I am going to comment on a few:

VST Plugin – Boss HM2

I created a rough VST plugin effect simulating the infamous Boss HM-2, known for its chainsaw sound and notorious for the old-school Swedish death metal guitar tone. It was created using iPlug2 and faust language and consisted basically of an asymmetric clipping stage followed by three parametric equalizer filters(one for the low knob and two for the high knob). It did the job surprisingly quite well, but nothing different than what could be achieved using any good distortion plugin followed by any equalizer plugin.

For my very first project, it was fine, but my goal was to model the effect after the real circuit and soon I was dealing with quadratic functions, filter topologies, frequency response functions, thick signal processing books, and many things I wasn’t ready to deal with. At least at that moment and with the volume of work I was dealing back then.

It was a fun experience and I definitely plan to go back to it, but I still need to understand a lot of signal processing to be able to model the circuit schematic to the proper equations and functions.

Poetry

One day I was just laying down in bed and I had a moment where the words started coming to my mind. I got up and started writing non-stop until I finished my (very first) poem.

I really don’t know how to explain how it happened, maybe it was inspiration? I don’t know. It happened a few times more and now I am trying to write on a regular basis, even if it’s not something that I find good… I can’t rely on inspiration every time.

Vermicomposting

Since I have a couple of birds, there is always a few fruit leftovers that they reject during the day and I also deal with cardboard and paper bags from services like Amazon. Considering this, I decided to start a worm farm.

There is not much to say, they kinda do all the work for me. But it is really exciting to research and understand more about these detritivorous creatures… and obviously reduce my waste output

Gardening

After these years, I ended up moving to an apartment with an external area and, combined with the worms mentioned earlier, sounded like the perfect environment to grow some crops. I have quite a few pots with different herbs and chili peppers, I am still considering getting bigger pots to have larger plants.

Compared to my usual activities, it’s something completely different to have small interactions and see the changes after some days or weeks.

Fermenting

I started and brew a few batches of Kombucha during the pandemic. It worked well and I am definitely revisiting it soon. Recently I also did my own hot sauce, even bottled it into small glass bottles to give it a gift to friends. Oh… did I mention I grew the chilies?

URL Shortening and PasteBin clone

As a way to learn and keep myself motivated, I like to start personal projects using languages and technologies different from what I use while working. Since I never used MongoDB(or any NoSQL), I decided to do a couple of simple projects.

With ExpressJS and MongoDB I created my own version of Pastebin and URL shorter for personal use.

What’s up next?

Well… I am planning to keep track of my new or ongoing activities and projects here. It’s quite abandoned right now, to be honest.

I feel quite insecure to open the source of some projects, like the VST or the ExpressJS/MongoDB one, at least when working with something I am still learning and I don’t dominate yet. It feels like I am showing all my mistakes to the world.
But well… I am starting a new project with Rust and SFML, my goal is to document (and commit) every step and hopefully start new projects after the first one.

So please, unlike the B string of my guitar: stay tuned!

How to set up an amazing development environment on Windows

Introduction

I have been using Linux for development for a long time and MacOS for quite a few years. The only handful of times that I developed on Windows was for a small fix or adjustment.

The display of my Macbook Pro died back in September and I went back to Linux to develop. Hoping that I would have the Macbook up and running as soon as possible. The repair quotation arrived and, to my surprise, the price was way out of my reality.

I then decided to give it a try to docker-desktop since a coworker from another team had success running our development stack.

(This guide is based on guides, StackOverflow questions, and discussions all over the internet. Unintentionally I may end up forgetting to give due credit.)

Hyper.js + Oh My ZSH as Ubuntu on Windows (WSL) Terminal

(Original: https://medium.com/@ssharizal/hyper-js-oh-my-zsh-as-ubuntu-on-windows-wsl-terminal-8bf577cdbd97)

Install Windows Subsystem Linux — https://docs.microsoft.com/en-us/windows/wsl/install-win10

Install Ubuntu on Windows from Microsoft Store or any other Linux flavor — https://www.microsoft.com/en-us/p/ubuntu/9nblggh4msv6

Install Hyper.js terminal — https://hyper.is/

I went for the hyper-material-theme to set it up press Ctrl + , to bring up Hyper.js configuration file. Look for plugins: [ edit and add the theme.

plugins: [
//"hyper-dracula"
//"hyper-solarized-dark"
"hyper-material-theme"
],

Setup Hyper.js to automatically open Ubuntu on Windows

  • Open up Hyper.js configuration again and type Ctrl + ,
  • Scroll down to shell and change it to C:\\Windows\\System32\\bash.exe
// the shell to run when spawning a new session (i.e. /usr/local/bin/fish)
// if left empty, your system's login shell will be used by default
//
// Windows
// - Make sure to use a full path if the binary name doesn't work
// - Remove `--login` in shellArgs
//
// Bash on Windows
// - Example: `C:\\Windows\\System32\\bash.exe`
//
// PowerShell on Windows
// - Example: `C:\\WINDOWS\\System32\\WindowsPowerShell\\v1.0\\powershell.exe`
shell: 'C:\\Windows\\System32\\bash.exe',

Install ZSH on Ubuntu Bash Windows

  • Run this sudo apt-get install zsh
  • Open your bash profile vim~/.bashrc
  • Add this to set it to use ZSH as default:
bash -c zsh
# ~/.bashrc: executed by bash(1) for non-login shells.
# see /usr/share/doc/bash/examples/startup-files (in the package bash-doc)
# for examples# If not running interactively, don't do anything
case $- in

Install Oh My ZSH

Install Oh My Zsh with 

sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"

Restart Hyper.js and you are done!

Docker Desktop, docker-compose, and nvm

Install Docker Desktop

Follow the instructions on https://docs.docker.com/docker-for-windows/wsl/, but it is basically the usual next-next-finish.

Install docker, docker-compose, and nvm

On your terminal install both docker and docker-compose

sudo apt-get install docker docker-compose nvm

Speed things up

zsh is smart with its completions, but it may get really slow and frustrating if you let Windows concatenate its PATH with WSL’s path.

Edit your /etc/wsl.conf with the following:

[automount]
enabled = true
[interop]
appendWindowsPath = false

Besides that, make sure that you are not running docker/node on your mounted hard drive(i.e. /mnt/c/), but instead the WSL filesystem. If you need to access it, with your IDE or editor, use the \\wsl$\ network path.

Running Selenium/Webdriver tests

Install google-chrome inside WSL with your favorite PPA repository. I am not going to teach you this since there an infinity of tutorials on the subject. It may or may not work with chromium, but I didn’t test.

Install Xming/Xlaunch with the notorious next-next-finish https://sourceforge.net/projects/xming/

Create a config.xlaunch file with the following and run it afterwards:

<?xml version="1.0"?>
<XLaunch xmlns="http://www.straightrunning.com/XmingNotes" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" <?xml version="1.0"?>
<XLaunch xmlns="http://www.straightrunning.com/XmingNotes" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.straightrunning.com/XmingNotes XLaunch.xsd" WindowMode="Windowed" ClientMode="NoClient" Display="0" Clipboard="true" ExtraParams="-ac"/>

On WSL you need to export the DISPLAY variable(I recommend you put it on your bashrc or similar):

export DISPLAY=$(grep -m 1 nameserver /etc/resolv.conf | awk '{print $2}'):0.0

You should be able to run Google Chrome by now on your terminal: google-chrome

Don’t forget to install chromedriver:

npm install -g chromedriver --detect_chromedriver_version

End Notes

Wish I started this as a draft when I got the notebook and started the process, so I could document every step. However, this post consolidates every major step or issue that I had.

The speed is blazing fast compared to the one that I got on the MacBook. I never imagined that I would like to code on Windows. Guess my words come back to me 🤷‍♂️.