用户:
耐心的胆小菇N_vj查看:0 回复:0 评论:0 创建时间:2021-07-29T15:47:57
import pygame#游戏
import sys#系统(不需要)
import time#时间
import random#随机
pygame.init()
screen = pygame.display.set_mode((600,320))#创建屏幕
pygame.display.set_caption("pvz")#设置名字
def rect(s = screen,c1=0,c2=0,c3=0,xfg=0,yfg=0,b1 = 20,b2 = 20):
pygame.draw.rect(s,(c1,c2,c3),(xfg,xfg,b1,b2))
quit = True
screen.fill((0,255,0))
clock = pygame.time.Clock()
mouse_down_x, mouse_down_y = pygame.mouse.get_pos()
def f_g():
pygame.draw.rect(screen,(0,255,255),(mouse_down_x,mouse_down_y,20,20),(0))
while quit:
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
if event.type == pygame.MOUSEBUTTONDOWN:#鼠标事件
mouse_down_x, mouse_down_y = event.pos#读取鼠标事件,位置
pygame.draw.rect(screen,(0,0,255),(mouse_down_x,mouse_down_y,10,10),(0))
print(mouse_down_x,' ',mouse_down_y)
f_g()
clock.tick(25)
pygame.display.update()