Created
April 20, 2020 21:26
-
-
Save LevBravE/00912018f64e183448928572da467dcf to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import random | |
import pygame | |
def load_image(name, color_key=None): | |
fullname = os.path.join('data', name) | |
try: | |
image = pygame.image.load(fullname).convert() | |
except pygame.error as message: | |
print('Cannot load image:', name) | |
raise SystemExit(message) | |
if color_key is not None: | |
if color_key == -1: | |
color_key = image.get_at((0, 0)) | |
image.set_colorkey(color_key) | |
else: | |
image = image.convert_alpha() | |
return image | |
size = width, height = 400, 300 | |
screen = pygame.display.set_mode(size) | |
clock = pygame.time.Clock() | |
# группа, ÑÐ¾Ð´ÐµÑ€Ð¶Ð°Ñ‰Ð°Ñ Ð²Ñе Ñпрайты | |
all_sprites = pygame.sprite.Group() | |
# изображение должно лежать в папке data | |
bomb_image = load_image("bomb.png") | |
for i in range(50): | |
# можно Ñразу Ñоздавать Ñпрайты Ñ ÑƒÐºÐ°Ð·Ð°Ð½Ð¸ÐµÐ¼ группы | |
bomb = pygame.sprite.Sprite(all_sprites) | |
bomb.image = bomb_image | |
bomb.rect = bomb.image.get_rect() | |
# задаем Ñлучайное меÑтоположение бомбочке | |
bomb.rect.x = random.randrange(width) | |
bomb.rect.y = random.randrange(height) | |
running = True | |
while running: | |
for event in pygame.event.get(): | |
if event.type == pygame.QUIT: | |
running = False | |
screen.fill(pygame.Color("white")) | |
all_sprites.draw(screen) | |
pygame.display.flip() | |
pygame.quit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment