''' roll a dice with animation by Ching-Shoei Chiang ''' import pygame, random, sys pygame.init() SCREEN = pygame.display.set_mode((1000,1000)) pygame.display.set_caption("Roll a dice with animation") number = 0 WHITE = (255,255,255) trigger = True #load image image1 = pygame.image.load("dice1.png") image2 = pygame.image.load("dice2.jpg") image3 = pygame.image.load("dice3.png") image4 = pygame.image.load("dice4.png") image5 = pygame.image.load("dice5.jpg") image6 = pygame.image.load("dice6.png") while True: for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() sys.exit() elif event.type == pygame.KEYDOWN: trigger = True elif event.type == pygame.KEYUP: trigger = False if trigger: number = random.randint(1,6) if number == 1: image = image1 elif number == 2: image = image2 elif number == 3: image = image3 elif number == 4: image = image4 elif number == 5: image = image5 else: image = image6 SCREEN.fill(WHITE) SCREEN.blit(image, (0,0)) pygame.display.update()