pygame的方块类鼠标单击示例样本程序

"""
   pygame的方块类鼠标单击示例样本程序.py
"""

import pygame

BLACK = (0, 0, 0)
RED   = (255, 0, 0)
GREEN = (0, 255, 0)
SIZE = WIDTH,HEIGHT = 480,360

class  Square(pygame.sprite.Sprite):
    """
       定义类,继承自Sprite类
    """
    
    def __init__(self,pos,color,size):
        """
           pos:方块中心点坐标
           color:颜色
           size:宽高
        """
        pygame.sprite.Sprite.__init__(self)
        self.color = color
        self.size = size
        self.image = pygame.Surface(size)
        self.image.fill(color)
        self.rect = self.image.get_rect()
        self.rect.center = pos

    def check_click(self, pos):
        """
           检测pos是否在矩形内
        """

You must log in to read the rest of this article. Please log in or register as a user.