def main(): import pygame from labyrinth import Labyrinth from guardian import Gardian from hero import Hero from items import Items from constants import screen, black pygame.init() pygame.display.set_caption("SOS MacGyver") # create of labyrinth labyrinth = Labyrinth("labyrinth.txt") labyrinth.creat_labyrinth() labyrinth.blit_labyrinth("pictures/wall32.jpg") # creat and placement MacGyver MacGyver = Hero("pictures/MacGyver32.png", "MacGyver") MacGyver.placement_hero(labyrinth.position_start) print("position du hero", labyrinth.position_start) MacGyver.blit(screen) # creat and placement gardian gardian = Gardian("pictures/Gardien32.png", "Gardian") gardian.placement_gardian(labyrinth.position_arrival) print("position du méchant", gardian.position) gardian.blit(screen) # creat and placement items aiguille = Items("pictures/seringue32.png", "aiguille") aiguille.placement_item(screen, labyrinth.list_positions_empty) print("position de l'aiguille", aiguille.position) tube = Items("pictures/tube_plastique32.png", "tube") tube.placement_item(screen, labyrinth.list_positions_empty) print("position du tube", tube.position) ether = Items("pictures/ether32.png", "ether") ether.placement_item(screen, labyrinth.list_positions_empty) print("position de l'ether", ether.position) pygame.display.flip() # Loop of game end_game = False while not end_game: # loop evenements for event in pygame.event.get(): if event.type == pygame.QUIT: end_game = True pygame.quit() elif event.type == pygame.KEYDOWN: if event.key == pygame.K_LEFT: MacGyver.move("L", labyrinth) elif event.key == pygame.K_RIGHT: MacGyver.move("R", labyrinth) elif event.key == pygame.K_UP: MacGyver.move("U", labyrinth) elif event.key == pygame.K_DOWN: MacGyver.move("D", labyrinth) MacGyver.clear_hero(screen, black) MacGyver.blit(screen) print("MacGyver est en position: ", MacGyver.position) aiguille.colision_items(MacGyver.position, labyrinth.seringue) tube.colision_items(MacGyver.position, labyrinth.seringue) ether.colision_items(MacGyver.position, labyrinth.seringue) print("liste des éléments de la seringue", labyrinth.seringue) labyrinth.counter_items(black) labyrinth.end_game(MacGyver.position) pygame.display.flip()
class Game: def __init__(self, window): self.is_playing = False self.window = window # self.pressed = {} def initialization(self, window): """ Initialise new objects when call """ self.labyrinth = Labyrinth() self.mac_gyver = Player( MAC_GYVER_IMAGE, FLOOR_IMAGE, self.labyrinth, self.window ) self.mac_gyver.position = [0, 0] self.objects = Objects( SYRINGE_IMAGE, ETHER_IMAGE, NEEDLE_IMAGE, self.labyrinth, self.window ) # Labyrinth self.labyrinth.labyrinth_construction() self.labyrinth.display_level(window) # Player self.mac_gyver.blit(self.mac_gyver.position) # Objects self.objects.generate_random_position() self.objects.display_objects() self.objects.objects_collected = 0 self.run = True self.response = None def menu(self, menu_image, window): """ Display menu """ self.menu_i = pygame.image.load(menu_image).convert_alpha() self.window.blit(self.menu_i, (0, 0)) play_button = pygame.image.load("assets/playbutton.png") play_button = pygame.transform.scale(play_button, (200, 70)) play_button_rect = play_button.get_rect() play_button_rect.x = math.ceil(window.get_width() / 3.333) play_button_rect.y = math.ceil(window.get_height() / 1.4) window.blit(play_button, play_button_rect) continu = True while continu: pygame.display.update() for event in pygame.event.get(): # Waiting for events if event.type == pygame.QUIT: continu = False return False if event.type == pygame.MOUSEBUTTONDOWN: if play_button_rect.collidepoint(event.pos): continu = False return True def play(self): """Manage all input player's input""" continu = True while continu: pygame.display.update() for event in pygame.event.get(): # Waiting for events if event.type == pygame.QUIT: continu = False self.run = False if event.type == pygame.KEYDOWN: if event.key == pygame.K_RIGHT: self.mac_gyver.move("right") elif event.key == pygame.K_LEFT: self.mac_gyver.move("left") elif event.key == pygame.K_UP: self.mac_gyver.move("up") elif event.key == pygame.K_DOWN: self.mac_gyver.move("down") self.objects.collect_objects(self.mac_gyver) continu = self.labyrinth.end_game(self.mac_gyver) self.response = self.labyrinth.response( self.mac_gyver, self.objects ) pygame.display.flip() return self.response def player_win(self, win_image): """Display Win Screen at the end of the game""" self.win_image = pygame.image.load(win_image).convert_alpha() self.window.blit(self.win_image, ((0, 0))) continu = True while continu: pygame.display.update() for event in pygame.event.get(): # Waiting for events if event.type == pygame.QUIT: continu = False self.run = False if event.type == pygame.KEYDOWN: if event.key == pygame.K_SPACE: continu = False return True def player_loose(self, loose_image): """Display Loose Screen at the end of the game""" self.loose_image = pygame.image.load(loose_image).convert_alpha() self.window.blit(self.loose_image, ((0, 0))) continu = True while continu: pygame.display.update() for event in pygame.event.get(): # Waiting for events if event.type == pygame.QUIT: continu = False self.run = False if event.type == pygame.KEYDOWN: if event.key == pygame.K_SPACE: continu = False return True