san560

Untitled

Dec 11th, 2017
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. this is my entire main file
  2.  
  3. import pygame as pg
  4. from settings import *
  5. from sprites import *
  6.  
  7. #initializes pygame
  8. pg.init()
  9. pg.mixer.init()
  10. screen = pg.display.set_mode((WIDTH,HEIGHT))
  11. pg.display.set_caption("My Game")
  12. clock = pg.time.Clock()
  13. #adds and spawns them in group
  14. all_sprites = pg.sprite.Group()
  15. platforms = pg.sprite.Group()
  16. #adds the sprite to group and spawns the sprites
  17. player = Player()
  18. all_sprites.add(player)
  19. p1 = Platform(0, HEIGHT - 40, WIDTH, 40)
  20. all_sprites.add(p1)
  21. platforms.add(p1)
  22. p2 = Platform(WIDTH / 2 - 50, HEIGHT - 300, 100, 20)
  23. all_sprites.add(p2)
  24. platforms.add(p2)
  25.  
  26. #Game loop
  27. running = True
  28. while running:
  29. #keep loop running at the right speed
  30. clock.tick(FPS)
  31. #proccess input(events)
  32. for event in pg.event.get():
  33. #check for closing the window
  34. if event.type == pg.QUIT:
  35. running = False
  36. if event.type == pg.KEYDOWN:
  37. if event.key == pg.K_SPACE:
  38. player.jump()
  39.  
  40.  
  41. #Update
  42. all_sprites.update()
  43. hits = pg.sprite.spritecollide(player, platforms, False)
  44. if hits:
  45. player.pos.y = hits[0].rect.top + 1
  46. player.vel.y = 0
  47.  
  48. #Draw / render
  49. screen.fill(BLACK)
  50. all_sprites.draw(screen)
  51. #after drawing everything_flip the display
  52. pg.display.flip()
  53.  
  54. pg.quit()
Advertisement
Add Comment
Please, Sign In to add comment