<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Martin Možucha</title>
    <description>The latest articles on DEV Community by Martin Možucha (@spekcezstolicku).</description>
    <link>https://dev.to/spekcezstolicku</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F772335%2Fb6d96ca0-01bb-4196-a2a3-70ceea8ee864.jpg</url>
      <title>DEV Community: Martin Možucha</title>
      <link>https://dev.to/spekcezstolicku</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/spekcezstolicku"/>
    <language>en</language>
    <item>
      <title>You're a better developer than you think, you just need to realize...</title>
      <dc:creator>Martin Možucha</dc:creator>
      <pubDate>Wed, 07 May 2025 16:25:09 +0000</pubDate>
      <link>https://dev.to/spekcezstolicku/youre-a-better-developer-than-you-think-you-just-need-to-realize-1e2f</link>
      <guid>https://dev.to/spekcezstolicku/youre-a-better-developer-than-you-think-you-just-need-to-realize-1e2f</guid>
      <description>&lt;p&gt;The world of programming is a massive &lt;strong&gt;maze&lt;/strong&gt;. It has its own rules that can help you find your way to the goal. At the beginning, you feel lost. So many paths, and you don’t know where to start.&lt;/p&gt;

&lt;p&gt;Those who started &lt;strong&gt;decades ago&lt;/strong&gt; had only a book in their backpack. They learned through trial and error, slowly and painfully.&lt;/p&gt;

&lt;p&gt;Later, the internet came. The book stayed, but a &lt;strong&gt;walkie-talkie&lt;/strong&gt; was added. You could finally ask someone on the other side of the world for help.&lt;/p&gt;

&lt;p&gt;Today? You have the book, the walkie-talkie, and a &lt;strong&gt;jetpack&lt;/strong&gt;. You can fly over the walls and reach your destination faster than ever before.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Is this the full picture? Not quite... There's still one key variable missing.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The size of the maze&lt;/strong&gt;. The first generation learned to navigate a much smaller space. Today’s programming world is enormous and growing faster every day. Frontend, backend, AI, mobile apps, DevOps...&lt;/p&gt;

&lt;p&gt;Need proof? Ask 10 different web development companies what tech stack they use. You’ll get 10 different answers.&lt;/p&gt;

&lt;p&gt;The jetpack may seem like a miracle, but in today’s &lt;strong&gt;infinite maze&lt;/strong&gt;, even that won’t make your journey effortless.&lt;/p&gt;




&lt;p&gt;If you started with only a book and you’re still coding today, you’ve earned the title of &lt;strong&gt;wizard&lt;/strong&gt;.&lt;br&gt;&lt;br&gt;
But be honest. Can you still keep up with today’s pace? Probably not. And it’s not about age, motivation, or family obligations.&lt;br&gt;&lt;br&gt;
It’s because while you’re learning one thing, &lt;strong&gt;ten new updates&lt;/strong&gt; and &lt;strong&gt;two new frameworks&lt;/strong&gt; are released.&lt;/p&gt;

&lt;p&gt;Now imagine someone who’s just started coding &lt;strong&gt;a week ago&lt;/strong&gt;.&lt;br&gt;&lt;br&gt;
How are &lt;strong&gt;they&lt;/strong&gt; supposed to feel?&lt;/p&gt;




&lt;h2&gt;
  
  
  It's not about perfect code. It’s about the result.
&lt;/h2&gt;

&lt;p&gt;If your goal is to build a calculator, then do whatever it takes to make sure your mom can use it to calculate her grocery budget. That’s your mission.&lt;/p&gt;

&lt;p&gt;And guess what?&lt;/p&gt;

