vendredi 27 septembre 2019

Why does my game ignore my true false statement?

I made a game on pygame. I want the player speed to change once the health reaches a certain point. I have tried a combination of if/else statements and true/false statements - the speed still won't change. Here is the relevent code:

class Player(pg.sprite.Sprite):
    def __init__(self, game, x, y):
        self.health = PLAYER_HEALTH
        self.speed = True
        if PLAYER_HEALTH <= 20:
            self.speed == False
        if PLAYER_HEALTH >= 20:
            self.speed == True

    def get_keys(self):
        PLAYER_RUN = 55
        PLAYER_RUNS = 300
        self.rot_speed = 0
        self.vel = vec(0, 0)
        keys = pg.key.get_pressed()
        if keys[pg.K_UP] or keys[pg.K_w]:
            if self.speed == True:
                self.vel = vec(PLAYER_RUNS, 0).rotate(-self.rot)
            else:
                self.vel = vec(PLAYER_RUN, 0).rotate(-self.rot)
        if keys[pg.K_DOWN] or keys[pg.K_s]:
            if self.speed == True:
                self.vel = vec(-PLAYER_RUNS / 2, 0).rotate(-self.rot)
            else:
                self.vel = vec(-PLAYER_RUN / 2, 0).rotate(-self.rot)

This is the code from the file I use to define my sprites. I thought that importing this file with its changes would be enough to make the speed change, but it doesn't work. I even added code to the main loop that dealt with player damage:

if self.player.health <= 20:
    print(CONSTANT[hit_count])
    self.player.speed == False
    self.player.health += CONSTANT.popleft()
    hit_count += 1
    hit.vel = vec(0, 0)
elif self.player.health >= 20
    print(CONSTANT[hit_count])
    self.player.speed == True
    self.player.health += CONSTANT.popleft()

Do you see anything that can explain why the player speed won't switch after the player health hits a certain point?

Aucun commentaire:

Enregistrer un commentaire