main.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import pygame
  2. from sys import exit
  3. pygame.init()
  4. screen = pygame.display.set_mode((800,400))
  5. pygame.display.set_caption('Runner Tutorial')
  6. clock = pygame.time.Clock()
  7. test_font = pygame.font.Font('Pixeltype.ttf', 50)
  8. sky_surface = pygame.image.load('Sky.png').convert()
  9. ground_surface = pygame.image.load('Ground.png').convert()
  10. text_surface = test_font.render('MY GAME', False, 'Black')
  11. #jaguar_surface = pygame.image.load('jaguar.png').convert_alpha()
  12. #jaguar_rect = jaguar_surface.get_rect(bottomright = (600,300))
  13. player_surf = pygame.image.load('sloth1.png').convert_alpha()
  14. player_rect = player_surf.get_rect(midbottom = (80, 300))
  15. while True:
  16. for event in pygame.event.get():
  17. if event.type == pygame.QUIT:
  18. pygame.quit()
  19. exit()
  20. screen.blit(sky_surface,(0,0))
  21. screen.blit(ground_surface,(0, 300))
  22. screen.blit(text_surface,(300, 50))
  23. #jaguar_rect.x -= 4
  24. #if jaguar_rect.right <= 0:
  25. # jaguar_rect.left = 800
  26. #screen.blit(jaguar_surface, jaguar_rect)
  27. keys = pygame.key.get_pressed()
  28. centerX, centerY = player_rect.center
  29. rot = player_surf
  30. angle = 0
  31. if keys[pygame.K_d]:
  32. angle -= 5
  33. rot = pygame.transform.rotate(player_surf, angle)
  34. if keys[pygame.K_a]:
  35. angle += 5
  36. player_surf = pygame.transform.rotate(player_surf, angle)
  37. screen.blit(rot, player_surf.get_rect(center = (centerX, centerY)))
  38. #if player_rect.colliderect(jaguar_rect):
  39. # print('collision')
  40. # draw all our elements
  41. # update everything
  42. pygame.display.update()
  43. clock.tick(60)