pygame像素级碰撞检测示例程序_pygame_pixel_collision_check

"""pygame像素级碰撞检测示例程序

采用mask的碰撞检测,提取像素后可用于像素级撞检测,pygame_pixel_collision_check by lixingqiu
"""


import pygame, time
from pygame.locals import *


class Sprite(pygame.sprite.Sprite):

    def __init__(self, imagefile, screen, pos):
        """
          初始化角色,imagefile:图像文件名,screen:所在屏幕,pos:左上角坐标
        """
        pygame.sprite.Sprite.__init__(self)
        self.image = pygame.image.load(imagefile)
        self.rect = self.image.get_rect()
        self.rect.topleft = pos
        self.screen = screen         
        self.speed = [0 ,0]    # 水平和垂直方向位移向量
       

    def update(self):
        """原地更新矩形坐标"""
        self.rect.move_ip(self.speed[0],self.speed[1])
    
    pass

if __name__ == '__main__':
    main()

如需要下载完整源代码及素材,请

成为会员后,登陆才能继续浏览!联系微信scratch8即可办理会员。
(会员专属:能浏览所有文章,下载所有带链接的Python资源。)

关于李兴球

李兴球的博客是Python创意编程原创博客
此条目发表在pygame, python分类目录。将固定链接加入收藏夹。