&lt;p&gt;It &lt;strong&gt;doesn’t matter&lt;/strong&gt; if AI generated most of the code and you just copy-pasted it.&lt;br&gt;&lt;br&gt;
(If you're a wizard, you're probably bleeding from the nose right now. It's okay, wipe it off and keep reading. This is the good part.)&lt;/p&gt;

&lt;p&gt;Maybe you'll build 10 more projects like that. Maybe 15. But eventually, you’ll hit the limits of what AI can do.&lt;br&gt;&lt;br&gt;
And that’s when you’ll &lt;strong&gt;turn your brain on&lt;/strong&gt;, start asking questions, learning from mistakes, and gaining experience.&lt;/p&gt;

&lt;p&gt;That’s when you’ll start becoming a &lt;strong&gt;developer&lt;/strong&gt;.&lt;br&gt;&lt;br&gt;
And AI will become your &lt;strong&gt;assistant&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Back in the day, it could take a &lt;strong&gt;week&lt;/strong&gt; to find a single bug. Now, AI can fix it in &lt;strong&gt;a minute&lt;/strong&gt;, giving you the time to learn Docker, Git, GitHub...&lt;br&gt;&lt;br&gt;
Because without those, &lt;strong&gt;no company&lt;/strong&gt; will want to talk to you. That’s the reality today.&lt;/p&gt;




&lt;h2&gt;
  
  
  And what about perfect code?
&lt;/h2&gt;

&lt;p&gt;There’s only one kind: &lt;strong&gt;completed and working&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;I’ve drowned more than once chasing “perfect” code. I followed every best practice. Security, performance, readability, reusability.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;And the result?&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
A project that could’ve taken a month ended up taking &lt;strong&gt;four&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;And in the end? It did the &lt;strong&gt;exact same thing&lt;/strong&gt; as other projects.&lt;br&gt;&lt;br&gt;
Maybe a bit faster. Maybe a bit safer.&lt;br&gt;&lt;br&gt;
But the only one who noticed the difference? &lt;strong&gt;Me&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;And six months later, I opened the code and thought:&lt;br&gt;&lt;br&gt;
&lt;strong&gt;“Who the hell wrote this mess?”&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>productivity</category>
      <category>coding</category>
      <category>programming</category>
      <category>beginners</category>
    </item>
    <item>
      <title>Realistic Snake twists using just 2 images? Possible!</title>
      <dc:creator>Martin Možucha</dc:creator>
      <pubDate>Mon, 05 May 2025 02:15:56 +0000</pubDate>
      <link>https://dev.to/spekcezstolicku/realistic-snake-twists-using-just-2-images-possible-49oc</link>
      <guid>https://dev.to/spekcezstolicku/realistic-snake-twists-using-just-2-images-possible-49oc</guid>
      <description>&lt;p&gt;Online, there's a plethora of Snake game tutorials. Most focus on chasing a cluster of squares representing the snake behind another square, symbolizing loot. Better projects distinguish the head from the body by coloring the first square differently, while chasing an apple. The more professional projects come closest to the ideals of classic snake games, where the snake looks like a snake and moves realistically. Such projects utilize &lt;strong&gt;sprites&lt;/strong&gt;, a set of images placed at direction-change points, to give the snake smooth structure and simulate its movement.&lt;/p&gt;

&lt;p&gt;But... Can a Snake game &lt;strong&gt;be created&lt;/strong&gt; using &lt;strong&gt;only 2 images&lt;/strong&gt; for the head and body while meeting all the functional attributes? Let's explore together.&lt;/p&gt;




&lt;h2&gt;
  
  
  What's (Not) included in the Article?
&lt;/h2&gt;

&lt;p&gt;The entire step-by-step process with code &lt;strong&gt;won't be found here&lt;/strong&gt;, so if you want to see the &lt;strong&gt;result&lt;/strong&gt; straight away, at the &lt;strong&gt;end of the article&lt;/strong&gt; you'll find a link to the &lt;strong&gt;repository&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;However, I'll provide you with unique &lt;strong&gt;tips&lt;/strong&gt; and &lt;strong&gt;tricks&lt;/strong&gt; that can help you in creating your own game.&lt;/p&gt;




&lt;h2&gt;
  
  
  Playground
&lt;/h2&gt;

&lt;p&gt;Let's begin with the &lt;strong&gt;playground&lt;/strong&gt;. We can create it using a simple &lt;strong&gt;CSS Grid&lt;/strong&gt; or with &lt;strong&gt;HTML Canvas&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Both options are valid and each has its advantages.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Canvas&lt;/strong&gt; provides absolute control over rendering and animation pixel by pixel.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;CSS Grid&lt;/strong&gt; provides efficient and straightforward implementation.&lt;/p&gt;




&lt;blockquote&gt;
&lt;p&gt;So, if you want smooth snake movement, use &lt;strong&gt;Canvas&lt;/strong&gt;.&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  Snake
&lt;/h2&gt;

&lt;p&gt;If we used &lt;strong&gt;sprites&lt;/strong&gt;, we’d need to create a set of images for every segment of the snake in each possible position. That requires at least some drawing skills, which can be a major obstacle. That’s why we’ll aim for a simple model that even a complete graphic illiterate like me can manage.&lt;/p&gt;

&lt;p&gt;At first glance, it might seem the snake must be made of at least &lt;strong&gt;three parts&lt;/strong&gt;: the head, the body, and the tail. I naturally started building the game with these three segments. The first model was really just a simple sketch:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftm6vp3tmqxn9sebrmrqv.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Ftm6vp3tmqxn9sebrmrqv.png" alt="Snake first sketch" width="51" height="150"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I drew the snake in the direction of its initial position. I split it into 3 separate images and thought I just needed to rotate them based on the &lt;strong&gt;current movement&lt;/strong&gt; direction. And that’s when the problem appeared. The snake turned into squares at the points where it changed direction:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F45ka9w3f1pl0nz2lt36r.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F45ka9w3f1pl0nz2lt36r.png" alt="Snake direction change problem" width="250" height="250"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So a new strategy was needed. To achieve a natural, curved shape at the bend, the body of the snake had to be &lt;strong&gt;rounded on both sides&lt;/strong&gt;. But we must &lt;strong&gt;not forget&lt;/strong&gt; that our game field is a &lt;strong&gt;square grid&lt;/strong&gt;. If we just made the snake's body into a perfect &lt;strong&gt;circle&lt;/strong&gt;, the snake would look like a tapeworm:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcf3b19w471qwriflc9dm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fcf3b19w471qwriflc9dm.png" alt="Circles example" width="51" height="204"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That’s why I got the idea to make one side &lt;strong&gt;extend past&lt;/strong&gt; the grid and use an &lt;strong&gt;ellipse&lt;/strong&gt; instead of a circle. That could nicely &lt;strong&gt;connect&lt;/strong&gt; the snake segments and naturally round the turns:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fg8rdyc21zvbyt52eybqy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fg8rdyc21zvbyt52eybqy.png" alt="Ellipse in square" width="51" height="101"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fs8h1a720f49427085udm.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fs8h1a720f49427085udm.png" alt="Ellipse body parts" width="250" height="250"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here, the solution begins to take shape, the snake’s body is &lt;strong&gt;rounded on both sides&lt;/strong&gt;, so we &lt;strong&gt;no longer need&lt;/strong&gt; a separate tail segment.&lt;/p&gt;

&lt;p&gt;In the final version, we’ll change its color, add a decorative stripe, tweak the head a little, and suddenly… voilà!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The snake is drawn&lt;/strong&gt;. All it took was one head and one ellipse:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fapesaqj9jv7dai0jszmk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fapesaqj9jv7dai0jszmk.png" alt="Final version snake" width="250" height="250"&gt;&lt;/a&gt;&lt;/p&gt;




&lt;blockquote&gt;
&lt;p&gt;I drew the snake using the free online editor &lt;a href="https://pixilart.com" rel="noopener noreferrer"&gt;pixilart.com&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;




&lt;h2&gt;
  
  
  Let's start coding
&lt;/h2&gt;

&lt;p&gt;Each snake segment is just an instance of either the &lt;code&gt;head&lt;/code&gt; or &lt;code&gt;body&lt;/code&gt; image.&lt;br&gt;&lt;br&gt;
We place these segments into the &lt;code&gt;GameBoard&lt;/code&gt; grid using &lt;strong&gt;absolutely positioned HTML elements&lt;/strong&gt; and rotate them based on the current direction (0°, 90°, 180°, 270°).&lt;/p&gt;



&lt;p&gt;&lt;strong&gt;1. Segment Placement&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Each segment contains:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Grid coordinates (x, y)
&lt;/li&gt;
&lt;li&gt;Movement direction (&lt;code&gt;up&lt;/code&gt;, &lt;code&gt;down&lt;/code&gt;, &lt;code&gt;left&lt;/code&gt;, &lt;code&gt;right&lt;/code&gt;)
&lt;/li&gt;
&lt;li&gt;Type: &lt;code&gt;head&lt;/code&gt; or &lt;code&gt;body&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We can represent this in TypeScript like so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kr"&gt;interface&lt;/span&gt; &lt;span class="nx"&gt;SnakeSegment&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;x&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;
  &lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;
  &lt;span class="nx"&gt;direction&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;up&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;down&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;left&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;right&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
  &lt;span class="kd"&gt;type&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;head&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;body&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;&lt;strong&gt;2. Z-Index &amp;amp; Overlapping&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To create the "overlapping" effect where segments slightly layer over each other we use:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;position: absolute&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Slight pixel offset via &lt;code&gt;transform: translate(...)&lt;/code&gt; or tweaking &lt;code&gt;top/left&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;z-index&lt;/code&gt; based on order - head highest, last body segment lowest&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Example CSS:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.segment&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;position&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;absolute&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;32px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;32px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.head&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;z-index&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;100&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.body&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;z-index&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;var&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;--segment-order&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;&lt;strong&gt;3. Segment Rotation&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;To rotate each segment based on its direction, we use a utility function:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;getRotation&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;direction&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;up&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;right&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;down&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;left&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;switch &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;direction&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;up&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;rotate(0deg)&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;right&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;rotate(90deg)&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;down&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;rotate(180deg)&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;left&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;rotate(270deg)&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;p&gt;&lt;strong&gt;Storing Turn Points&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When the snake turns, we must remember where the change happened so that each segment turns when it reaches that same point.&lt;/p&gt;

&lt;p&gt;We'll implement a &lt;strong&gt;FIFO queue&lt;/strong&gt; of turn points:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kr"&gt;interface&lt;/span&gt; &lt;span class="nx"&gt;TurnPoint&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;x&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;
  &lt;span class="nx"&gt;y&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kr"&gt;number&lt;/span&gt;
  &lt;span class="nx"&gt;newDirection&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;up&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;right&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;down&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="o"&gt;|&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;left&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each segment checks against these &lt;code&gt;TurnPoints&lt;/code&gt;. If it matches its current &lt;code&gt;(x, y)&lt;/code&gt;, it changes direction accordingly.&lt;/p&gt;

&lt;p&gt;Once the last segment passes a turn point, we remove it from the queue.&lt;/p&gt;




&lt;p&gt;The implementation of core game logic such as collisions, movement, and snake control is the same as in any other snake game, so we won’t go into detail here.&lt;/p&gt;




&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;I hope you’ll enjoy this unique little snake and that you'll ride many happy pixels with it!&lt;/p&gt;

&lt;p&gt;As promised, you can find the full project &lt;a href="https://github.com/SpekCezStolicku/snakeGame" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;You can also play the game online right away &lt;a href="https://spekcezstolicku.github.io/snakeGame/" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;If there’s interest, I’ll gladly prepare a follow-up with a more detailed explanation.&lt;/p&gt;

&lt;p&gt;Wishing everyone lots of success in coding! :)&lt;/p&gt;

</description>
      <category>snake</category>
      <category>gamedev</category>
      <category>javascript</category>
      <category>vue</category>
    </item>
  </channel>
</rss>
