+关注
已关注

分类  

暂无分类

标签  

暂无标签

日期归档  

2020-09(1)

接小球(简单版)

发布于2020-09-05 17:50     阅读(326)     评论(0)     点赞(0)     收藏(0)


0

1

2

3

4

5

6

7

8

9

import pygame

import random


def show_text(text, pos, size, screen):
    f = pygame.font.Font("庞门正道粗书体.ttf", size)
    t = f.render(text, True, [0, 0, 0])
    screen.blit(t, pos)

def game():
    pygame.init()
    screen = pygame.display.set_mode((800, 600))
    pygame.display.set_caption("game")
    running = True
    circle_x = random.randint(50, 750)
    circle_y = 0
    rect_x = 310
    rect_y = 560
    ms = 3
    fs = 0
    speed = 3

    while running == True:
        screen.fill([105, 165, 184])

        if ms > 0:
            pygame.draw.circle(screen, [200, 200, 200], [circle_x, circle_y], 50, 0)
            pygame.draw.rect(screen, [0, 0, 0], [rect_x, rect_y, 150, 40], 0)
            show_text("命数:" + str(ms), (2, 2), 34, screen)
            show_text("分数:" + str(fs), (650, 2), 34, screen)
            circle_y = circle_y + speed
            pygame.display.update()

            if circle_y > 575:
                circle_y = 0
                circle_x = random.randint(50, 750)
                ms = ms - 1

            if 0 <= rect_y - circle_y <= 50 and rect_x - 50 <= circle_x <= rect_x + 200:
                circle_y = 0
                circle_x = random.randint(50, 750)
                fs = fs + 1

                if fs % 20 == 0:
                    speed = speed + 1

        else:
            show_text("GAME OVER", (3, 120), 180, screen)
            show_text("获得分数" + str(fs), (310, 300), 50, screen)
            pygame.display.update()

        for event in pygame.event.get():

            if event.type == pygame.QUIT:
                running = False

            if event.type == pygame.MOUSEMOTION:
                rect_x, rect_y = event.pos
                rect_y = 560

game()

0

1

2

3

4

5

6

7



所属网站分类: 资源下载 > python小游戏

作者:ouye123

链接: https://www.pythonheidong.com/blog/article/506616/3c5d668bde72e7fa79df/

来源: python黑洞网

任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任

0 0
收藏该文
已收藏

评论内容:(最多支持255个字符)