示例#1
0
def update():
    global root, changerNiveau, VIES

    if briques.hasBriqueBreakable() or animationsExplosion.nbExplosion() or animationsArtifice.NBANIMATIONS:
        if balles.nbBalle() or bonus.nbBonus():
            collisions.gestionCollisions()
            balles.move()
            barres.move()
            bonus.move()
            animationsExplosion.explosionsMove()
            animationsArtifice.animationsArtificeMove()
            config.SPEED += config.SPEED_PER_FRAME
            root.after(1000 // (config.FPS), update)
        elif VIES:
            VIES -= 1
            barres.enleverBarres()
            barres.ajouterBarre(config.WIDTH / 2 - 100, 500)
            balles.enleverBalles()
            config.SPEED = config.BALLE_SPEED_INIT
            balles.ajouterBalle(config.WIDTH / 2 - 10 + randrange(-5, 5), 350)
            root.after(1000 // (config.FPS), update)
        else:
            print("PERDU")
            root.quit()
    else:
        changerNiveau()
示例#2
0
def gestionCollisionBallesBarres():
    global gestionCollisionBalleBarre

    for i in range(barres.nbBarre()):
        k = 0
        for j in range(balles.nbBalle()):
            if balles.y[k] > config.HEIGHT:
                balles.enleverBalle(k)
            else:
                gestionCollisionBalleBarre(k, i)
                k += 1
示例#3
0
def gestionCollisionBallesBriques():
    global gestionCollisionBalleBrique

    flagsretour = []

    for i in range(balles.nbBalle()):
        flags = []
        k = 0
        for j in range(briques.nbBrique()):
            flags += gestionCollisionBalleBrique(i, k)
            if {"event": "brique.enlever"} in flags:
                briques.enleverBrique(k)
                flags.remove({"event": "brique.enlever"})
            else:
                k += 1

        # gestion des flags
        # flags possibles : "balle.invert_dx", "balle.invert_dy", "explosion.create", "animationArtifice.create", "bonus.create"
        flags_processed = list()
        for flag in flags:
            if flag["event"] == "balle.invert_dx" and flag not in flags_processed:
                balles.dx[i] = -balles.dx[i]
                flags_processed.append(flag)
            elif flag["event"] == "balle.invert_dy" and flag not in flags_processed:
                balles.dy[i] = -balles.dy[i]
                flags_processed.append(flag)
            elif flag["event"] == "animationArtifice.create" and flag not in flags_processed:
                animationsArtifice.ajouterAnimationArtifice(flag["x"], flag["y"])
                flags_processed.append(flag)
            elif flag["event"] == "bonus.create" and flag not in flags_processed:
                bonus.ajouterBonus(flag["x"], flag["y"], flag["bonus"])
                flags_processed.append(flag)
            elif flag["event"] == "explosion.create" and flag not in flags_processed:
                animationsExplosion.ajouterExplosion(flag["x"], flag["y"])
                briques.explosion(flag["x"], flag["y"])
                flags_processed.append(flag)

        # suppression des flags
        for flag in flags_processed:
            while flag in flags:
                flags.remove(flag)

        # sauvegarde des flags non traités
        flagsretour += flags

    return flagsretour
示例#4
0
def gestionCollisonBonusBarre(i, j):
    """Si il y a collision, on active le bonus"""
    global collision

    retour = False

    bonusx1 = bonus.x[i] + bonus.dx[i]
    bonusx2 = bonusx1 + bonus.w[i]
    bonusy1 = bonus.y[i] + bonus.dy[i]
    bonusy2 = bonusy1 + bonus.h[i]

    barrex1 = barres.x[j] + barres.dx[j]
    barrex2 = barrex1 + barres.w[j]
    barrey1 = barres.y[j]
    barrey2 = barrey1 + barres.h[j]

    if collision(bonusx1, bonusx2, bonusy1, bonusy2, barrex1, barrex2, barrey1, barrey2):

        retour = True

        # l'effet obtenu depend du bonus
        if bonus.bonus_contenu[i] in ["barre_agrandie", "barre_retrecie"]:
            barres.applyBonus(j, bonus.bonus_contenu[i])
            bonus.enleverBonus(i)
        elif bonus.bonus_contenu[i] == "balle_feu":
            for k in range(balles.nbBalle()):
                balles.applyBonus(k, "balle_feu")
            bonus.enleverBonus(i)
        elif bonus.bonus_contenu[i] == "ajout_balle":
            xBalle = barres.x[j] + barres.w[j] // 2 - balles.RAYON_BALLE
            yBalle = barres.y[j] + -balles.RAYON_BALLE
            dxBalle = 0
            dyBalle = -config.SPEED
            balles.ajouterBalle(xBalle, yBalle, dxBalle, dyBalle)
            bonus.enleverBonus(i)
        elif bonus.bonus_contenu[i] == "":
            bonus.enleverBonus(i)
        else:
            raise ValueError("Erreur : bonus contenant un type d bonus inconnu : " + bonus.bonus_contenu[i])

    return retour
示例#5
0
def gestionCollisionBallesMurs():
    """Applique les collisions entre les balles et les murs"""
    global collision

    for i in range(balles.nbBalle()):
        balleDy = balles.dy[i]
        balleDx = balles.dx[i]
        ballex1 = balles.x[i] + balleDx
        ballex2 = ballex1 + balles.w[i]
        balley1 = balles.y[i] + balleDy
        balley2 = balley1 + balles.h[i]

        # si la balle entre en collision avec le mur gauche ou le mur droit alors on inverse dx.
        if collision(ballex1, ballex2, balley1, balley2, 0, 0, 0, config.HEIGHT) or collision(
            ballex1, ballex2, balley1, balley2, config.WIDTH, config.WIDTH, 0, config.HEIGHT
        ):
            balles.dx[i] = -balleDx

        # si la balle entre en collision avec le mur haut alors on inverse dy.
        if collision(ballex1, ballex2, balley1, balley2, 0, config.WIDTH, 0, 0):
            balles.dy[i] = -balleDy