Advertisement
metalx1000

Basic PyGame script

Nov 22nd, 2018
1,126
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.15 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. import pygame
  4. from pygame.locals import*
  5.  
  6. #create player
  7. player = pygame.image.load('player.png')
  8. player_x = 0
  9. player_y = 0
  10. player_r = 0
  11.  
  12. #set screen size and background color
  13. bg = (255, 64, 64)
  14. w = 640
  15. h = 480
  16. screen = pygame.display.set_mode((w, h))
  17. screen.fill((bg))
  18.  
  19.  
  20. #main loop
  21. while True:
  22.   screen.fill((bg))
  23.  
  24.   #check for key press
  25.   for event in pygame.event.get():
  26.     if event.type == pygame.KEYDOWN:
  27.       #print event.key
  28.       if (event.key == pygame.K_ESCAPE) or (event.key == pygame.K_q):
  29.         pygame.quit();
  30.  
  31.   #Check for continuous key pressess
  32.   keys = pygame.key.get_pressed()
  33.   if keys[pygame.K_RIGHT]:
  34.     player_x+=1
  35.   if keys[pygame.K_LEFT]:
  36.     player_x-=1
  37.   if keys[pygame.K_UP]:
  38.     player_y-=1
  39.   if keys[pygame.K_DOWN]:
  40.     player_y+=1
  41.   if keys[pygame.K_r]:
  42.     #    player_r+=.01
  43.     #    player_rect = player.get_rect(center=image_rect.center)
  44.         #screen.blit(image, image_rect)
  45.     print "nope"
  46.     #player = pygame.transform.rotate(player, player_r)
  47.  
  48.   #draw player to screen
  49.   screen.blit(player,(player_x,player_y))
  50.  
  51.   #update display
  52.   pygame.display.flip()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement