Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pygame
- import neat
- import os
- import random
- import time
- #######################
- WINDOW_WIDTH = 800
- WINDOW_HEIGHT = 800
- pygame.init()
- win = pygame.display.set_mode((WINDOW_WIDTH, WINDOW_HEIGHT))
- #######################
- 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")))]
- backgroundImage = pygame.transform.scale(pygame.image.load(os.path.join("images","bg.png")),(800,800))
- pipeImage = pygame.transform.scale2x(pygame.image.load(os.path.join("images","pipe.png")))
- class Bird:
- def __init__(self,x,y):
- self.x = x #initial x and y positions
- self.y = y
- self.animationCounter = 0
- self.animation = images[0]
- self.isAlive = True
- def flap(self):
- self.y -= 30
- def grav(self):
- self.y +=15
- def ani(self):
- if(self.animationCounter == 0):
- self.animationCounter +=1
- elif(self.animationCounter == 1):
- self.animationCounter +=1
- elif(self.animationCounter == 2):
- self.animationCounter = 0
- self.animation = images[self.animationCounter]
- def isOffScreen(self):
- if(self.y<= 0 or self.y >= 730):
- return True
- else:
- return False
- def draw(win,bird):
- bird.ani()
- win.blit(backgroundImage, (0,0))
- win.blit(bird.animation, (bird.x,bird.y))
- if(bird.animationCounter<2):
- bird.animationCounter+=1
- else:
- bird.animationCounter=0
- pygame.display.update()
- def main():
- bird = Bird(150,150)
- run = True
- while(run):
- if(bird.isAlive):
- for event in pygame.event.get():
- if event.type == pygame.QUIT:
- run = False
- keys = pygame.key.get_pressed()
- if(keys[pygame.K_UP]):
- bird.flap()
- else:
- bird.grav()
- draw(win, bird)
- if(bird.isOffScreen()):
- bird.isAlive=False
- else:
- print('ohno')
- break
- win.blit(backgroundImage, (0,0))
- pygame.display.update()
- pygame.time.delay(5000)
- pygame.quit()
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement