I'd like to create a 2D environment in which the top & bottom and left & right are connected (similar to a Torus or Doughnut). However, rather than doing a check on an object's x/y coordinate every frame, I'd like to simulate it using integer overflow.
While normal iteration (as shown in the sample code below) can be done, it may be slightly more effective (though dangerous) to simply enable overflow on some variables, especially when dealing with hundreds or thousands of objects in each frame/iteration.
I can find some examples which also simulate integer overflow in Python like this. However, I'm looking for something that can overflow just by enabling overflow in certain variables and skipping the checks in general.
# With normal checking of every instance
import random
width = 100
height = 100
class item():
global width, height
def __init__(self):
self.x = random.randint(0, width)
self.y = random.randint(0, height)
items = [item for _ in range(10)] # create 10 instances
while True:
for obj in items:
obj.x += 10
obj.y += 20
while obj.x > width:
obj.x -= width
while obj.y > height:
obj.y -= height
while obj.x < width:
obj.x += width
while obj.y < height:
obj.y += height
I'd like to simulate integer overflow for only some certain classes/objects. Is there a way to have some variables automatically overflow and loop back to their min/max values?