Giới thiệu sản phẩm

Tìm hiểu chủ đề: Nhà phát hành game - Nintendo 
Kiến thức, khái niệm: Vận dụng thư viện pygame để hoàn thiện trò chơi tetris
Dự án trò chơi Tetris: Hoàn thiện trò chơi xếp gạch

import pygame
import random

pygame.init()
screen = pygame.display.set_mode((400, 600))
pygame.display.set_caption("Flappy ")
img = pygame.image.load("flappybirdbg.png")
player_img = pygame.image.load("flappybird1.png")
player = pygame.transform.scale(player_img, (32, 32))
clock = pygame.time.Clock()

x = 0
y = 100
gravity = 0.5
velocity = 0

pipe_x = 800
top_pipe_y = random.randint(100, 300) 
gap_height = 150 

while True:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                exit()
            if event.type == pygame.KEYDOWN and event.key == pygame.K_SPACE:
                velocity = -10
            if event.type == pygame.MOUSEBUTTONDOWN:
                velocity = -10

        screen.fill((135, 206, 235))
        screen.blit(img, (x, 0))
        screen.blit(img, (x + img.get_width(), 0))
        x -= 2
        if x < -img.get_width():
            x = 0

        velocity += gravity
        y += velocity
        screen.blit(player, (300, y))

        pygame.draw.rect(screen, (0, 255, 0), (pipe_x, 0, 50, top_pipe_y))
        bottom_pipe_y = top_pipe_y + gap_height
        pygame.draw.rect(screen, (0, 255, 0), (pipe_x, bottom_pipe_y, 50, 600 - bottom_pipe_y))

        pipe_x -= 3
        if pipe_x < -50:
            pipe_x = 800
            top_pipe_y = random.randint(100, 300)

        pygame.display.flip()
        clock.tick(60)

Hình ảnh sản phẩm
Hãy bình luận để nhặt 100 thóc nhé

Đăng nhập để tham gia bình luận