用pygame做一个简单的python游戏 - 彩色同心

用pygame做一个简单的python游戏 - 彩色同心

玩法:历次点击鼠标时,会以鼠标为重心,连接向外扩充圆(一致于水海浪的分散),进而产生一个专心圆,并到达随机巨细后遏止扩充。个中每个专心圆的脸色都是随机的。

import pygame, random, sys, time

pygame.init()

screen = pygame.display.set_mode([600, 400])

screen.fill((255, 255, 255))

radiusr = 0

arrradiusr = [0] * 10 # 圆的半径

arraddradiusr = [0] * 10 # 圆的半径增量

arrradiusbool = [False] * 10 # 圆能否生存 False代办该索引值下的圆不生存,True代办生存

arrradiusx = [0] * 10 # 圆的坐标x轴

arrradiusy = [0] * 10 # 圆的坐标y轴

RGBx = [0] * 10 # 脸色RGB值第一个值

RGBy = [0] * 10 # 脸色RGB值第二个值

RGBz = [0] * 10 # 脸色RGB值第三个值

while True:

time.sleep(0.1) # 0.1秒

for event in pygame.event.get(): # 监听器

if event.type == pygame.MOUSEBUTTONDOWN: # 鼠标按下

num = arrradiusbool.index(False) #获得圆不生存的索引值

arrradiusbool[num] = True #将该索引值的圆树立为生存

arrradiusr[num] = 0 #该圆的半径树立为0

arrradiusx[num], arrradiusy[num] = pygame.mouse.get_pos() #获得鼠标坐标

RGBx[num] = random.randint(0, 255) #获得脸色值

RGBy[num] = random.randint(0, 255) #获得脸色值

RGBz[num] = random.randint(0, 255) #获得脸色值

pygame.draw.circle(screen, pygame.Color(RGBx[num], RGBy[num], RGBz[num]), #画圆

(arrradiusx[num], arrradiusy[num]), arrradiusr[num], 1)

if event.type == pygame.QUIT:

pygame.quit()

sys.exit()

for i in range(10):

if arrradiusbool[i] == False: #即使圆不生存则跳过轮回

pass

else:

if (arrradiusr[i] < random.randint(10, 50)): #随机圆的巨细

arraddradiusr[i] = random.randint(0, 5) #圆的随机半径增量

arrradiusr[i] += arraddradiusr[i]

pygame.draw.circle(screen, pygame.Color(RGBx[i], RGBy[i], RGBz[i]), #画圆

(arrradiusx[i], arrradiusy[i]), arrradiusr[i], 1)

else:

arrradiusbool[i] = False #若圆已到达最大,这将该索引值的圆树立为不生存

pygame.display.update()

分享到 :

Leave a Reply

Your email address will not be published. Required fields are marked *