我已经制作了一个推杆游戏,现在我想添加一个倾斜的墙类型。因此,我需要使用遮罩进行碰撞(到目前为止我只使用了矩形)。我花了几个小时学习掩模并试图找出为什么我的代码不起作用。没有错误,只是没有检测到碰撞。
我已将代码简化为更小的代码,以便我有效地测试它。从我所看到的一切来看,这似乎应该有效,但事实并非如此。这里是:
import pygame
# Pygame init stuff
pygame.init()
wind_width = 1200
wind_height = 700
gameDisplay = pygame.display.set_mode((wind_width, wind_height))
pygame.display.set_caption("Mini Golf!")
pygame.display.update()
gameExit = False
clock = pygame.time.Clock()
# Class setups
class Ball:
def __init__(self, x, y):
self.x = x
self.y = y
self.image = pygame.image.load("sball.png")
self.rect = self.image.get_rect()
self.mask = pygame.mask.from_surface(self.image)
def render(self):
self.rect.topleft = (self.x, self.y)
gameDisplay.blit(self.image, self.rect)
class Slant:
def __init__(self, x, y):
self.x = x
self.y = y
self.image = pygame.image.load("posslant.png")
self.rect = self.image.get_rect()
self.mask = …Run Code Online (Sandbox Code Playgroud)