def __init__(self, numero_joueur, center): pygame.sprite.Sprite.__init__(self) self.numero_joueur = numero_joueur if numero_joueur == Joueur.numeroJoueur: self.image, self.rect = load_png(ASSET_SPAWN_JOUEUR) else: self.image, self.rect = load_png(ASSET_SPAWN_ENNEMI) self.rect.center = center
def __init__(self, xAbs, yAbs): pygame.sprite.Sprite.__init__(self) self.id = Flamme.calcul_id(self) self.rect = load_png(ASSET_FLAME)[1] self.rect.center = (xAbs, yAbs) self.timer = BOMB_EXPLOSE_DELAY
def __init__(self, id, center, joueur_id): pygame.sprite.Sprite.__init__(self) self.id = id self.joueur_id = joueur_id self.image, self.rect = load_png(ASSET_BOMBE) self.rect.center = center
def __init__(self, joueur, x, y): pygame.sprite.Sprite.__init__(self) self.id = Bombe.calcul_id(self) self.joueur = joueur self.image, self.rect = load_png(ASSET_BOMBE) self.rect.center = (x, y) self.time = BOMB_DELAY
def __init__(self, id, center): pygame.sprite.Sprite.__init__(self) self.id = id self.image, self.rect = load_png(ASSET_FLAME) self.rect.center = center self.timer = BOMB_EXPLOSE_DELAY self.image_time = BOMB_EXPLOSE_DELAY / len(ASSET_ANIMATE_FLAMES)
def __init__(self, numero, life): pygame.sprite.Sprite.__init__(self), self.numero = numero self.life = life self.is_at_spawn = False self.bouclier = False if numero == Joueur.numeroJoueur: # Alors c'est nous self.bas = load_png(ASSET_JOUEUR['BAS'])[0] self.haut = load_png(ASSET_JOUEUR['HAUT'])[0] self.droite = load_png(ASSET_JOUEUR['DROITE'])[0] self.gauche = pygame.transform.flip(self.droite, True, False) else: # C'est un ennemi self.bas = load_png(ASSET_ENNEMI['BAS'])[0] self.haut = load_png(ASSET_ENNEMI['HAUT'])[0] self.droite = load_png(ASSET_ENNEMI['DROITE'])[0] self.gauche = pygame.transform.flip(self.droite, True, False) self.image, self.rect = self.bas, self.bas.get_rect() self.bulle_invicible_image = load_png(ASSET_BULLE_INVINCIBLE)[0] self.bouclier_image = load_png(ASSET_BOUCLIER)[0]
def __init__(self, numero, spawn_topleft): pygame.sprite.Sprite.__init__(self) self.numero = numero self.image, self.rect = load_png(ASSET_JOUEUR['BAS']) self.rect.topleft = spawn_topleft self.direction = "bas" self.is_at_spawn = False self.spawn = pygame.Rect(spawn_topleft, (SIDE_LENGTH, SIDE_LENGTH)) self.life_max = PLAYER_LIFE_MAX self.life = PLAYER_LIFE_MAX self.bombe_detection = True self.bombe_range = BOMB_RANGE self.bombe_max_number = 1 self.bombe_number = 1 self.velocity = PLAYER_SPEED self.speed = [0, 0] self.bouclier = False self.bouclierEnDestruction = False
def __init__(self, type, xAbs, yAbs): pygame.sprite.Sprite.__init__(self) self.type = type self.id = PowerUp.calcul_id(self) self.rect = load_png(ASSET_POWER_UP[type])[1] self.rect.topleft = (xAbs, yAbs)
def __init__(self, xAbs, yAbs): pygame.sprite.Sprite.__init__(self) self.id = Caisse.calcul_id(self) self.rect = load_png(ASSET_CAISSE)[1] self.rect.topleft = (xAbs, yAbs)
def __init__(self, xAbs, Abs): pygame.sprite.Sprite.__init__(self) self.rect = load_png(ASSET_MUR)[1] self.rect.topleft = (xAbs, Abs)
def __init__(self, type, id, center): pygame.sprite.Sprite.__init__(self) self.image, self.rect = load_png(ASSET_POWER_UP[type]) self.id = id self.rect.center = center
def init_game(screen): """ Initialization game dialog """ screen.fill((0, 0, 0)) font_title = pygame.font.Font("assets/font/pacifico.ttf", 45) font_normal = pygame.font.Font("assets/font/aller_regular.ttf", 25) images_joueur = { 'bas': load_png(ASSET_JOUEUR['BAS'])[0], 'haut': load_png(ASSET_JOUEUR['HAUT'])[0], 'droite': load_png(ASSET_JOUEUR['DROITE'])[0], } images_joueur['gauche'] = pygame.transform.flip(images_joueur['droite'], True, False) image_fond, image_fond_rect = None, None image_shadow, image_shadow_rect = None, None image_joueur, image_joueur_rect = None, (screen.get_rect().centerx - 16, screen.get_rect().centery - 16) title_rect = screen.get_rect() title_rect.height /= 2 display_message(screen, font_title, "Initialisation", (152, 152, 100), title_rect) message_rect = screen.get_rect() message_rect.height *= 1.5 display_message(screen, font_normal, "Appuyez sur espace", (172, 172, 100), message_rect) pygame.display.flip() key_to_press = 'espace' pressed = { 'espace': False, 'haut': False, 'droite': False, 'bas': False, 'gauche': False } while True: for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit(0) if event.type == pygame.KEYUP: if event.key == pygame.K_SPACE: if not pressed['espace']: image_fond, image_fond_rect = load_png(ASSET_SOL) image_fond_rect.center = screen.get_rect().center image_shadow, image_shadow_rect = load_png( ASSET_JOUEUR['SHADOW']) image_shadow_rect.center = screen.get_rect().center pressed['espace'] = True key_to_press = 'haut' all_pressed = True for value in pressed.values(): all_pressed = (all_pressed and value) if all_pressed: screen.fill((0, 0, 0)) display_message(screen, font_title, "C'est parti ! (on va gagner)", (152, 152, 100)) pygame.display.flip() time.sleep(1.75) return elif event.key == pygame.K_UP: if not pressed['haut'] and pressed['espace']: pressed['haut'] = True key_to_press = 'gauche' if pressed['haut']: image_joueur = images_joueur['haut'] elif event.key == pygame.K_LEFT: if not pressed['gauche'] and pressed['haut']: pressed['gauche'] = True key_to_press = 'bas' if pressed['gauche']: image_joueur = images_joueur['gauche'] elif event.key == pygame.K_DOWN: if not pressed['bas'] and pressed['gauche']: pressed['bas'] = True key_to_press = 'droite' if pressed['bas']: image_joueur = images_joueur['bas'] elif event.key == pygame.K_RIGHT: if not pressed['droite'] and pressed['bas']: pressed['droite'] = True key_to_press = 'espace pour jouer !' if pressed['droite']: image_joueur = images_joueur['droite'] screen.fill((0, 0, 0)) display_message(screen, font_title, "Initialisation", (152, 152, 100), title_rect) display_message(screen, font_normal, "Appuyez sur " + key_to_press, (172, 172, 100), message_rect) if pressed['espace']: screen.blit(image_fond, image_fond_rect) screen.blit(image_shadow, image_shadow_rect) if pressed['haut']: screen.blit(image_joueur, image_joueur_rect) pygame.display.flip()
def __init__(self, center): pygame.sprite.Sprite.__init__(self) self.image, self.rect = load_png(ASSET_MUR) self.rect.center = center
def __init__(self, center): pygame.sprite.Sprite.__init__(self) self.image, self.rect = load_png(ASSET_JOUEUR['SHADOW']) self.rect.center = center
def update(self, joueurs): self.timer -= 1 for i in range(len(ASSET_ANIMATE_FLAMES)): if self.timer == self.image_time * i: self.image = load_png(ASSET_ANIMATE_FLAMES[i])[0] break
def __init__(self, id, center): pygame.sprite.Sprite.__init__(self) self.image, self.rect = load_png(ASSET_CAISSE) self.id = id self.rect.center = center
def show_stat_panel(screen, joueurs, bombes): # Card width, card height card_width = PANEL_WIDTH - 10 card_height = (ARENA_HEIGHT * SIDE_LENGTH) / (len(joueurs) + 1) # Scale ratio scale = 1.4 # Récupération des bombes bombe_joueur = {} for j in joueurs: bombe_joueur[j.numero] = 0 for bombe in bombes: if (bombe.joueur_id in bombe_joueur.keys()): bombe_joueur[bombe.joueur_id] += 1 # Bombe definitions bombe_img, bombe_rect = load_png(ASSET_BOMBE) bombe_img_height = bombe_rect.height + 10 # Life definitions life_img, life_rect = load_png(ASSET_LIFE) life_gone_img = load_png(ASSET_LIFE_GONE)[0] life_img_height = life_rect.height + 10 # (width, height) center of the first card w_center = (ARENA_WIDTH * SIDE_LENGTH) + (card_width / 2) h_center = card_height / 2 # Blit joueurs stats for joueur in joueurs: # Joueur's life blitting img_width = (card_width / (PLAYER_LIFE_MAX + 1)) life_rect.center = ((ARENA_WIDTH * SIDE_LENGTH + img_width), h_center) for i in range(joueur.life): screen.blit(life_img, life_rect) life_rect.centerx += img_width for i in range(PLAYER_LIFE_MAX - joueur.life): screen.blit(life_gone_img, life_rect) life_rect.centerx += img_width h_center += life_img_height # Joueur blitting image = pygame.transform.scale( joueur.image, (int(joueur.rect.width * scale), int(joueur.rect.height * scale))) rect = image.get_rect() rect.center = (w_center, h_center) screen.blit(image, rect) h_center += bombe_img_height # Joueur's bombes blitting img_width = (card_width / (bombe_joueur[joueur.numero] + 1)) bombe_rect.center = ((ARENA_WIDTH * SIDE_LENGTH + img_width), h_center) for i in range(bombe_joueur[joueur.numero]): screen.blit(bombe_img, bombe_rect) bombe_rect.centerx += img_width h_center += (card_height / 2)