I am a beginner programmer practicing with Python. I am trying to make a simple game, what I have so far is just adding the character sprite onto the map. What I'm trying to do is when no keys are being pressed, that the character sprite continuously switches between two animations.
When running the game, it just loads up a black screen and the game freezes if you click on the screen.
CODE:
class Character(pygame.sprite.Sprite):
clock = pygame.time.Clock()
sprite_frame = 0
def __init__(self):
self.standing_right_frame1 = pygame.image.load("C:\\...\\character1_standing_facing_right_1.png")
self.standing_right_frame2 = pygame.image.load("C:\\...\\character1_standing_facing_right_2.png")
self.standing_right = [self.standing_right_frame1, self.standing_right_frame2]
self.rect1 = self.standing_right_frame1.get_rect()
self.rect2 = self.standing_right_frame2.get_rect()
self.rect1.center = (300, 200)
self.rect2.center = (300, 200)
def update(self):
game_running = True
self.sprite_frame = 0
while game_running:
if self.sprite_frame >= len(self.standing_right):
self.sprite_frame = 0
self.character_sprite = self.standing_right[self.sprite_frame]
self.sprite_frame = self.sprite_frame + 1
def draw(self, display):
self.game_screen = display
self.game_screen.blit(self.character_sprite, self.rect)
pygame.init()
character = Character()
#GAME COLORS:
color_black = pygame.Color(0, 0, 0)
color_white = pygame.Color(255, 255, 255)
color_light_grey = pygame.Color(212, 212, 212)
color_grey = pygame.Color(150, 150, 150)
color_dark_grey = pygame.Color(100, 100, 100)
color_dark_green = pygame.Color(41, 169, 48)
#GAME INITIALIZATION
pygame.display.set_caption("My First Game")
screen_width = 800
screen_height = 600
game_screen = pygame.display.set_mode((800, 600))
game_screen.fill(color_white)
game_clock = pygame.time.Clock()
game_clock.tick(60)
game_running = True
# MAIN GAME LOOP
while game_running:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
else:
character.update()
character.draw(game_screen)