注意: platforms
是我定义灯光尺寸的模块,在这里我只是使用x和y将对象放入屏幕level
坐标。
如何制作播放器和对象' LIGHT'在我的游戏中碰撞?
播放器代码:
class Player(pygame.sprite.Sprite):
change_x = 0
change_y = 0
walking_frames_l = []
walking_frames_r = []
direction = "R"
level = None
def __init__(self):
pygame.sprite.Sprite.__init__(self)
sprite_sheet = SpriteSheet("p2_jump.png")
image = sprite_sheet.get_image(0, 0, 66, 90)
self.walking_frames_r.append(image)
image = sprite_sheet.get_image(0, 0, 66, 90)
image = pygame.transform.flip(image, True, False)
self.walking_frames_l.append(image)
self.image = self.walking_frames_r[0]
self.rect = self.image.get_rect()
对象代码:
class Level_01(Level):
def __init__(self, player):
Level.__init__(self, player)
self.background = pygame.image.load("120111.png").convert()
self.background.set_colorkey(setup.WHITE)
self.level_limit = -2200
level = [[platforms.GRASS_LEFT, 500, 500],
[platforms.GRASS_MIDDLE, 570, 500],
[platforms.GRASS_RIGHT, 640, 500],
[platforms.GRASS_LEFT, 800, 400],
[platforms.GRASS_MIDDLE, 870, 400],
[platforms.GRASS_RIGHT, 940, 400],
[platforms.GRASS_LEFT, 1000, 500],
[platforms.GRASS_MIDDLE, 1070, 500],
[platforms.GRASS_RIGHT, 1140, 500],
[platforms.GRASS_LEFT, 1120, 280],
[platforms.GRASS_MIDDLE, 1190, 280],
[platforms.GRASS_RIGHT, 1260, 280],
[platforms.GRASS_LEFT, 1870, 400],
[platforms.GRASS_MIDDLE, 1940, 400],
[platforms.GRASS_RIGHT, 2010, 400],
[platforms.GRASS_LEFT, 2080, 280],
[platforms.GRASS_MIDDLE, 2150, 280],
[platforms.GRASS_RIGHT, 2220, 280],
[platforms.GRASS_LEFT, 2350, 450],
[platforms.GRASS_MIDDLE, 2420, 450],
[platforms.GRASS_RIGHT, 2490, 450],
[platforms.LIGHT1, 570, 430],
[platforms.LIGHT2, 870, 250],
[platforms.LIGHT3, 1190, 150],
[platforms.LIGHT4, 1940, 350],
[platforms.LIGHT5, 2200, 95],
[platforms.LIGHT6, 2420, 350],
]