mardi 10 septembre 2019

Why wont my code switch back and forth between lists?

I have two lists in my game that I want to switch between in my method.

I am working on a game where at a certain point, if a box is broken, a color is printed on the screen - those colors show up in a particular order, and are in a list. There are 3 levels: A, B, and C. I have this set up so that the levels switch one the player's health reaches a certain point. I want the lists to switch each time a new level begins. So if Level A starts in List A, I want level B to switch to list B and level C to switch back to list A.

I don't know why my code isn't working. I have "if" statements that are contingent on the player health, but the switch isn't happening.

In this code boxes are broken by 'shards'. BoxA and BoxB are lists. What I thought would happen is that when the player's health was less than 20, BoxA would be used. When the player's health is above 20, Box B should be used. When health is above 40, BoxA should be used again.

    hits = pg.sprite.groupcollide(self.boxs, self.shards, False, True)
    hit_count = 0

    for hit in hits:
        font1 = pg.font.SysFont('comicsans', 100)
        if BOXA[hit_count] == GRE:
            text = font1.render('green', 1, (GREEN))
            #self.effects_sounds['lose_sound'].play()
        elif BOXA[hit_count] == BLU:
            text = font1.render('blue', 1, (CYAN))
        elif BOXB[hit_count] == YEL:
            text = font1.render('yellow', 1, (YELLOW))
        elif BOXB[hit_count] == RE:
            text = font1.render('red', 1, (RED))
            #self.effects_sounds['jackpot_sound'].play()

        self.screen.blit(text, (250 -(text.get_width()/2),200))
        pg.display.update()
        i = 0
        while i < 100:
            pg.time.delay(10)
            i += 1
            for event in pg.event.get():
                if event.type == pg.QUIT:
                    i = 301
                    pg.quit()
        hit.health -= SHARD_DAMAGE
        if self.player.health < 20:
            self.player.health += 0
            hit.health += BOXA.popleft()
            hit_count += 1
            print('lvl_A')

        if self.player.health > 20 and self.player.health < 40:
            hit.health += BOXB.popleft()
            self.player.health += 0
            print('lvl_B')

        elif self.player.health > 40:
            self.player.health += 0
            hit.health += BOXA.popleft()
            print('lvl_C')

The lists are defined in a separate file that I import into the main code. Here is an example list:

BOXA =  deque([BLU, GRE, BLU, BLU, GRE, GRE, GRE, BLU, GRE, BLU, BLU, BLU])
BOXB = deque([YEL, YEL, RE, YEL, RE, RE, RE, YEL])
#BLU = 1
#GRE = 2
#YEL = 7
#RE = 4

I'm really not sure why it isn't switching, so any insight would be appreciated!

Aucun commentaire:

Enregistrer un commentaire