I know this is probably overly simple but I am terrible with math.
This is a section from a game I'm attempting with PyGame. Instead of using pixels for coordinates I have my own render function that uses blocks(actually just cnverts block value to pixels), which are 32x32 pixels, so it's easier to make levels. At least I think it will be. :S
Like the title says, if I accidentally put in a pixel value that is not a multiple of 32, my code will raise a ValueError. Instead I want it to round the pixel value to the nearest multiple of 32 and just warn me that it is incorrect.
class graphics(): def __init__(self): pass def render(self, sprites): for sprite, coord in sprites: surface.blit(sprite, (coord, coord)) pygame.display.update() def PTB(self, pixels): #Pixels to blocks if pixels == 1024: return 1024/32 if pixels not in range(0, 1024, 32): raise ValueError("PTB: Pixels not a multiple of 32.") #instead of an error, round to nearest multiple else: return pixels / 32 def BTP(self, blocks): #Blocks to pixels return blocks * 32 gfx = graphics()
Edited by WildBamaBoy: n/a