import pygame # Pygame setup pygame.display.init() # Optional -- get the MONITOR resolution... video_info = pygame.display.Info() win_width = video_info.current_w win_height = video_info.current_h is_fullscreen = False # Create the (windowed) screen screen = pygame.display.set_mode((800, 600)) running = True # Create some variables x = 400 y = 300 rad = 50 speed = 0.1 # GAME LOOP while running: # INPUT-HANDLING # ... this is the heart of event-handling. Does two things: # a. gives us one event to handle (or not) # b. saves the state of all input devices (mouse, keyboard, gamepads) evt = pygame.event.poll() # ... do some EVENT-HANDLING if evt.type == pygame.QUIT: # The user just clicked the close button running = False elif evt.type == pygame.KEYDOWN: # The user just pressed a keyboard button. if evt.key == pygame.K_F5: if is_fullscreen: screen = pygame.display.set_mode((800, 600)) is_fullscreen = False else: screen = pygame.display.set_mode((win_width, win_height), pygame.FULLSCREEN) is_fullscreen = True elif evt.key == pygame.K_LSHIFT or evt.key == pygame.K_RSHIFT: speed = 1 elif evt.type == pygame.KEYUP: if evt.key == pygame.K_LSHIFT or evt.key == pygame.K_RSHIFT: speed = 0.1 # ... do some DEVICE-POLLING pressed_keys = pygame.key.get_pressed() # ... the full list of keys can be found at: http://pygame.org/docs/ref/key.html if pressed_keys[pygame.K_ESCAPE]: running = False if pressed_keys[pygame.K_a] or pressed_keys[pygame.K_LEFT]: x -= speed # Hmmmm... if pressed_keys[pygame.K_d] or pressed_keys[pygame.K_RIGHT]: x += speed # Hmmmm... # UPDATE-VARIABLES if x < rad: x = rad if x > screen.get_width() - rad: x = screen.get_width() - rad # DRAWING screen.fill((0, 0, 0)) pygame.draw.circle(screen, (255,0,0), (int(x), y), rad) pygame.display.flip() # Pygame shutdown pygame.display.quit()