def maj(self, delta): self.__temps_anim += delta if not self.__fin_jeu.debut and self.__vainqueur.get_pos()[0] >= 700: self.__fin_jeu.debut = True if self.__fin_jeu.fin: self.__vainqueur.deplacement = (-1, 0) self.__vainqueur.vitesse = 0 self.__vainqueur.anim = Animation(0, 0, TAILLE_PERSO[0], TAILLE_PERSO[1], 4, 0.2) for dino in self.__perdants: dino.fin() sons = Sons() from gestionnaires.Jeu import Jeu if Jeu.konami_actif(): sons.jouer_son('k-mort2') else: sons.jouer_son('mort') sons.jouer_son('mort2') sons.jouer_son('mort3') sons.jouer_son('crash', 'ogg') BoutonRejouer(self, 550) Maj().supprimer(self)
def __init__(self, couleur, position, deplacement): self.__sprite = Images().charger_image(f'{CHEMIN_SPRITE}dino-{couleur}.png') self.__rect = self.__sprite.get_rect() self.__rect.x, self.__rect.y = position self.vitesse = 300 self.deplacement = deplacement self.anim = Animation(18, 0, TAILLE_PERSO[0], TAILLE_PERSO[1], 6, 0.2) Maj().enregistrer(self) Affichage().enregistrer(self, 3)
def __init__(self, positions, deplacement, couleur_joueur, vitesse=400, duree=3): self.__couleur_joueur = couleur_joueur self.__sprite = Images().charger_image(self.CHEMIN_SPRITE + 'Tornade.png') self.__rect = self.__sprite.get_rect() self.__rect.x, self.__rect.y = positions self.__deplacement = deplacement self.__vitesse = vitesse self.__animation = Animation(0, 0, Tornade.TAILLE_IMAGE[0], Tornade.TAILLE_IMAGE[1], 4, duree / 12) self.__temps_restant = duree Sons().jouer_son('Tornade', 'wav', math.ceil(duree/3) - 1, duree) # Avec 3 la duree du sons Affichage().enregistrer(self, 1) Maj().enregistrer(self)
def __init__(self, touches, couleur, nb_coeurs): # Private Joueur.__count += 1 self.__attente_releve = False self.__vies = nb_coeurs self.__sprite = Images().charger_image( f'{CHEMIN_SPRITE}dino-{couleur}.png') self.__hud = HudVie(self.__vies, couleur) self.__rect = self.__sprite.get_rect() self.__rect.y = HAUTEUR - TAILLE_PERSO[1] self.__vitesse = 300 self.__deplacement = [0, 0] self.__boost = 0 self.__velocite_saut, self.vitesse_chute = 2, 4 self.__nb_saut_restant = 1 self._subit_tornade = -1 self.__accroupi = False self.__anim_attente = Animation(0, 0, TAILLE_PERSO[0], TAILLE_PERSO[1], 4, 0.2) self.__anim_deplacement = Animation(4, 0, TAILLE_PERSO[0], TAILLE_PERSO[1], 6, 0.13) self.__anim_attaque = Animation(10, 0, TAILLE_PERSO[0], TAILLE_PERSO[1], 3, 0.2) self.__anim_degat = Animation(13, 0, TAILLE_PERSO[0], TAILLE_PERSO[1], 4, 0.2, False, 0.5) self.__anim_accroupi = Animation(18, 0, TAILLE_PERSO[0], TAILLE_PERSO[1], 6, 0.2) self.__anim_active = self.__anim_attente # Protected self._touches = touches self._couleur = couleur evenement = Evenement() evenement.enregistrer(pygame.KEYDOWN, self) evenement.enregistrer(pygame.KEYUP, self) Affichage().enregistrer(self, 1) Maj().enregistrer(self)
def load(filename, start=None, end=None, order=None, world=False, rotate=False): """ Reads a BVH file and constructs an animation Parameters ---------- filename: str File to be opened start : int Optional Starting Frame end : int Optional Ending Frame order : str Optional Specifier for joint order. Given as string E.G 'xyz', 'zxy' world : bool If set to true euler angles are applied together in world space rather than local space Returns ------- (animation, joint_names, frametime) Tuple of loaded animation and joint names """ f = open(filename, "r") i = 0 active = -1 end_site = False names = [] orients = Quaternions.id(0) offsets = np.array([]).reshape((0,3)) parents = np.array([], dtype=int) for line in f: if "HIERARCHY" in line: continue if "MOTION" in line: continue """ Modified line read to handle mixamo data """ # rmatch = re.match(r"ROOT (\w+)", line) rmatch = re.match(r"ROOT (\w+:?\w+)", line) if rmatch: names.append(rmatch.group(1)) offsets = np.append(offsets, np.array([[0,0,0]]), axis=0) orients.qs = np.append(orients.qs, np.array([[1,0,0,0]]), axis=0) parents = np.append(parents, active) active = (len(parents)-1) continue if "{" in line: continue if "}" in line: if end_site: end_site = False else: active = parents[active] continue offmatch = re.match(r"\s*OFFSET\s+([\-\d\.e]+)\s+([\-\d\.e]+)\s+([\-\d\.e]+)", line) if offmatch: if not end_site: offsets[active] = np.array([list(map(float, offmatch.groups()))]) continue chanmatch = re.match(r"\s*CHANNELS\s+(\d+)", line) if chanmatch: channels = int(chanmatch.group(1)) if order is None: channelis = 0 if channels == 3 else 3 channelie = 3 if channels == 3 else 6 parts = line.split()[2+channelis:2+channelie] if any([p not in channelmap for p in parts]): continue order = "".join([channelmap[p] for p in parts]) continue """ Modified line read to handle mixamo data """ # jmatch = re.match("\s*JOINT\s+(\w+)", line) jmatch = re.match("\s*JOINT\s+(\w+:?\w+)", line) if jmatch: if not jmatch.group(1).replace('\n', '') in ['head_ee_ry', 'left_ee_rx', 'right_ee_rx', 'left_foot_ee', 'right_foot_ee']: names.append(jmatch.group(1)) offsets = np.append(offsets, np.array([[0,0,0]]), axis=0) orients.qs = np.append(orients.qs, np.array([[1,0,0,0]]), axis=0) parents = np.append(parents, active) active = (len(parents)-1) continue if "End Site" in line: end_site = True continue fmatch = re.match("\s*Frames:\s+(\d+)", line) if fmatch: if start and end: fnum = (end - start)-1 else: fnum = int(fmatch.group(1)) jnum = len(parents) positions = offsets[np.newaxis].repeat(fnum, axis=0) rotations = np.zeros((fnum, len(orients), 3)) continue fmatch = re.match("\s*Frame Time:\s+([\d\.]+)", line) if fmatch: frametime = float(fmatch.group(1)) continue if (start and end) and (i < start or i >= end-1): i += 1 continue dmatch = line.strip().split(' ') if dmatch: data_block = np.array(list(map(float, dmatch))) N = len(parents) fi = i - start if start else i if channels == 3: positions[fi,0:1] = data_block[0:3] rotations[fi, : ] = data_block[3: ].reshape(N,3) elif channels == 6: data_block = data_block.reshape(N,6) positions[fi,:] = data_block[:,0:3] rotations[fi,:] = data_block[:,3:6] elif channels == 9: positions[fi,0] = data_block[0:3] data_block = data_block[3:].reshape(N-1,9) rotations[fi,1:] = data_block[:,3:6] positions[fi,1:] += data_block[:,0:3] * data_block[:,6:9] else: raise Exception("Too many channels! %i" % channels) i += 1 f.close() if rotate: rotations[:, [0]] += np.array([0, 90, 0]) rotations = Quaternions.from_euler(np.radians(rotations), order=order, world=world) return (Animation(rotations, positions, orients, offsets, parents), names, frametime)
def __init__(self, nom_json, x, y, taille): fichier_json = open(f'res/blocs/{nom_json}.json') self.__donnees = json.load(fichier_json) self.__sprite = Images().charger_image('res/img/Tileset.png') self._x = x self._y = y self.__z = self.__donnees['z'] if 'z' in self.__donnees.keys() else 0 self.__taille = taille self._dessin = None self.__animation = None if all(cle in self.__donnees for cle in ['animation', 'temps-animation']): self.__animation = Animation(self.__donnees['x'], self.__donnees['y'], self.__donnees['largeur'], self.__donnees['hauteur'], self.__donnees['animation'], self.__donnees['temps-animation']) direction = self.__donnees['direction'] if direction == 'x': self.__direction = [1, 0] self.__largeur = self.__donnees['largeur'] * taille self.__hauteur = self.__donnees['hauteur'] else: self.__direction = [0, 1] self.__largeur = self.__donnees['largeur'] self.__hauteur = self.__donnees['hauteur'] * taille Maj().enregistrer(self) else: fin_debut = 0 fin_milieu = 0 taille_milieu = 0 if self.__donnees['direction'] == 'x': largeur = 0 for debut in self.__donnees['debut']: largeur += debut['largeur'] fin_debut = largeur for milieu in self.__donnees['milieu']: taille_milieu += milieu['largeur'] largeur += taille_milieu * self.__taille fin_milieu = largeur for fin in self.__donnees['fin']: largeur += fin['largeur'] hauteur = self.__donnees['debut'][0]['hauteur'] elif self.__donnees['direction'] == 'y': largeur = self.__donnees['debut'][0]['largeur'] hauteur = 0 for debut in self.__donnees['debut']: hauteur += debut['hauteur'] fin_debut = largeur for milieu in self.__donnees['milieu']: taille_milieu += milieu['hauteur'] hauteur += taille_milieu * self.__taille fin_milieu = largeur for fin in self.__donnees['fin']: hauteur += fin['hauteur'] else: largeur = self.__donnees['debut'][0]['largeur'] hauteur = self.__donnees['debut'][0]['hauteur'] self.__taille = taille nom_cache = f'{nom_json}|{taille}' if nom_cache not in Bloc.DESSINS: self.__init_dessin(largeur, hauteur, fin_debut, fin_milieu, taille_milieu) Bloc.DESSINS[nom_cache] = self._dessin else: self._dessin = Bloc.DESSINS[nom_cache] self.__largeur = self._dessin.get_width() Affichage().enregistrer(self, self.__z)