In a big city full of multi-story buildings, pawns can walk between them. If they walk behind a building, the player won’t be able to see them, meaning they might miss them entirely or be unable to select them. This is a classic visibility problem. There are various solutions to it, but most of the…

UI: pygame-gui vs imgui_bundle
When it comes to building in-game UIs in Python, pygame-gui and imgui_bundle take two very different approaches. I’ve tried both, and while each has its strengths, they suit different needs and workflows. pygame-gui is much easier to drop into a Pygame project. It runs in the same Pygame window, supports importing images for things like…

Drawing opaque and semi-transparent pixels in the shader
I was making a selection marker decal and to make it appear smoothly, I noticed a broader issue when rendering alpha-0 and alpha non-0 pixels in the shader. I had to adjust my frag shader to draw opaque pixels in a separate pipeline from semi-transparent pixels: Later, I encountered a smaller issue of y-sorting it…

Pathfinding
One of the more interesting aspects of game development is to pick and implement a variety of pathfinding algos. For now I settled on three kinds of pathfinding algos for the game: Traffic A Star This version of A* is tailored specifically for vehicles navigating city roads. Instead of scanning the full grid like traditional…

Y-Sorting in Isometric Games
In isometric games, rendering order is crucial. Objects closer to the camera should appear in front of objects further away. This is where Y-sorting comes in—it ensures that when drawing sprites, the objects in the back are rendered first, and those in the front are drawn last. Without proper Y-sorting, objects can overlap incorrectly, breaking…

Moving to OpenGL: Instance Rendering with ModernGL
After trying blitting and SDL2 rendering in Pygame, it was clear that neither would be enough for large-scale NPC rendering. Even with optimizations like culling non-visible NPCs, FPS would drop too fast as soon as I started adding animations or game logic. So, I finally switched to instance rendering in OpenGL using ModernGL, and the…

Rendering with SDL2
As blitting in pygame turned out to be not enough, it’s time to see how pygame’s experimental SDL2 module compares. When comparing FPS between the two approaches, it’s important to keep in mind the non-linear nature of FPS. Also, worth noting that as of writing this SDL2 module in pygame is still in development/experimental. Pygame’s…

Non-linear relationship between FPS and frame-to-frame time interval (Δt)
Before I implement SDL2 rendering, it’s worth reminding ourselves what FPS actually is and how it is measured as this is the metric I’ll be using to benchmark performance. It’s important because you can’t compare FPS gain from 30 to 60 against a gain 300 to 330. FPS (Frames Per Second) refers to how many…

Optimizing Rendering by Blitting Visible Entities Only
A few months ago, I optimized blitting a lot. But wasn’t really satisfied with the results. I thought of giving up on pygame entirely. Yes, there is that experimental SDL2 wrapper to try but I was a bit disappointed with pygame’s rendering capabilities altogether so didn’t pin my hopes to it. I went looking for…

FPS and a Quick Map POC: Blitting Buildings, and NPCs
So, I threw together a quick map proof of concept and some mechanics for populating it with buildings and randomly spawned NPCs. Then I implemented a camera system with zooming, and honestly? It was way easier than I expected. Barely took any code at all. Python’s ability to iterate fast is an absolute game-changer. But,…