import pygame
import random
pygame.init()
back = (200, 255, 255)
window = pygame.display.set_mode((500, 500))
pygame.display.set_caption("Поймай кнопку!")
window.fill(back)
clock = pygame.time.Clock()
game_over = False
YELLOW = (255, 255, 0)
DARK_BLUE = (0, 0, 100)
BLUE = (80, 80, 255)
GREEN = (0, 255, 0)
RED = (255, 0, 0)
class Area():
def __init__(self, x=0, y=0, width=10, height=10, color=None):
self.rect = pygame.Rect(x, y, width, height)
self.fill_color = back
if color:
self.fill_color = color
def color(self, new_color):
self.fill_color = new_color
def fill(self):
pygame.draw.rect(window, self.fill_color, self.rect)
def outline(self, frame_color, thickness):
pygame.draw.rect(window, frame_color, self.rect, thickness)
def collidepoint(self, x, y):
return self.rect.collidepoint(x, y)
class Picture(Area):
def __init__(self, filename, x = 0, y = 0, width = 10, height = 10):
Area.__init__(self, x = x, y = y, width = width, height = height, color = None)
self.image = pygame.image.load(filename)
def draw(self):
window.blit(self.image, (self.rect.x, self.rect.y))
racket_x = 200
racket_y = 330
ball = Picture('ball.png', 160, 200, 50, 50)
platform = Picture('platform.png', racket_x, racket_y, 100, 30)
start_x = 5
start_y = 5
count = 9
monsters= []
for i in range(3):
y = start_y + (55 * i)
x = start_x + (27.5 * i)
for j in range(count):
d = Picture('enemy.png', x, y, 50, 50)
monsters.append(d)
x = x + 55
count -= 1
while not game_over:
ball.fill()
platform.fill()
for event in pygame.event.get():
if event.type == pygame.QUIT:
game_over = True
for m in monsters:
m.draw()
platform.draw()
ball.draw()
pygame.display.update()
clock.tick(40)
while not game_over:
for event in pygame.event.get():
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_RIGHT:
move_right = True
elif event.type == pygame.KEYUP:
if event.key == pygame.K_RIGHT:
move_right = False
if move_right:
platform.rect.x += 3
while not game_over:
for event in pygame.event.get():
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_LEFT:
move_left = True
elif event.type == pygame.KEYUP:
if event.key == pygame.K_LEFT:
move_left = False
if move_right:
platform.rect.x += 3