import pygame
import random
WIDTH = 500
HEIGHT = 500
FPS = 5
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
RED = (255, 0, 0)
GREEN = (0, 255, 0)
BLUE = (0, 0, 255)
pygame.init()
screen = pygame.display.set_mode((WIDTH, HEIGHT))
clock = pygame.time.Clock()
speedY = 0
speedX = random.randint(0,19)*25
running = True
state = []
for index in range(0,400,1):
state.append(1)
for index in range(0,20,1):
state[19*index +(index-1) + 20] = 2
index_X = []
for index in range(0,20,1):
index_X.append(20)
flag_down = 1
while running:
clock.tick(FPS)
for event in pygame.event.get():
if (speedY < 0): speedY = 0
if (speedY > 475):speedY = 475
if event.type == pygame.QUIT:
running = False
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_LEFT and speedX > 0:
speedX -= 25
if event.key == pygame.K_RIGHT and speedX < 475:
speedX += 25
if event.type == pygame.KEYUP:
if event.key == pygame.K_LEFT and speedX > 0:
speedX -= 25
if event.key == pygame.K_RIGHT and speedX < 475:
speedX += 25
screen.fill(BLACK)
counter = 0
for it_1 in range(0,500,25):
for it_2 in range(0,500,25):
if (state[counter]==1):
pygame.draw.rect(screen,WHITE, (it_1,it_2,24,24))
if (state[counter]==2):
pygame.draw.rect(screen,RED, (it_1,it_2,24,24))
counter = counter + 1
pygame.draw.rect(screen,RED, (speedX,speedY,24,24))
pygame.display.flip()
speedY = speedY + 25
if speedY > 475:
x = speedX//25
print(index_X[x])
if (state[19*x +(x-1) + index_X[x]] == 2):
index_X[x] -= 1
state[19*x +(x-1) + index_X[x]] = 2
speedY = 0
speedX = random.randint(0,19)*25
pygame.quit()
|