רובוטרוניקס מפתחת משחקי מחשב מבוססי בינה מלאכותית ומעבירה קורסים בתחום
פיתוח משחקי מחשב – RB24-03 – מבוססי בינה מלאכותית
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
import pygame import sys # Initialize Pygame pygame.init() # Set the width and height of the screen (in pixels) WIDTH, HEIGHT = 800, 600 # Create the screen screen = pygame.display.set_mode((WIDTH, HEIGHT)) pygame.display.set_caption("Change Sprite with Space Bar") # Define colors WHITE = (255, 255, 255) # Load sprites sprite_images = [ pygame.image.load('D:/temp4/shotting-range/S1/1.png').convert_alpha(), pygame.image.load('D:/temp4/shotting-range/S1/2.png').convert_alpha(), pygame.image.load('D:/temp4/shotting-range/S1/3.png').convert_alpha() ] current_sprite_index = 0 # Main loop running = True clock = pygame.time.Clock() while running: # Handle events for event in pygame.event.get(): if event.type == pygame.QUIT: running = False elif event.type == pygame.KEYDOWN: if event.key == pygame.K_SPACE: current_sprite_index = (current_sprite_index + 1) % len(sprite_images) elif event.key == pygame.K_q: running = False # Fill the screen with white screen.fill(WHITE) # Display the current sprite current_sprite = sprite_images[current_sprite_index] screen.blit(current_sprite, (WIDTH/2 - current_sprite.get_width()/2, HEIGHT/2 - current_sprite.get_height()/2)) # Update the display pygame.display.flip() # Limit the frame rate clock.tick(30) # Quit Pygame pygame.quit() sys.exit() |