def deathLoadElements(self): label = runtime.Label() if self._deathWas1 == True: label.text = "Le joueur 1 a gagné!" else: label.text = "Le joueur 2 a gagné!" label.rect.x = 200 label.rect.y = 100 self._rtm.appendObject(label) button = runtime.Button() button.text = "Retour" button.rect.x = 200 button.rect.y = 200 button.setCallBack(self._onExit) self._rtm.appendObject(button) self._hasDeath = True
def loadElements(self): """Loads UI elements""" l1 = runtime.Label() l1.text = "Comment jouer?" l1.font = pg.font.SysFont(None, 64) l1.color = (100, 100, 255) l1.rect.x = 10 l1.rect.y = 5 self._rtm.appendObject(l1) self._return_button = runtime.Button() self._return_button.text = "Retour" self._return_button.rect.x = self._rtm.target_win.get_width( ) - 5 - self._return_button.rect.width self._return_button.rect.y = self._rtm.target_win.get_height( ) - 5 - self._return_button.rect.height self._return_button.setCallBack(self.handleReturn) self._return_button.background_clicked = (0, 255, 8) self._return_button.background = (76, 175, 80) self._rtm.appendObject(self._return_button) #Create the label for each line l2 = runtime.Label() l3 = runtime.Label() l4 = runtime.Label() l5 = runtime.Label() l6 = runtime.Label() l2.text = "Ici, deux joueurs s'affrontent en 1v1." l3.text = "Chacun a un personnage avec différentes attaques. Cependant, il n'y en a seulement 4," l4.text = "pour les appeler, vérifiez vos touches.La barre de vie, les sauts, kicks et autres" l5.text = "coups en tout genre seront vos seules options pour battre les doigts qui sont posés" l6.text = "sur le même clavier." listed = [l2, l3, l4, l5, l6] i = 0 top = 68 left = 15 font = pg.font.SysFont(None, 24) while (i < len(listed)): listed[i].font = font listed[i].rect.y = i * 26 + top listed[i].rect.x = left self._rtm.appendObject(listed[i]) i += 1
def loadElements(self): """Loads UI elements""" j1 = runtime.Label() j1.text = "Choisissez la map!" j1.font = pg.font.SysFont(None, 64) j1.rect.x = 20 self._rtm.appendObject(j1) self._return_button = runtime.Button() self._return_button.text = "Retour" self._return_button.rect.x = self._rtm.target_win.get_width() - 5 - self._return_button.rect.width self._return_button.rect.y = self._rtm.target_win.get_height() - 5 - self._return_button.rect.height self._return_button.setCallBack(self.handleReturn) self._return_button.background_clicked = (0, 255, 8) self._return_button.background = (76, 175, 80) self._rtm.appendObject(self._return_button) #Put the button self._button = runtime.Button() self._button.text = "Suivant >" self._button.font = pg.font.SysFont(None, 32) self._button.rect.x = 595 self._button.rect.y = 5 self._button.setCallBack(self.handleNext) self._button.background = (255, 100, 100) self._button.background_clicked = (255, 180, 180) self._rtm.appendObject(self._button) #Put the title self._label = runtime.Label() self._label.text = "Choisissez une map" self._label.font = pg.font.SysFont(None, 40) self._label.color = (100, 100, 255) self._label.rect.x = 5 self._label.rect.y = self._win.get_rect().height - self._label.rect.height self._rtm.appendObject(self._label) mapList = os.listdir("./maps") compatible = {} i = 0 #Load data from dir while i<len(mapList): filePath = os.path.splitext(mapList[i]) if filePath[1] == ".image": if os.path.exists("./maps/" + filePath[0] + ".field"): try: f = open("./maps/" + filePath[0] + ".field", "r") data = str(f.read()).split("\n") if len(data) >= 2: compatible["./maps/" + filePath[0] + ".image"] = data[0] f.close() except: "" else: print("./maps/" + filePath[0] + ".field", "has incoherent data when coupled with files") i+=1 keys = list(compatible.keys()) values = list(compatible.values()) #Generate buttons from loaded data left = 20 top = 60 spacing = 5 row = 0 column = 0 i = 0 items = [] while i<len(keys): it = cbi.ClickableItem(values[i]) it.setImage(keys[i]) it.makePaintUpdate = True it.setCallBack(self.onItemClick) it.setX(column*150 + spacing*column + left) it.setY(row*170 + spacing*row + top) column += 1 if column == 4: column = 0 row += 1 items.append(it) self._rtm.appendObject(it) i+=1
def loadElements(self): """Loads and displays UI elements.""" j1 = runtime.Label() j1.text = "Choisissez un joueur!" j1.font = pg.font.SysFont(None, 64) j1.rect.x = 20 self._rtm.appendObject(j1) self._return_button = runtime.Button() self._return_button.text = "Retour" self._return_button.rect.x = self._rtm.target_win.get_width( ) - 5 - self._return_button.rect.width self._return_button.rect.y = self._rtm.target_win.get_height( ) - 5 - self._return_button.rect.height self._return_button.setCallBack(self.handleReturn) self._return_button.background_clicked = (0, 255, 8) self._return_button.background = (76, 175, 80) self._rtm.appendObject(self._return_button) #Put the button self._button = runtime.Button() self._button.text = "Suivant >" self._button.font = pg.font.SysFont(None, 32) self._button.rect.x = self._rtm.target_win.get_width( ) - 5 - self._button.rect.width self._button.rect.y = 5 self._button.setCallBack(self.handleNext) self._button.background = (255, 100, 100) self._button.background_clicked = (255, 180, 180) self._rtm.appendObject(self._button) mapList = os.listdir("./players/profiles") compatible = {} i = 0 while i < len(mapList): filePath = os.path.splitext(mapList[i]) if filePath[1] == ".image": if os.path.exists("./players/profiles/" + filePath[0] + ".field"): try: f = open( "./players/profiles/" + filePath[0] + ".field", "r") data = str(f.read()).split("\n") if len(data) >= 2: compatible["./players/profiles/" + filePath[0] + ".image"] = data[0] f.close() except: "" else: print("./players/profiles/" + filePath[0] + ".field", "has incoherent data when coupled with files") i += 1 #Load the clickables self.generateClickablesFrom(compatible, self.onItemClick1) self.generateClickablesFrom(compatible, self.onItemClick2, 400) #Show the labels to let users know which player have been chosen self._label1 = runtime.Label() self._label1.text = "Choisissez le J1" self._label1.font = pg.font.SysFont(None, 40) self._label1.color = (100, 100, 255) self._label1.rect.x = 5 self._label1.rect.y = self._win.get_rect( ).height - self._label1.rect.height self._rtm.appendObject(self._label1) self._label2 = runtime.Label() self._label2.text = "Choisissez une J2" self._label2.font = pg.font.SysFont(None, 40) self._label2.color = (100, 100, 255) self._label2.rect.x = 400 self._label2.rect.y = self._win.get_rect( ).height - self._label2.rect.height self._rtm.appendObject(self._label2)
def loadElements(self): """Loads the UI elements and display 'em""" j1 = runtime.Label() j2 = runtime.Label() self._return_button = runtime.Button() self._return_button.text = "Retour" self._return_button.rect.x = self._rtm.target_win.get_width( ) - 5 - self._return_button.rect.width self._return_button.rect.y = self._rtm.target_win.get_height( ) - 5 - self._return_button.rect.height self._return_button.setCallBack(self._returnCallBack) self._return_button.background_clicked = (0, 255, 8) self._return_button.background = (76, 175, 80) self._rtm.appendObject(self._return_button) list1 = [] list2 = [] for i in range(0, 14): list1.append(KeyButton()) for i in range(0, 7): list2.append(runtime.Label()) #Put the titles j1.text = "Joueur 1" j2.text = "Joueur 2" j1.font = pg.font.SysFont(None, 64) j2.font = pg.font.SysFont(None, 64) j1.rect.x = 20 j2.rect.x = 320 #The sublabels list2[0].text = "Aller à gauche" list2[1].text = "Aller à droite" list2[2].text = "Sauter" list2[3].text = "Se baisser" list2[4].text = "Attaque 1" list2[5].text = "Attaque 2" list2[6].text = "Attaque 3" global switcher keys = list(switcher.values()) self._rtm.appendObject(j1) self._rtm.appendObject(j2) #Add the buttons and the labels to know the used keys for i in range(0, 14): list1[i].rect.height = 40 list1[i].setKey(keys[i]) self._rtm.appendObject(list1[i]) for i in range(0, 7): list2[i].rect.height = 20 self._rtm.appendObject(list2[i]) topBase = 60 padding = 10 for i in range(0, 7): list2[i].font = pg.font.SysFont(None, 20) list1[i].font = pg.font.SysFont(None, 40) list1[i + 7].font = pg.font.SysFont(None, 40) list2[i].rect.x = 20 list2[i].rect.y = topBase + i * 60 + i * padding list1[i].rect.x = 20 list1[i + 7].rect.x = 320 y = list2[i].rect.y + 20 list1[i].rect.y = y list1[i + 7].rect.y = y