Advertisement
Guest User

Untitled

a guest
Dec 6th, 2019
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.16 KB | None | 0 0
  1. import pygame
  2. pygame.init()
  3.  
  4. #CHARACTER VALUES
  5. charWidthX = 50
  6. charHeightY = 60
  7. charSpeed = 5
  8. charPosX = 50
  9. charPosY = 50
  10.  
  11. #COLOUR VALUES
  12. black = 0, 0, 0
  13. white = 255, 255, 255
  14. red = 255, 0, 0
  15. green = 0, 255, 0
  16. blue = 0, 0, 255
  17.  
  18. #SCREEN VALUES
  19. screen = pygame.display.set_mode([1000, 650])
  20. screen.fill(blue)
  21. pygame.display.update()
  22. pygame.display.set_caption("Test Game")
  23.  
  24. run = True
  25. while run:
  26. pygame.time.delay(100)
  27.  
  28. for event in pygame.event.get():
  29. if event.type == pygame.QUIT:
  30. run = False
  31.  
  32. keys = pygame.key.get_pressed()
  33.  
  34. if keys[pygame.K_LEFT] and charPosX >= 5:
  35. charPosX -= charSpeed
  36. charPosX -= charSpeed
  37. if keys[pygame.K_RIGHT] and charPosX <= 940:
  38. charPosX += charSpeed
  39. charPosX += charSpeed
  40. if keys[pygame.K_UP] and charPosY >= 5:
  41. charPosY -= charSpeed
  42. charPosY -= charSpeed
  43. if keys[pygame.K_DOWN] and charPosY <= 580:
  44. charPosY += charSpeed
  45. charPosY += charSpeed
  46.  
  47. screen.fill(blue)
  48. pygame.draw.rect(screen, (white), (charPosX, charPosY, charWidthX, charHeightY))
  49. pygame.display.update()
  50.  
  51. pygame.quit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement