Today’s adventure started with making the foyer room look nicer. Yesterday I started creating custom textures for the game using Libresprite. I created the floor which took me longer than it should’ve. Today I made a door and quickly ran into an issue.
The idea was to show one door for each room the foyer is connected to but the door texture was only created for the bottom edge of the room. It also looked pretty small so I decided to add a way to scale and mirror the images.
Fortunately LOVE2D already has a scale_x and scale_y parameter for the draw method. This method also takes in negative values for mirroring so most of my work here was done for me. All i had to do was alter the legend system where each character was mapped to an image. Now it has optional width and height parameters which are the number of cells that image will take.
I thought I was done here but running the game proved otherwise. LOVE’s draw method treats the top left corner as origin so all images are drawn relative to that. Previously this was hard coded to move the cell’s center to the top left which was fine for the use case but when the scale is negative LOVE draws the image on the opposite side of where it wouldve been with a positive scale factor. This math look me some trial and error (evidence shown here) but in the end I figured out a formula to make it work.
px = gx + (col -1 + math.abs(w)) * cell
here px is the x coordinate of the image’s position, gx is the offset of the room view from the left edge of the screen, col is the column number of the current image, w is the desired width of the image and cell is the size of 1 square.
Solving problems like these remind me of the “joy of programming” we had back before AI and the dopamine hits after the hours of debugging finally pay off. It reminds me of why I went into software engineering in the first place: to solve problems, not to prompt an AI to fix it and make no mistakes.
I have no doubt that claude code would’ve taken over 5 minutes to solve this problem and its solution might even be better than mine but I think that blocks my learning as it removes all struggle from solving a task.