Created
April 20, 2020 21:29
-
-
Save LevBravE/aaab4ac9997b7715561c27dd89b3d7df 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 | |
size = width, height = 400, 300 | |
screen = pygame.display.set_mode(size) | |
def load_image(name, color_key=None): | |
fullname = os.path.join('data', name) | |
image = pygame.image.load(fullname).convert() | |
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 | |
class Bomb(pygame.sprite.Sprite): | |
image = load_image("bomb.png") | |
def __init__(self, group): | |
# ÐЕОБХОДИМО вызвать конÑтруктор родительÑкого клаÑÑа Sprite | |
super().__init__(group) | |
self.image = Bomb.image | |
self.rect = self.image.get_rect() | |
self.rect.x = random.randrange(width) | |
self.rect.y = random.randrange(height) | |
def update(self): | |
self.rect = self.rect.move(random.randrange(3) - 1, random.randrange(3) - 1) | |
clock = pygame.time.Clock() | |
# группа, ÑÐ¾Ð´ÐµÑ€Ð¶Ð°Ñ‰Ð°Ñ Ð²Ñе Ñпрайты | |
all_sprites = pygame.sprite.Group() | |
for i in range(50): | |
# нам уже не нужно даже Ð¸Ð¼Ñ Ð¾Ð±ÑŠÐµÐºÑ‚Ð°! | |
Bomb(all_sprites) | |
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) | |
all_sprites.update() | |
pygame.display.flip() | |
pygame.quit() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment