Removable

By Chris Proctor

class quest.contrib.removable.RemovableMixin[source]

A mixin for QuestGame which adds support for removing sprites from the game.

When a sprite is removed, it no longer shows up on the game map. This could already be achieved using sprite.kill(), but sometimes you want to keep track of a sprite even though it has been removed: perhaps it will return, or perhaps it has gone somewhere like into the player’s inventory.

The key to this mixin is that QuestGame only renders and checks for collisions on certain SpriteLists, such as self.wall_list and self.npc_list. So when we remove a sprite from one of these “live” SpriteLists, it will no longer show up or trigger collisions.

RemovableMixin extends initialization to add a dictionary called removed_sprite_lists, where each key is the name of a list in which to store removed sprites. If you don’t need more than one place to store removed sprites, you can ignore this; they will all be stored in “default.”

removed_sprite_list_names

A list of strings naming destinations for removed sprites. By default, there is just one destination, called “default,” but you might want others like “inventory” or “shop” or “dead_spirits_seeking_revenge.”

add_sprite_to_game(sprite)[source]

Adds the sprite to the game and removes it from storage.

If the sprite is in any of the removed_sprite_lists, it is removed from them. If the sprite is not already in self.npc_list, adds the sprite.

remove_sprite_from_game(sprite, destination='default')[source]

Removes the sprite from the game and adds it to storage.

If the sprite is in self.npc_list, it is removed. If the sprite is not already in the specified removed sprite list, adds it.