You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

20 lines
860 B

import pygame
from settings import *
class Tile(pygame.sprite.Sprite):
def __init__(self,pos,groups,sprite_type,surface = pygame.Surface((TILESIZE,TILESIZE))):
# 调用父类pygame.sprite.Sprite的构造函数
super().__init__(groups)
# 设置瓷砖类型(如 'player'、'object'、'grass' 等)
self.sprite_type = sprite_type
# 获取瓷砖类型对应的 Y 偏移量
y_offset = HITBOX_OFFSET[sprite_type]
# 设置瓷砖的表面Surface默认为 TILESIZE x TILESIZE 的空表面
self.image = surface
# 根据瓷砖类型设置矩形位置和碰撞框
if sprite_type == 'object':
self.rect = self.image.get_rect(topleft = (pos[0],pos[1] - TILESIZE))
else:
self.rect = self.image.get_rect(topleft = pos)
# 根据 Y 偏移量设置碰撞框大小
self.hitbox = self.rect.inflate(0,y_offset)