def start(): # При старте игры global cursor pygame.mouse.set_visible(False) # Скрыть курсор Background(general.load_image('background.jpg'), Transform((0, 0))) # Фон Background(general.load_image('background2.png'), Transform((-100, 400)), 0.1) general.load_map() # Загрузка карты player = Pers(Transform((200, 600))) # Игрок general.player = player general.camera = Camera(Transform((0, 0), parent=player.transform_), offset=(-900, -540)) # Камера player.select_weapon(Weapon('pistol', player.transform_)) # Выбор оружия # Разбросанные по карте оружия Weapon('ak_47', pos=(2300, 950)) Weapon('shotgun', pos=(2450, 950)) Weapon('rifle', pos=(2600, 950)) Weapon('machine gun', pos=(14800, 1650)) Weapon('p90', pos=(15000, 1650)) Weapon('sniper', pos=(15200, 1650)) cursor = Background(load_image('cursor.png'), Transform( (100, 100))) # курсор мыши
def start_screen(): # Выполняется до начала игры # создание кнопок menu_buttons = [ Sprite(general.load_image('fon.jpg'), Transform((0, 0))), Sprite(general.load_image('title.png'), Transform((560, 80))), Button(general.load_image('btn_start.png'), Transform((710, 500)), start_game, general.buttons_group), Button(general.load_image('btn_exit.png'), Transform((760, 700)), terminate, general.buttons_group) ] while is_menu: for event in pygame.event.get(): if event.type == pygame.QUIT: terminate() elif event.type == pygame.MOUSEBUTTONDOWN: general.buttons_group.update(event.pos) elif event.type == pygame.KEYDOWN: if event.key == pygame.K_ESCAPE: terminate() general.all_sprites.update() general.all_sprites.draw(general.screen) pygame.display.flip() general.clock.tick(general.FPS) # удаление кнопок for btn in menu_buttons: btn.kill()
def game_over(): # Проигрыш Background(general.load_image('fon.jpg'), Transform((0, 0))) Background(general.load_image('gameover.png'), Transform((560, 80))) while True: for event in pygame.event.get(): if event.type != pygame.MOUSEMOTION: terminate() general.all_sprites.update() general.all_sprites.draw(general.screen) pygame.display.flip() general.clock.tick(general.FPS)
def __init__(self, controller): controller = open(f'data/Animations/{controller}.txt', 'r').read() self.animations = [] for ani in controller.split('\n'): ani = ani.split(';') self.animations.append(AnimationClip(general.load_image(ani[0]), ani[1], ani[2], eval(ani[3]))) self.current_ani = self.animations[0]
def __init__(self, entrance, background_png_name, name, collectibles, furniture): png_name = os.path.join("inside_houses", background_png_name) self.entrance = ScaledRect.from_rect(entrance) self.background = load_image(png_name, return_rect=False) self.name = name self.collectibles = collectibles self.furniture = { k: ScaledRect.from_rect(v) for k, v in furniture.items() } exit_x = 59 exit_y = self.background.get_height() // SCALE - 25 exit_width = self.background.get_width() // SCALE - 59 * 2 exit_height = 15 self.exit_area = ScaledRect(exit_x, exit_y, exit_width, exit_height) self.walls = ScaledRect(11, 63, 140, 175)
def end(self): if not self.countdown.ended: self.countdown.pause() self.state = GAME_FADE_OUT self.fade_out_timer.start(GAME_FADE_OUT_TIME) # gets the end image if not self.character.escaped: self.end_image = load_image("endings/stay_death.png", return_rect=False) elif sum(self.character.items.values()) <= 2: self.end_image = load_image("endings/missing_lots_death.png", return_rect=False) elif self.character.has_no_items("filled_water_skin"): self.end_image = load_image("endings/thirst_death.png", return_rect=False) elif self.character.has_no_items("ugly_green_scarf"): self.end_image = load_image("endings/cold_death.png", return_rect=False) elif self.character.has_no_items("bread", "cheese", "jerky"): self.end_image = load_image("endings/starvation_death.png", return_rect=False) elif self.character.has_no_items("bandages", "bow_arrow", "cheese"): self.end_image = load_image("endings/bandits_death.png", return_rect=False) elif self.character.has_no_items("pileogold"): self.end_image = load_image("endings/no_money_death.png", return_rect=False) else: self.end_image = load_image("endings/win_happy.png", return_rect=False) self.end_image = pygame.transform.scale(self.end_image, SCREEN_SIZE) if DEBUG: print("ended!")
def __init__(self, png_name, x, y, convert_alpha=False): self.image, self.rect = load_image(png_name, convert_alpha) super().__init__() self.rect.x = x * SCALE self.rect.y = y * SCALE
def __init__(self, *png_names, flip=False): self.frames = tuple(load_image("avatar/MC-" + png_name, convert_alpha=True, flip=flip, return_rect=False) for png_name in png_names)
def __init__(self): # initialize the pygame module pygame.init() logo_name = os.path.join('assets', "logo.png") logo = pygame.image.load(logo_name) pygame.display.set_icon(logo) pygame.display.set_caption("Escape") self.screen = pygame.display.set_mode(SCREEN_SIZE) self.black_surface = self.screen.copy() self.black_surface.fill(pygame.Color("black")) # default font used for the timer self.font = pygame.font.Font(None, 100) self.subtext_font = pygame.font.Font(None, 25) self.notification_font = pygame.font.Font(None, 25) # specifies the middle of the screen self.character = Character("avatar/MC-front.png", 0, 0) self.camera = Coords(CHARACTER_START[X], CHARACTER_START[Y]) # saves the camera for when enering the building self.camera_save = None self.user_input = UserInput() # sound self.ambient = pygame.mixer.Sound("assets/ambient.wav") self.ambient_channel = pygame.mixer.Channel(1) self.wind = pygame.mixer.Sound("assets/wind.wav") self.wind.play(-1) # a shit ton of time related stuff self.clock = pygame.time.Clock() self.countdown = Countdown() self.ticker = Ticker() self.fade_in_timer = Timer() self.display_timer = Timer() self.notification_timer = Timer() self.fade_out_timer = Timer() # variables for when you're in some building self.current_building = None self.buildings = create_buildings() self.well_area = ScaledRect(208, 354, 60, 51) # define a variable to control the main loop # where it is really only set to false if the player exits or the X button is pressed self.running = True self.state = None self.fade_into_main_menu() self.wins = create_wins() self.subtext_value = "" self.notification_value = "" # self.ended = False # self.show_ending = False self.end_image = None self.begin_image = load_image("beginlol.png", use_scale=False, return_rect=False) self.begin_image = pygame.transform.scale(self.begin_image, SCREEN_SIZE) self.default_background = load_image('background.png', return_rect=False) self.building_wall_mask = load_image('background_outline.png', convert_alpha=True, return_rect=False) # background can change to default background or house background self.background = self.default_background # creates the start menus self.pause_menu = PauseMenu(self.screen) self.main_menu = MainMenu(self.screen) self.temp = []