Snake

22/07/2026

I tried to make Snake in Love2D

function love.load() local window_x = 500 local window_y = 300 love.window.setMode(window_x, window_y) math.randomseed(os.time()) Max_x = window_x / 10 - 1 Max_y = window_y / 10 - 1 Snake = { {1, 1} } Dir = { x = 1, y = 0 } Update = 0.1 Time = 0 Score = 0 spawnApple() end function love.keypressed(key) if key == "w" then Dir = { x = 0, y = -1 } elseif key == "s" then Dir = { x = 0, y = 1 } elseif key == "a" then Dir = { x = -1, y = 0 } elseif key == "d" then Dir = { x = 1, y = 0 } end end function spawnApple() while true do Apple_x = math.random(0, Max_x) Apple_y = math.random(0, Max_y) local on_snake = false for _, segment in ipairs(Snake) do if segment[1] == Apple_x and segment[2] == Apple_y then on_snake = true break end end if not on_snake then break end end end function love.update(dt) Time = Time + dt if Time < Update then return end Time = 0 local head = Snake[#Snake] local new_head = { head[1] + Dir.x, head[2] + Dir.y } if new_head[1] < 0 or new_head[1] > Max_x or new_head[2] < 0 or new_head[2] > Max_y then print("Damn! Score: " .. Score) love.event.quit("restart") return end for _, segment in ipairs(Snake) do if segment[1] == new_head[1] and segment[2] == new_head[2] then print("Damn! Score: " .. Score) love.event.quit("restart") return end end table.insert(Snake, new_head) if new_head[1] == Apple_x and new_head[2] == Apple_y then Score = Score + 1 spawnApple() else table.remove(Snake, 1) end end function love.draw() love.graphics.setColor(1, 1, 1) for _, segment in ipairs(Snake) do love.graphics.rectangle("fill", (segment[1] - 1) * 10, (segment[2] - 1) * 10, 10, 10) end love.graphics.setColor(1, 0.48, 0.91) love.graphics.rectangle("fill", (Apple_x - 1) * 10, (Apple_y - 1) * 10, 10, 10) end

It is quite simple. We have an array that stores the position of each part of the snake in a grid. Then, everytime we update, we grab the snake head position, calculate the next direction, and check the conditions one by one

1. If we touch the walls, we end the game and restart.

2. If we touch ourselves, also end the game.

3. If the next position is the apple, generate a new apple ( not colliding with the snake ), and add the next head to the array.

4. If all of the above is false, append the new head, and remove the tail to stimulate moving.

That's all. Add a score counter, and done! Pretty good for an evening.

( There're still edge cases that I don't bother with, such as: sometimes the apple bugs out and doesn't spawn again, what would happen if the snake turns around into itself ( might be fixed by changing the direction only if the next direction is not opposite of the current direction and the snake is longer than 2 blocks ), etc... )

Code blocks!

17/07/2026

Hi it's me again.

I've implemented code blocks!

function fact(n) if n == 0 then return 1 else return n * fact(n-1) end end

Not super good. But it works. And also, no HTML code, since I can't inject HTML into HTML without something breaking.

( No it's not "not good" it's horrendous look at the source code. I just added a tag to straight up inject into the HTML without any formatting. How the hell did people implement this thing it's so hard. )


A Humble Start

16/07/2026

Hello, and welcome to my blog!

After seeing all the cool stuff that people write on their blogs, I've decided to make my own little space!

This website is powered by a small, simple static site generator written in Lua, mainly for me to learn and experiment. At first, the idea was to have a "blogs" folder with text files inside. Each file was intended to be a blog post. I would then iterate over each file and process them one by one, but I realised that I couldn't control the order in which the posts appeared, so that idea was scrapped.

Now we use a single file for all the posts. The format is very simple: HTML tag + space + content. h2 should be used for the blog title, h3 for the date, and p for the content. After that, I can just do lua proc.lua and boom—the posts are live on the web!

I might extend the generator for code blocks and a separate site for each post later, but for now, this is good enough.

Bye!