i am making a simulator and i need every pixel of the pygame screen to be an int so i have some data like a pixel may be like 10000000 the first digit is the indicator that the pixel is loaded the second is if the pixel is explored and goes on. while creating the main city pixels i need to let the pixel know that it is occupied so i want to update the in to 11011010 while i do that it throws this error
Here the code
## Simple Python port - You need: pip install pygame. Note the code here is not efficient but it's made to be educational and easy
import numpy as np
import pygame
import random
sims = []
window_size = 600
pix = 10000000+np.zeros((window_size,window_size))
pygame.init()
window = pygame.display.set_mode((window_size, window_size))
###
green= 1
red = 2
blue= 3
yellow=4
magenta=5
cyan= 6
white=7
###
def draw(surface, x, y, color, size):
for i in range(0, size):
pygame.draw.line(surface, color, (x, y - 1), (x, y + 2), abs(size))
def px(x, y, c):
return {"x": x, "y": y, "vx": 0, "vy": 0, "color": c}
def randomxy():
return round(random.random() * window_size)
def simdoms():
tx,ty = randomxy(), randomxy()
print(pix[[ty],[tx]]+1)# here it runs ok while having the same tx and ty (stands for temp x)
print(tx,ty)
pix[[ty][tx]] = 11011010
green= px(tx,ty,(0,255,0))
tx, ty = randomxy(), randomxy()
red = px(tx,ty,(255,0,0))
pix[[ty-1][tx-1]]=11012010
tx, ty = randomxy(), randomxy()
blue= px(tx,ty,(0,10,255))
pix[[ty-1][tx-1]]=11013010
tx, ty = randomxy(), randomxy()
yellow= px(tx,ty,(255, 196, 0))
pix[[ty-1][tx-1]]=11014010
tx, ty = randomxy(), randomxy()
magenta= px(tx,ty,(242, 0, 202))
pix[[ty-1][tx-1]]=11015010
tx, ty = randomxy(), randomxy()
cyan= px(tx,ty,(0, 255, 195))
pix[[ty-1][tx-1]]=11016010
tx, ty = randomxy(), randomxy()
white= px(tx,ty,(255,255,255))
pix[[ty-1][tx-1]]=11017010
sims.append(green,red,blue,yellow,magenta,cyan,white)
print (pix)
simdoms()
run = True
while run:
window.fill(0)
for i in range(len(sims)):
draw(window, sims[i]["x"], sims[i]["y"], sims[i]["color"], 3)
for event in pygame.event.get():
if event.type == pygame.QUIT:
run = False
pygame.display.flip()
pygame.quit()
exit()

