从零开始学python要多久_【图片】从0开始学用Python做游戏的全过程【精品贴】(不定期更新)【python吧】_百度贴吧...

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼

"""

下雨了

"""

import pygame #导入pygame模块

import random #导入random模块

pygame.init() #初始化Pygame

screen = pygame.display.set_mode([800, 600]) #创建一个宽800像素高600像素的显示窗口

keep_going = True #布尔值控制游戏循环

BLACK = (0, 0, 0) #定义黑色RGB值

colors = [0] * 100 #初始化100个颜色

locations = [0] * 100 #初始化100个坐标

sizes = [0] * 100 #初始化100个大小

for n in range(100): #循环100次

colors[n] = (random.randint(0, 255), random.randint(0, 255), random.randint(0, 255)) #为100个颜色赋值随机RGB颜色

locations[n] = (random.randint(0, 800), random.randint(0, 600)) #为100个位置赋值800*600内的随机坐标

sizes[n] = random.randint(10, 100) #为100个大小赋值随机10-100的整数

while keep_going: #游戏循环

for event in pygame.event.get(): #处理所有触发的交互事件

if event.type == pygame.QUIT: #点击退出

keep_going = False #退出循环

for n in range(100): #循环100次

pygame.draw.circle(screen, colors[n], locations[n], sizes[n]) #画第n个随机圆

new_x = locations[n][0] + 1 #x坐标+1

new_y = locations[n][1] + 1 #y坐标+1

if new_x > 800: #如果飞出了右屏幕,则回到左屏幕

new_x -= 800

if new_y > 600: #如果飞出了下屏幕,则回到上屏幕

new_y -= 600

locations[n] = (new_x, new_y) #更新100个坐标

pygame.display.update() #刷新屏幕

screen.fill(BLACK) #全屏涂黑,达到清屏效果,以产生动画效果

pygame.quit() #退出游戏

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值