用户:
仰>v<~查看:1 回复:3 评论:1 创建时间:2021-07-22T13:26:46
求大神PVZ里捡阳光的操作代码
import pygame
import sys
pygame.init()
mouse_down_x, mouse_down_y = pygame.mouse.get_pos()
sun_have = 0
sun_math = 0
run_x = 40 # 假设
run_y = 40
screen = pygame.display.set_mode((400,400))
def run_color(color):# yellow
pygame.draw.rect(screen, (color), (run_x, run_y, 20, 20), (100)) # 大小
clock = pygame.time.Clock()
while True:
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
print(mouse_down_x,' ',mouse_down_y)
if mouse_down_x == run_x and mouse_down_y == run_y:
run_color(255, 255, 255)
pygame.draw.rect(screen, (255,255,255), (run_x, run_y, 20, 20), (100))
run_have += 25 # 或者50
run_math -= 1
if sun_math > 1:
run_color(255, 255, 0)
pygame.draw.rect(screen, (255,255,0), (run_x, run_y, 20, 20), (100))
clock.tick(25)
pygame.display.update()点赞1
评论