pygame游戏模版框架_鼠标指针移动圆圈盖图章

"""游戏模版框架_鼠标指针移动圆圈盖图章.py
"""

__author__ = "李兴球"
__date__ = "2019年1月"
__company__ = "风火轮少儿编程"

import pygame
 
# 定义颜色常量
BLACK = (0, 0, 0)
WHITE = (255, 255, 255)
GREEN = (0, 255, 0)
RED = (255, 0, 0)
CYAN = (0, 255, 255) 
 
def produce_stamp():

    surface = pygame.Surface((50,50))
    surface.set_colorkey((0,0,0))
    # 在这个面上画一个圆形
    pygame.draw.circle(surface, CYAN, (25,25),25)

    return surface
 
# 启动派gei引擎
pygame.init()
 
# 设置屏幕对象
size = [700, 500]
screen = pygame.display.set_mode(size) 
pygame.display.set_caption("游戏模版框架_鼠标指针移动圆圈盖图章_作者:李兴球")

circle = produce_stamp()
stamps = {}                # 记录图层和它的渲染坐标

# 退出while循环的利器,当单击窗口关闭按钮时的事件发生时它的值会为True
done = False
 
# 这是用来控制帧率的时钟变量
clock = pygame.time.Clock()
 
# 隐藏鼠标指针
pygame.mouse.set_visible(0)
 
# -------- Main Program Loop -----------
while not done:
    # 迭代所发生的每件事
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            done = True
    # 获取鼠标指针的坐标
    pos = pygame.mouse.get_pos()
    x = pos[0]
    y = pos[1]
    
    click = pygame.mouse.get_pressed()
    # 如果单击左键,则"盖一个图章",放入字典,键为surface,值为中心点坐标
    if click[0] : stamps[produce_stamp()] = x-25,y-25
    # 清屏幕为黑色,重画所有circle
    screen.fill(BLACK)
    screen.blit(circle, (x-25, y-25))
    for stamp in stamps:
        screen.blit(stamp,(stamps[stamp]))
    # 显示所画
    pygame.display.flip()
 
    # 设置帧率为60
    clock.tick(60)
 
# 安全退出到IDLE 
pygame.quit()