import random
import pygame
from pygame import *
import time
# loading初始化
pygame.init() # 1.初始化
screen = pygame.display.set_mode((600,500)) # 3.设置窗口大小
pygame.display.set_caption("接小球游戏")
rect_x, rect_y, rect_w, rect_h = 0, 460, 120, 40
ball_x = 100
ball_y = 100
# 设置一个变量
down = True
while True:
for event in pygame.event.get():
print(event)
if event.type == pygame.QUIT:
pygame.quit()
elif event.type==pygame.MOUSEMOTION:
rect_x,_ = event.pos
screen.fill((255,255,255))
# if down:
# ball_y = ball_y+1
# if ball_y>500:
# down = False
# else:
# ball_y = ball_y-1
# if ball_y<0:
# down = True
ball_y+=1
if ball_y >500:
ball_y=0
ball_x = random.randint(0,600)
pygame.draw.circle(screen, (0,255,255),(ball_x ,ball_y),15,0) #锯齿化
pygame.draw.rect(screen, (30, 0, 0), (rect_x, rect_y, rect_w, rect_h ), 0)
pygame.display.update() # 刷新页面
pygame.quit() # 2.退出游戏
Runze- take a small ball game
Guess you like
Origin blog.csdn.net/houlaos/article/details/102642323
Recommended
Ranking