I'm programming a game with moving boxes. I've done everything and got it to run and show up, however the boxes cannot go outside of the screen. I think it's something with the elifs or within them. Where is my error and how can I get them to move?
screen = pygame.display.set_mode( (640, 480) )
pygame.display.set_caption("Wahoo")
background = pygame.Surface(screen.get_size())
background = background.convert()
background.fill( (204,204,255) )
box1 = pygame.Surface((100,100))
box1 = box1.convert()
labelBox(box1, (153, 255, 255), "1")
box1X = 0 # The starting location for this box
box1Y = 0
moveBox1 = False # If True, this is the box that moves
box2 = pygame.Surface((100,100))
box2 = box2.convert()
labelBox(box2, (255, 255,153), "2")
box2X = 540 # The starting location for this box
box2Y = 0
moveBox2 = False # If True, this is the box that moves
box3 = pygame.Surface((100,100))
box3 = box3.convert()
labelBox(box3, (153, 255, 153), "3")
box3X = 540 # The starting location for this box
box3Y = 380
moveBox3 = False # If True, this is the box that moves
box4 = pygame.Surface((100,100))
box4 = box4.convert()
labelBox(box4, (255, 153, 204), "4")
box4X = 0 # The starting location for this box
box4Y = 380
moveBox4 = False # If True, this is the box that moves
clock = pygame.time.Clock()
keepGoing = True
clock.tick(30) # Maintain 30 frame per second refresh.
for event in pygame.event.get() :
if event.type == pygame.QUIT :
keepGoing = False
elif event.type == pygame.MOUSEBUTTONDOWN :
box1X=0
box1Y=0
box2X=540
box2Y=0
box3X=540
box3Y=380
box4X=0
box4Y=380
elif event.type == pygame.KEYDOWN :
if event.key == pygame.K_ESCAPE :
keepGoing = False
elif event.key == pygame.K_1 :
moveBox1==True
moveBox2==False
moveBox3==False
moveBox4==False
elif event.key == pygame.K_2 :
moveBox2==True
moveBox3==False
moveBox4==False
moveBox1==False
elif event.key == pygame.K_3 :
moveBox3==True
moveBox4==False
moveBox2==False
moveBox1==False
elif event.key == pygame.K_4:
moveBox4==True
moveBox1==False
moveBox2==False
moveBox3==False
elif event.key == pygame.K_LEFT :
if moveBox1==True and box1X>=30:
box1X=box1X-30
elif box2==True and box2X>=30:
box2=box2X-30
elif box3==True and box3X>=30:
box3=box3X-30
elif box4==True and box4X>=30:
box4=box4X-30
elif event.key == pygame.K_RIGHT :
if moveBox2==True and box2X<=540:
box2X=box2X+540
elif box3==True and box3X<=540:
box3=Box3X+540
elif box4==True and box4X<=540:
box4=box4X+540
elif box1==True and box1X<=540:
box1=box1X+540
elif event.key == pygame.K_UP :
if moveBox3==True and box3Y<=580:
box3Y==box3Y+580
elif box4==True and box4Y>=580:
box4=box4Y+580
elif box2==True and box2Y>=580:
box2=box2Y+580
elif box1==True and box1Y>=580:
box1=box1Y+580
elif event.key == pygame.K_DOWN :
if moveBox4==True and box4Y>=380:
box4Y=box4Y-380
elif box1==True and box1Y>=580:
box1=box1Y-380
elif box2==True and box2Y>=580:
box2=box2Y-380
elif box3==True and box3Y>=580:
box3=box3Y-380
screen.blit(background, (0,0))
screen.blit(box1, (box1X, box1Y))
screen.blit(box2, (box2X, box2Y))
screen.blit(box3, (box3X, box3Y))
screen.blit(box4, (box4X, box4Y))
pygame.display.flip()