Advertisement
cookertron

Vertical scrolling background image

Nov 4th, 2018
238
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.86 KB | None | 0 0
  1. # change the name of the filename
  2.  
  3. import pygame
  4. import sys
  5.  
  6. width = 400
  7. heigh = 400
  8. FPS = 60
  9.  
  10. screen = pygame.display.set_mode((width,heigh))
  11. pygame.display.set_caption('Space Invaders: Closing Up')
  12. clock = pygame.time.Clock()
  13.  
  14. class Background():
  15.     def __init__(self):
  16.         self.image = pygame.image.load('background.jpg').convert() # change the nam
  17.         self.w, self.h = self.image.get_rect().size
  18.         self.y = 0
  19.        
  20.     def update(self, display):
  21.         self.y += 1
  22.         if self.y > self.h:
  23.             self.y = 0 
  24.            
  25.         display.blit(self.image, (0, self.y))
  26.         display.blit(self.image, (0, self.y - self.h))
  27.        
  28. bg = Background()      
  29. while True:
  30.     for event in pygame.event.get():
  31.         if event.type == pygame.QUIT or (event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE):
  32.             pygame.quit()
  33.             sys.exit()
  34.    
  35.     bg.update(screen)
  36.    
  37.     pygame.display.update()
  38.     clock.tick(FPS)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement