欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

xinixn -接彩球游戏

程序员文章站 2024-03-23 21:02:34
...
import pygame # 一个专门用来做游戏的工具包呀
import random
pygame.init() #
ping_mu = pygame.display.set_mode((600, 500))
pygame.display.set_caption("传奇")
ballx = 200
bally = 300
banx,bany,ban_w,ban_h =  100,450 ,120,50
SCORE = 1
while True:
    for event in pygame.event.get():   # for循环是电脑来监测我们的操作
        if event.type == pygame.QUIT:  # 判断是否点了判断按钮
            pygame.quit()   # 如果点了就退出游戏
        # 通过鼠标操纵这个板
        elif event.type == pygame.MOUSEMOTION:
            banx, _ = event.pos

    # 接到小球
    if banx<ballx<banx+ban_w  and bany<bally<bany+ban_h:
        bally = 0
        ballx = random.randint(1,600)
        SCORE = SCORE+1
        print("GET IT:%d"%SCORE)

    ping_mu.fill((255,255,240))
    bally = bally + 1
    if bally > 500:
        bally = 0
        ballx = random.randint(1, 600)
    pygame.draw.circle(ping_mu,(random.randint(1,255),random.randint(1,255),random.randint(1,255)),(ballx,bally),30)
    # 屏幕,颜色,(宽度高度,坐标)
    pygame.draw.rect(ping_mu,(139,101,8),(banx,bany,ban_w,ban_h))
    pygame.display.update()