Day 2: I DID IT. ASPECT RATIOS. Well, not really.

I know I'm supposed to make a game, but I've spent my entire afternoon trying to make my brain think about aspect ratios.

Every engine I've used so far had some sort of automatic scaling for when the user resized their window. But, python? Yeah, forget about any kind of help.

This was a pain. There was absolutely 0 documentation about how to implement this on Arcade, which is the module I'm using. I want my game to keep it's aspect ratio no matter how the user resizes the window, by adding black bars to the sides. It took me 45 minutes for my brain to use 5% of it's processing power and realize this:

(orig height/orig width) = (new height/new width)
Therefore
(orig height/orig width) * new width = new height
(orig width/orig height) * new height = new width

So simple, but my small brain kept searching for complicated equations, algorithms and formulas that were just not necessary.

Afterwards, I spend a good time looking at the docs. That set_viewport function wasn't even that complicated. But my brain refuses to believe things can be simple. I'm kind of contradicting myself now, aren't I?

That was not the end of it. This is the code I made:

if width <= height:
    # Width is smaller or equal
    r_width = width
    s_width = 0
    r_height= math.ceil((500/800)*width)
    s_height = math.floor((height - r_height)/2)
    self.set_viewport(-s_width, r_width+s_width, -s_height, r_height+s_height)
    print(f"\nResized to {width}, {height}.\nWidth is smaller.\nResult is {width}, {(500/800)*width}\n")
else:
    # Height is smaller
    print(f"\nResized to {width}, {height}.\nHeight is smaller.\nResult is {(800/500)*height}, {height}\n")
    r_width = math.ceil((800/500)*height)
    s_width = math.floor((width - r_width)/2)
    r_height= height
    s_height = 0
    self.set_viewport(-s_width, r_width+s_width, -s_height, r_height+s_height)

It basically tries to make the content inside as big as possible within the space available in the window. But since I'm not accounting for aspect ratios in the conditions, it doesn't detect when it has to switch modes very well. Also, making the width smaller breaks it and doesn't correctly center or scale the content. Here's a picture to embarrass myself.

My failure

TL;DR: Two days and I can't even handle aspect ratios. I better calm down and lower expectatives. Good luck to everyone!