class Platform(Object): platforms_image = [load_image('platform1.png', (255, 255, 255)), load_image('platform2.png')] def __init__(self, x=-80, y=-18): global platforms divider = random.randint(1, 11) if count_platforms > 1 and count_platforms % 10 == 0: Platform.platforms_image.append(load_image('platform3.png')) if count_platforms > 10 and count_platforms % divider == 0: Enemy(platforms[-1][0] + 5, platforms[-1][1] - 35) if count_platforms > 500: Platform.platforms_image = [load_image('platform3.png')] platform_image = random.choice(Platform.platforms_image) super().__init__(x, y, platform_image, platform_sprites) def update(self): global platforms, cameray, count_platforms, generation self.rect = self.rect.move(0, cameray) check = platforms[1][1] + cameray platforms[1][1] += cameray global HEIGHT if check > HEIGHT and generation: platforms.append([random.randint(0, 720), platforms[-1][1] - 40]) Platform(platforms[-1][0], platforms[-1][1]) platforms.pop(0) count_platforms += 1
def __init__(self, x=-80, y=-18): global platforms divider = random.randint(1, 11) if count_platforms > 1 and count_platforms % 10 == 0: Platform.platforms_image.append(load_image('platform3.png')) if count_platforms > 10 and count_platforms % divider == 0: Enemy(platforms[-1][0] + 5, platforms[-1][1] - 35) if count_platforms > 500: Platform.platforms_image = [load_image('platform3.png')] platform_image = random.choice(Platform.platforms_image) super().__init__(x, y, platform_image, platform_sprites)
class Sceleton(Object): skeleton_image = load_image('skeleton.png') skeleton_jump = [load_image('skeleton1.png'), load_image('skeleton2.png'), load_image('skeleton3.png')] game_over = False def __init__(self, x, y): super().__init__(x, y, Sceleton.skeleton_image, sceleton_sprite, 8, 46) self.isJump = False self.jump_count = 13 def update(self, x=0, shot=False): global WIDTH, HEIGHT, cameray, score, score_text, font if self.isJump: if self.jump_count >= 0: self.rect = self.rect.move(0, -self.jump_count) self.jump_count -= 1 score += 1 elif self.jump_count < 0: self.isJump = False self.jump_count = 13 self.image = Sceleton.skeleton_jump[2] score -= 5 else: score -= 1 if (pygame.sprite.spritecollideany(self, platform_sprites) or self.isJump) and not Sceleton.game_over: self.isJump = True self.image = Sceleton.skeleton_jump[0] else: self.rect = self.rect.move(0, self.jump_count) self.image = Sceleton.skeleton_jump[2] if pygame.sprite.spritecollideany(self, enemy_sprites): Sceleton.game_over = True if x != 0: if 0 < x < WIDTH - 24: self.rect.x = x if shot: Shell(self.rect.x, self.rect.y) if self.rect.y + 25 >= HEIGHT: game_over() if int(score_text) < score: score_text = str(score) string_rendered = font.render(score_text, 1, pygame.Color('black')) intro_rect = string_rendered.get_rect() intro_rect.x, intro_rect.y = 0, 0 screen.blit(string_rendered, intro_rect)
def start_screen2(): intro_text = [ "Вы выбрались из котла!", "", "Теперь вам нужно пробежать мимо чертовых руин!", "Для начала игры нажмите 1" ] fon = pygame.transform.scale(load_image('fon2.jpg'), (WIDTH, HEIGHT)) screen.blit(fon, (0, 0)) font = pygame.font.Font(None, 30) text_coord = 50 for line in intro_text: string_rendered = font.render(line, 1, pygame.Color('white')) intro_rect = string_rendered.get_rect() text_coord += 10 intro_rect.top = text_coord intro_rect.x = 100 text_coord += intro_rect.height screen.blit(string_rendered, intro_rect) while True: for event in pygame.event.get(): if event.type == pygame.QUIT: terminate() elif event.type == pygame.KEYDOWN and event.key == pygame.K_1: pygame.mixer.Sound('data/level_audio.wav').play() level() # начинаем игру pygame.display.flip() clock.tick(fps)
class Enemy(Object): enemy_image = load_image('gargoyle.png') def __init__(self, x, y): global WIDTH super().__init__(x, y, Enemy.enemy_image, enemy_sprites) self.jump_count = 5 self.is_Jump = False def update(self): global WIDTH, cameray, score if pygame.sprite.spritecollideany(self, platform_sprites): self.is_Jump = True else: self.rect = self.rect.move(0, self.jump_count) if pygame.sprite.spritecollideany(self, shell_sprites): self.kill() score += 10 if self.is_Jump: if self.jump_count >= 0: self.rect = self.rect.move(0, -self.jump_count) self.jump_count -= 1 else: self.is_Jump = False self.jump_count = 5
class Shell(Object): shell_image = load_image('bone3.png') def __init__(self, x, y): self.image_orig = Shell.shell_image super().__init__(x, y, Shell.shell_image, shell_sprites) self.rot = 0 self.rot_speed = random.randrange(-16, 16) def update(self): self.rect = self.rect.move(0, -10) self.rot = (self.rot + self.rot_speed) % 360 self.image = pygame.transform.rotate(self.image_orig, self.rot)
class Mist(Object): mist_image = [load_image(f'mist{i}.png') for i in range(1, 9)] index = 0 def __init__(self): super().__init__(0, 0, Mist.mist_image[Mist.index], mist_sprite) def update(self): Mist.index += 1 if Mist.index == 63: Mist.index = 0 else: self.image = Mist.mist_image[Mist.index // 8]
start() def background_scroll(x1, x2, speed=5): x1 -= speed x2 -= speed screen.blit(background, (x1, y_first_image)) screen.blit(background, (x2, y_second_image)) if x1 < -WIDTH: x1 = WIDTH if x2 < -WIDTH: x2 = WIDTH return x1, x2 background = load_image('postapocalypse1.png') background_size = background.get_size() background_rect = background.get_rect() background_width, background_height = background_size x_first_image, y_first_image = WIDTH, 0 x_second_image, y_second_image = x_first_image * 2, 0 def start_screen2(): intro_text = [ "Вы выбрались из котла!", "", "Теперь вам нужно пробежать мимо чертовых руин!", "Для начала игры нажмите 1" ]
def __init__(self, x, y): super().__init__(objects_sprites) self.image = load_image('spear.png') self.rect = self.image.get_rect() self.rect = self.rect.move(x, y) self.speed_y = 2
def __init__(self, x, y): super().__init__(objects_sprites, x, y, load_image(r'Obstacles\1.png'), 5, 1)
def property(self): if len(self.frames) < 6: self.frames.append(load_image(r'Obstacles\22.png')) self.frames.append(load_image(r'Obstacles\23.png'))
def __init__(self, x, y): y = 440 super().__init__(objects_sprites, x, y, load_image(r'Obstacles\4.png'), 1, 1)