"""
小弹球
1. 搭建项目
2. 绘制一个小球上下移动
3. 弹球
4. 小球碰撞边一次 修改小球颜色值
5. 5个小球同时运行碰撞
6. 计算小球碰撞得分 score +1 显示出来
7. 根据score调整速度 100 200 300
"""
import pygame,sys
import random
R = 0
G = 0
B = 0
xx = []
yy = []
ff = []
score = 0
speed = 0
"""
一、主函数
"""
def menu():
# 1.设置窗口标题
pygame.display.set_caption("小弹球游戏")
# 2.死循环
while True:
# 3.设置背景颜色填充
screen.fill((255,255,255))
# 4.调用业务处理函数
action()
# 5.调用图形图案绘制函数
paint()
# 6.屏幕刷新延迟
pygame.time.delay(speed)
# 7.设置窗口刷新屏幕
pygame.display.update()
"""
二、变量声明初始化区域
"""
# 设置窗体
screen = pygame.display.set_mode((800,600),0,0)
"""
三、业务逻辑处理区域
"""
def action():
# 3.1 循环迭代事件监听
for event in pygame.event.get():
# 3.2 判断是否退出系统
if event.type == pygame.QUIT:
sys.exit()
# 3.3 执行业务逻辑代码
global xx,yy,ff,score
for i in range(0,5):
# 3.3.1根据飞行方向修改坐标
if ff[i] == 0:
xx
python:pygame小游戏(一)——myBall 小弹球
最新推荐文章于 2025-07-22 09:44:38 发布