def __init__(self, setting, pos): super(StaticObject, self).__init__() self.setting = setting self.pos = Vector2(pos) self.image = self.static_images.get(setting.IMAGE_KEY).convert_alpha().subsurface(Rect(setting.IMAGE_RECT)) self.rect = self.image.get_rect() self.area = pygame.Rect(setting.AREA_RECT) self.area.center = pos self.status = cfg.StaticObject.STATUS_NORMAL if self.setting.IS_ELIMINABLE: self.image_origin = self.image.copy() self.shadow_image = get_shadow_image(setting.SHADOW_INDEX) self.shadow_rect = self.shadow_image.get_rect() self.blink = Blink(sfg.Effect.BLINK_RATE2, sfg.Effect.BLINK_DEPTH_SECTION2) self.adjust_rect()
class StaticObject(pygame.sprite.DirtySprite): static_images = ImageController(sfg.STATIC_OBJECT_IMAGES[0]) static_images.add_from_list(sfg.STATIC_OBJECT_IMAGES[1]) def __init__(self, setting, pos): super(StaticObject, self).__init__() self.setting = setting self.pos = Vector2(pos) self.image = self.static_images.get(setting.IMAGE_KEY).convert_alpha().subsurface(Rect(setting.IMAGE_RECT)) self.rect = self.image.get_rect() self.area = pygame.Rect(setting.AREA_RECT) self.area.center = pos self.status = cfg.StaticObject.STATUS_NORMAL if self.setting.IS_ELIMINABLE: self.image_origin = self.image.copy() self.shadow_image = get_shadow_image(setting.SHADOW_INDEX) self.shadow_rect = self.shadow_image.get_rect() self.blink = Blink(sfg.Effect.BLINK_RATE2, sfg.Effect.BLINK_DEPTH_SECTION2) self.adjust_rect() def adjust_rect(self): # static_objects are static, only call this one time is ok self.rect.center = (self.pos.x, self.pos.y * 0.5 - self.setting.POS_RECT_DELTA_Y) if self.setting.IS_ELIMINABLE: # self.shadow_rect.center = (self.pos.x, self.pos.y * 0.5 - self.shadow_rect_delta_y) self.shadow_rect.center = self.area.center self.shadow_rect.y = self.shadow_rect.y * 0.5 - self.setting.SHADOW_RECT_DELTA_Y def update(self, passed_seconds): if self.setting.IS_ELIMINABLE: # the object is eliminable, we should make it blink-blink look! self.image = self.blink.make(self.image_origin, passed_seconds) def draw_shadow(self, camera): camera.screen.blit(self.shadow_image, (self.shadow_rect.x - camera.rect.x, self.shadow_rect.y - camera.rect.y)) def draw(self, camera): if not self.rect.colliderect(camera.rect): return camera.screen.blit(self.image, (self.rect.x - camera.rect.x, self.rect.y - camera.rect.y))