pygame简易迷宫游戏_mask应用示例程序

"""
   简易迷宫游戏。本程序演示一个非常简单的迷宫游戏原理。
   采用mask进行碰撞检测,并且会打印出碰撞点的像素值。
"""
import pygame
from pygame.locals import *

RED = (255,0,0)
GREEN = (0,255,255)
w,h, = size = 779,765
pygame.init()
screen = pygame.display.set_mode(size)
pygame.display.set_caption("Pygame简易迷宫游戏by lixingqiu")
# 创建迷宫
maze = pygame.image.load("maze.png")
rect1 = maze.get_rect()
mask1 = pygame.mask.from_surface(maze)

# 创建角色
radius2 = 5
width2,height2 = 2 * radius2,2 * radius2
sprite = pygame.Surface((width2,height2),SRCALPHA)
pos = width2//2,height2//2                # 画圆中心坐标
rect2 = sprite.get_rect(center=(w//2,h//2))
pygame.draw.circle(sprite,GREEN,pos,radius2)
mask2 = pygame.mask.from_surface(sprite)
dx = 0
dy = 0
running = True

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