Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import pygame
- import random
- #Настройки окна
- WIDTH = 500
- HEIGHT = 500
- FPS = 60
- # Pipes
- pipes = []
- pipecd = 1200
- lastPipeTime = 0
- # Цвета
- YELLOW = (255, 255, 0)
- SKY = (133, 193, 233)
- GREEN = (46, 204, 113)
- WHITE = (255, 255, 255)
- #Инициализация
- pygame.init()
- screen = pygame.display.set_mode((WIDTH,HEIGHT))
- clock = pygame.time.Clock()
- # Настройки персонажа
- bird = pygame.Rect(40, 250, 30, 23)
- birdImg = pygame.image.load('fpbs1.png')
- points = 0
- # Шрифты
- font = pygame.font.SysFont('comic sans ms', 30)
- game_over_font = pygame.font.SysFont('comic sans ms', 50)
- game_over_text = game_over_font.render('GAME OVER', 1, WHITE)
- # Падение
- GRAVITY = 0.3
- y_change = 0
- # Прыжок
- isJump = False
- jumpCount = 10
- # Настройки труб
- pipes = []
- pipecd = 1500
- # Добавление очков
- check = []
- # Временные параметры
- clock = pygame.time.Clock()
- currentTime = 0
- lastPipeTime = 0
- game_over = False
- running = True
- while running:
- screen.fill(SKY)
- for i in pygame.event.get():
- if i.type == pygame.QUIT:
- running = False
- if i.type == pygame.KEYDOWN:
- if i.key == pygame.K_SPACE:
- isJump = True
- hopCount = 0
- # Прыжок
- if isJump:
- hopCount += 1
- bird.top -= 6
- if hopCount == 5:
- y_change = 0
- isJump = False
- # Падение
- else:
- y_change += GRAVITY
- bird.top += y_change
- # Текущее время
- currentTime = pygame.time.get_ticks()
- if currentTime - lastPipeTime > pipecd:
- width_pipe = 40
- height_up_pipe = random.randint(50,400)
- height_down_pipe = HEIGHT - 100 - height_up_pipe
- up_pipe = pygame.Rect(WIDTH, 0, width_pipe, height_up_pipe)
- y_down_pipe = 100 + height_up_pipe
- down_pipe = pygame.Rect(WIDTH, y_down_pipe,width_pipe, height_down_pipe)
- pipes.append((up_pipe, down_pipe))
- middle_pipe = pygame.Rect(WIDTH, height_up_pipe,width_pipe, 100 )
- check.append(middle_pipe)
- pipecd = random.randint(1500,2000)
- lastPipeTime = currentTime
- # Столкновение
- # Столкновение птички с краями окна игры
- if bird.top < 0 or bird.bottom > HEIGHT:
- game_over = True
- screen.blit(birdImg, (bird.left, bird.top))
- for pipe in pipes:
- pygame.draw.rect(screen, GREEN, pipe[0])
- pygame.draw.rect(screen, GREEN, pipe[1])
- pipe[0].x -= 2
- pipe[1].x -=2
- if pipe[0].colliderect(bird) or pipe[1].colliderect(bird):
- game_over = True
- for ch in check:
- ch.x -= 2
- if ch.colliderect(bird):
- points += 1
- check.remove(ch)
- point_text = font.render(points, True, WHITE)
- screen.blit(point_text, (245,245))
- if game_over:
- screen.fill(SKY)
- screen.blit(game_over_text, (80,120))
- clock.tick(FPS)
- pygame.display.update()
- pygame.quit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement