def __init__(self, l): ''' Constructeur de la class LoadScene ''' self.width = pygame.display.get_surface().get_width() self.height = pygame.display.get_surface().get_height() self.loader = l l.clearAnimation() l.addAnimationByPath('bg', '../img/background.jpg', level=0) l.addAnimationByPath('normal', '../img/normal.png', self.width / 2 - 140, 100, level=1) l.addAnimationByPath('union', '../img/union.png', self.width / 2 - 140, 100, level=1) l.addAnimationByPath('back', '../img/back.png', self.width / 2 - 140, 100, level=1) self.createButton(l) self.resizeWindow(l, self.width, self.height) self.ReturnScene = self texts = l.getFont('mainTitle') if len(texts) > 0: sprite = Sprite(texts[0].render("Partie solo :", 1, (255, 255, 0))) animation = Animation(sprite) animation.newPos((self.width / 2 - sprite.w / 2), 30, sprite.w, sprite.h, 0) l.removeAnimation('title') l.addAnimation('title', animation)
def update(self, e, l): ''' @param e: le gestionnaire d'événement @param l: le gestionnaire d'image @return: Scene à renvoyer ''' if self.counter < self.maxCounter: texts = l.getFont('mainTitle') if len(texts) > 0: percent = (self.counter * 1.0 / self.maxCounter * 100) sprite = Sprite(texts[0].render(self.fileCheck[self.counter]['title'] + " {0:.0f}".format(percent) + " %", 1, (255, 255, 0))) animation = Animation(sprite) animation.newPos((self.width / 2 - sprite.w / 2), self.height - 50, sprite.w, sprite.h, 0) l.removeAnimation('infoTitle') l.addAnimation('infoTitle', animation) self.counter += 1 else: nextScene = MainScene(l) return nextScene if (e.quit): return None return self
def showInfoCard(self): if not self.showInfo: self.showInfo = True print("On montre la carte (ID:" + str(self.name) + ")") card = self.loader.getAnimation('showCard') if len(card) > 0: card[0].newPos(self.swidth / 2 - 100, self.sheight / 2 - 140, 200, 280, 8) self.loader.removeAnimation('NOM_CARTE') self.loader.removeAnimation('INFO_CARTE') texts = self.loader.getFont('mainTitle') if len(texts) > 0: self.sp = Sprite(texts[0].render("" + str(self.carte.name) + "", 1, (127, 127, 255))) self.animation = Animation(self.sp) self.animation.newPos(self.swidth / 2 - 78, self.sheight / 2 - 125, self.width - 20, 25, 0, None) self.loader.addAnimation('NOM_CARTE', self.animation, 6) chaine = str(self.carte.cost) if self.isCarteServant(self.carte.ID): chaine += "/" + str(self.carte.attack) + "/" + str(self.carte.health) self.sp = Sprite(texts[0].render(chaine, 1, (127, 127, 255))) self.animation = Animation(self.sp) self.animation.newPos(self.swidth / 2 - 78, self.sheight / 2 - 95, self.width - 20, 25, 0, None) self.loader.addAnimation('INFO_CARTE', self.animation, 6)
def changeText(self, l, message): texts = l.getFont('mainTitle') if len(texts) > 0: sprite = Sprite(texts[0].render(message, 1, (255, 255, 0))) animation = Animation(sprite) animation.newPos((self.width / 2 - sprite.w / 2), (self.height / 2 - sprite.h / 2) + 60, sprite.w, sprite.h, 0) animation.newPos((self.width / 2 - sprite.w / 2), (self.height / 2 - sprite.h / 2) + 60, sprite.w, sprite.h, 50, self.asyncChangeText) l.removeAnimation('info') l.addAnimation('info', animation)
def __init__(self, l, carte, level): ''' Constructeur d'une carte affichable @param l: Le loader de ressource ''' self.swidth = pygame.display.get_surface().get_width() self.sheight = pygame.display.get_surface().get_height() self.carte = carte self.name = str(self.carte.ID) + "-" + self.carte.name + "-" + str(randint(1, 1000000)) self.loader = l self.type = "spell" self.visible = True self.showInfo = True self.select = False self.asyncSelect = False self.changeVisibility = False self.posX = 50 self.posY = 50 self.width = 75 self.height = 105 self.tick = 0 self.func = None self.level = level self.loader.addAnimation(self.name, None, level) texts = self.loader.getFont('mainTitle') if len(texts) > 0: self.sp = Sprite(texts[0].render("" + str(self.carte.name) + "", 1, (255, 0, 255))) self.animation = Animation(self.sp) self.animation.newPos(self.swidth / 2 - 75, self.sheight / 2 - 135, 0, 0, 0, None) self.loader.addAnimation('NOM_CARTE', self.animation, 6) self.updateModif(True)
def statusText(self, l): texts = l.getFont('mainTitle') # PLayer 1 ( Down ) if len(texts) > 0: sprite = Sprite(texts[0].render("VIE: " + str(self.player1.health) + "/30", 1, (255, 255, 0))) spriteBis = Sprite(texts[0].render("MANA: " + str(self.player1.mana) + "/10", 1, (255, 255, 0))) spriteTer = Sprite(texts[0].render("" + str(self.player1.name) + "", 1, (255, 255, 0))) animation = Animation(sprite) animationBis = Animation(spriteBis) animationTer = Animation(spriteTer) animation.newPos(self.width - (sprite.w / 2) - 10, (self.height / 2 - sprite.h / 2) - 10 - (sprite.h / 2), sprite.w / 2, sprite.h / 2, 0) animationBis.newPos(self.width - (sprite.w / 2) - 10, (self.height / 2 - sprite.h / 2), sprite.w / 2, sprite.h / 2, 0) animationTer.newPos(self.width - (sprite.w / 2) - 10, (self.height / 2 - sprite.h / 2) - (10 - (sprite.h / 2) * 2), sprite.w / 2, sprite.h / 2, 0) l.removeAnimation('infoVieP1') l.addAnimation('infoVieP1', animation, level=5) l.removeAnimation('infoManaP1') l.addAnimation('infoManaP1', animationBis, level=5) l.removeAnimation('infoNameP1') l.addAnimation('infoNameP1', animationTer, level=5) # PLayer 1 ( UP ) if len(texts) > 0: sprite = Sprite(texts[0].render("VIE: " + str(self.player2.health) + "/30", 1, (255, 255, 0))) spriteBis = Sprite(texts[0].render("MANA: " + str(self.player2.mana) + "/10", 1, (255, 255, 0))) spriteTer = Sprite(texts[0].render("" + str(self.player2.name) + "", 1, (255, 255, 0))) animation = Animation(sprite) animationBis = Animation(spriteBis) animationTer = Animation(spriteTer) animation.newPos(10, (self.height / 2 - sprite.h / 2) - 10 - (sprite.h / 2), sprite.w / 2, sprite.h / 2, 0) animationBis.newPos(10, (self.height / 2 - sprite.h / 2), sprite.w / 2, sprite.h / 2, 0) animationTer.newPos(10, (self.height / 2 - sprite.h / 2) - (10 - (sprite.h / 2) * 2), sprite.w / 2, sprite.h / 2, 0) l.removeAnimation('infoVieP2') l.addAnimation('infoVieP2', animation, level=5) l.removeAnimation('infoManaP2') l.addAnimation('infoManaP2', animationBis, level=5) l.removeAnimation('infoNameP2') l.addAnimation('infoNameP2', animationTer, level=5) selection = l.getAnimation('pioche1') if len(selection) > 0: selection[0].newPos(self.width - 200, self.height / 2 - 105 - 110, 75, 105, 0, None) selection = l.getAnimation('pioche2') if len(selection) > 0: selection[0].newPos(self.width - 200, self.height / 2 + 105, 75, 105, 0, None)
class CardInfo(object): ''' Une carte du jeu sur une scene ''' def __init__(self, l, carte, level): ''' Constructeur d'une carte affichable @param l: Le loader de ressource ''' self.swidth = pygame.display.get_surface().get_width() self.sheight = pygame.display.get_surface().get_height() self.carte = carte self.name = str(self.carte.ID) + "-" + self.carte.name + "-" + str(randint(1, 1000000)) self.loader = l self.type = "spell" self.visible = True self.showInfo = True self.select = False self.asyncSelect = False self.changeVisibility = False self.posX = 50 self.posY = 50 self.width = 75 self.height = 105 self.tick = 0 self.func = None self.level = level self.loader.addAnimation(self.name, None, level) texts = self.loader.getFont('mainTitle') if len(texts) > 0: self.sp = Sprite(texts[0].render("" + str(self.carte.name) + "", 1, (255, 0, 255))) self.animation = Animation(self.sp) self.animation.newPos(self.swidth / 2 - 75, self.sheight / 2 - 135, 0, 0, 0, None) self.loader.addAnimation('NOM_CARTE', self.animation, 6) self.updateModif(True) def setPosition(self, x, y, t = 0, func = None): ''' Modifie la position de la carte @param x: position x @param y: position y @param t: le nombre de tick vers la nouvelle position (animation) @param func: Fonction de callback ''' self.posX = x self.posY = y self.tick = t self.func = func self.updateModif() def setSize(self, w, h): ''' Modifie la talle d'une carte ''' self.width = w self.height = h self.updateModif() def setResize(self, x, y, w, h, t = 0, func = None): ''' Rassemble le setSize et le setPosition ''' self.posX = x self.posY = y self.width = w self.height = h self.tick = t self.func = func self.updateModif() def setType(self, typeCard): ''' Le type de la carte (servitor, spell) @param typeCard: type de la carte ''' self.type = typeCard self.updateModif() def setVisible(self, visibility): ''' La visibilité de la carte (retourné ou non) @param visibility: Boolean pour savoir si la carte est visible ''' if self.visible != visibility: self.changeVisibility = True self.visible = visibility self.updateModif() if self.select == True: self.setSelect() def setSelect(self): ''' Est-ce que la carte est sélectionné ? @param selected: Carte sélectionné ou pas ''' if self.visible == True: self.select = not self.select self.updateModif() def updateModif(self, forceVisibility = False): ''' On applique les modifications à l'image Les position, tailles, image à afficher ''' imageSelect = '' addingSize = 0 addingTime = self.tick if self.changeVisibility == True or forceVisibility == True: self.changeVisibility = False if self.visible == True: imageSelect = '../img/card/spellCard.jpg' # Show text on the card else: imageSelect = '../img/card/backSpellCard.jpg' self.loader.removeAnimation(self.name) self.loader.addAnimationByPath(self.name, imageSelect, level=1) if self.select != self.asyncSelect: self.asyncSelect = self.select if self.select: addingSize = 15 if addingTime == 0: addingTime = 20 anim = self.loader.getAnimation(self.name) if len(anim) > 0: anim[0].newPos(self.posX - addingSize, self.posY - addingSize, self.width + (addingSize * 2), self.height + (addingSize * 2), addingTime, self.func) def showInfoCard(self): if not self.showInfo: self.showInfo = True print("On montre la carte (ID:" + str(self.name) + ")") card = self.loader.getAnimation('showCard') if len(card) > 0: card[0].newPos(self.swidth / 2 - 100, self.sheight / 2 - 140, 200, 280, 8) self.loader.removeAnimation('NOM_CARTE') self.loader.removeAnimation('INFO_CARTE') texts = self.loader.getFont('mainTitle') if len(texts) > 0: self.sp = Sprite(texts[0].render("" + str(self.carte.name) + "", 1, (127, 127, 255))) self.animation = Animation(self.sp) self.animation.newPos(self.swidth / 2 - 78, self.sheight / 2 - 125, self.width - 20, 25, 0, None) self.loader.addAnimation('NOM_CARTE', self.animation, 6) chaine = str(self.carte.cost) if self.isCarteServant(self.carte.ID): chaine += "/" + str(self.carte.attack) + "/" + str(self.carte.health) self.sp = Sprite(texts[0].render(chaine, 1, (127, 127, 255))) self.animation = Animation(self.sp) self.animation.newPos(self.swidth / 2 - 78, self.sheight / 2 - 95, self.width - 20, 25, 0, None) self.loader.addAnimation('INFO_CARTE', self.animation, 6) def isCarteServant(self, ID): ''' Verifie si l'id correspond a une carte qui invoque un serviteur ''' if int(ID) > 2000000 and int(ID) < 3000000: return True else: return False def hideInfoCard(self): if self.showInfo: self.showInfo = False print("On cache la carte (ID:" + str(self.name) + ")") card = self.loader.getAnimation('showCard') if len(card) > 0: card[0].newPos(self.swidth / 2, self.sheight / 2, 0, 0, 8) self.loader.removeAnimation('NOM_CARTE') self.loader.removeAnimation('INFO_CARTE') def mouseCheck(self, e, x, y, w, h): return (e.posX >= x and e.posX <= (x + w) and e.posY >= y and e.posY <= (y + h)) def update(self, e, l): ''' On regarde les événements sur la carte ''' if not (e == None) and self.mouseCheck(e, self.posX, self.posY, self.width, self.height): if self.visible == True: self.showInfoCard() if e.button[1]: e.button[1] = False self.setSelect() else: self.hideInfoCard() def updateResize(self, w, h): self.swidth = w self.sheight = h