Advertisement
Guest User

Untitled

a guest
Nov 14th, 2019
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.45 KB | None | 0 0
  1. import pygame
  2. import neat
  3. import os
  4. import random
  5. import time
  6. #######################
  7. WINDOW_WIDTH = 800
  8. WINDOW_HEIGHT = 800
  9. pygame.init()
  10. win = pygame.display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT))
  11. #######################
  12. images = [pygame.transform.scale2x(pygame.image.load(os.path.join("images","bird1.png"))),pygame.transform.scale2x(pygame.image.load(os.path.join("images","bird2.png"))),pygame.transform.scale2x(pygame.image.load(os.path.join("images","bird3.png")))]
  13. backgroundImage = pygame.transform.scale(pygame.image.load(os.path.join("images","bg.png")),(800,800))
  14. pipeImage = pygame.transform.scale2x(pygame.image.load(os.path.join("images","pipe.png")))
  15.  
  16.  
  17. class Bird:
  18.  
  19.  
  20.     def __init__(self,x,y):
  21.         self.x = x  #initial x and y positions
  22.         self.y = y
  23.         self.animationCounter = 0
  24.         self.animation = images[0]
  25.         self.isAlive = True
  26.  
  27.     def flap(self):
  28.         self.y -= 30
  29.  
  30.     def grav(self):
  31.         self.y +=15
  32.  
  33.     def ani(self):
  34.         if(self.animationCounter == 0):
  35.             self.animationCounter +=1
  36.         elif(self.animationCounter == 1):
  37.             self.animationCounter +=1
  38.         elif(self.animationCounter == 2):
  39.             self.animationCounter = 0
  40.         self.animation = images[self.animationCounter]
  41.  
  42.     def isOffScreen(self):
  43.         if(self.y<= 0 or self.y >= 730):
  44.             return True
  45.         else:
  46.             return False
  47.  
  48.    
  49.    
  50.    
  51.  
  52.  
  53.  
  54.  
  55. def draw(win,bird):
  56.     bird.ani()
  57.     win.blit(backgroundImage, (0,0))
  58.     win.blit(bird.animation, (bird.x,bird.y))
  59.     if(bird.animationCounter<2):
  60.         bird.animationCounter+=1
  61.     else:
  62.         bird.animationCounter=0
  63.     pygame.display.update()
  64.    
  65.    
  66. def main():
  67.     bird = Bird(150,150)
  68.     run = True
  69.     while(run):
  70.         if(bird.isAlive):
  71.             for event in pygame.event.get():
  72.                 if event.type == pygame.QUIT:
  73.                     run = False
  74.             keys = pygame.key.get_pressed()
  75.             if(keys[pygame.K_UP]):
  76.                 bird.flap()
  77.             else:
  78.                 bird.grav()
  79.        
  80.             draw(win, bird)
  81.             if(bird.isOffScreen()):
  82.                 bird.isAlive=False
  83.         else:
  84.             print('ohno')
  85.             break
  86.            
  87.            
  88.  
  89.            
  90.     win.blit(backgroundImage, (0,0))
  91.     pygame.display.update()
  92.     pygame.time.delay(5000)
  93.     pygame.quit()
  94.    
  95.  
  96.  
  97. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement