Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pygame
- import random
- pygame.init()
- screen = pygame.display.set_mode([500, 500]) # задаем размер игрового дисплея
- runnig = True
- red = 0
- green = 0
- blue = 0
- x = y = 250
- speed = 0.1
- keyflag = False
- direction = 0 # 1 - x+1 2 x-1 3 y+1 4 y-1
- keys_direction = (pygame.K_a, pygame.K_d, pygame.K_w, pygame.K_s)
- while runnig:
- for event in pygame.event.get(): # получаем события для обработки
- if event.type == pygame.QUIT:
- runnig = False
- if event.type == pygame.KEYDOWN:
- keyflag = True
- if event.key == pygame.K_w:
- direction = 4
- if event.key == pygame.K_s:
- direction = 3
- if event.key == pygame.K_a:
- direction = 2
- if event.key == pygame.K_d:
- direction = 1
- if event.type == pygame.KEYUP:
- if event.key in keys_direction:
- keyflag = False
- direction = 0
- if keyflag and direction:
- if direction == 1:
- x += speed
- elif direction == 2:
- x -= speed
- elif direction == 3:
- y += speed
- elif direction == 4:
- y -= speed
- screen.fill((255, 255, 255)) # заполняем фон цветом (Red,Green,Blue)
- red = random.randint(0, 255)
- green = random.randint(0, 255)
- blue = random.randint(0, 255)
- pygame.draw.circle(screen, (red, green, blue), (x, y), 30)
- # поверхность куда рисуем, цвет которым рисуем, центр, радиус
- pygame.display.flip()
- pygame.quit() # закрытие ресурсов после выхода из игрового цикла
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement