entities.collisions module¶
Provides entity collisions functionality.
- class entities.collisions.BaseCollisionRules(*args, **kwargs)¶
Bases:
WeakAutoUnload
,instance
- __init__()¶
Raises an exception This class cannot be instantiated from Python
- should_collide((BaseCollisionRules)self, (_entities._entity.BaseEntity)entity, (_entities._entity.BaseEntity)other) bool : ¶
Returns whether the given entities should collide with each other.
- Return type:
- property mode¶
Returns the collision mode for these rules.
- Return type:
- class entities.collisions.CollisionHash(*args, **kwargs)¶
Bases:
BaseCollisionRules
Collision rules where contained pairs never collide with each other.
Example:
from entities.collisions import CollisionHash from events import Event from players.entity import Player h = CollisionHash() @Event('player_say') def player_say(game_event): player = Player.from_userid(game_event['userid']) entity = player.view_entity if entity is None: return # Toggle collisions with aimed entity if h.has_pair(player, entity): h.remove_pair(player, entity) else: h.add_pair(player, entity)
- __init__((object)arg1[, (CollisionMode)mode=_entities._collisions.CollisionMode.PREVENT[, (bool)solid_only=True]]) object : ¶
Constructs and initializes the collision hash.
- Parameters:
mode (CollisionMode) – The collision mode for these rules.
solid_only (bool) – Whether these rules should affect solid contents only.
- add_pair((CollisionHash)self, (_entities._entity.BaseEntity)entity, (_entities._entity.BaseEntity)other) None : ¶
Adds the given entity pair to the hash.
- Raises:
ValueError – If any of the given entities is not networked.
- clear((CollisionHash)self) None : ¶
Removes all entities from the hash.
- get_count((CollisionHash)self, (_entities._entity.BaseEntity)entity) int : ¶
Returns the amount of pairs associated with the given entity.
- Return type:
- get_pairs((CollisionHash)self, (_entities._entity.BaseEntity)entity) list : ¶
Returns a list of all entities associated with the given entity.
- Return type:
- has_pair((CollisionHash)self, (_entities._entity.BaseEntity)entity, (_entities._entity.BaseEntity)other) bool : ¶
Returns whether the given pair is in the hash.
- Return type:
- remove_pair((CollisionHash)self, (_entities._entity.BaseEntity)entity, (_entities._entity.BaseEntity)other) None : ¶
Removes the given pair from the hash.
- remove_pairs((CollisionHash)self, (_entities._entity.BaseEntity)entity) None : ¶
Removes all pairs associated with the given entity.
- class entities.collisions.CollisionHook(*args, **kwargs)[source]¶
Bases:
AutoUnload
Decorator used to create collision hooks that auto unload.
Example:
from engines.trace import ContentFlags from entities.collisions import CollisionHook @CollisionHook def collision_hook(entity, other, trace_filter, mask): # Prevent hostages from being killed by bullets if not mask & ContentFlags.HITBOX: return return other.classname != 'hostage_entity'
- class entities.collisions.CollisionManager¶
Bases:
instance
- __init__()¶
Raises an exception This class cannot be instantiated from Python
- register_hook((CollisionManager)self, (object)callback) None : ¶
Registers a collision hook.
- Parameters:
callback (function) – Function to register as a collision hook callback.
- Raises:
ValueError – If the given callback is already registered.
- unregister_hook((CollisionManager)self, (object)callback) None : ¶
Unregisters a collision hook.
- Parameters:
callback (function) – Function to unregister as a collision hook callback.
- Raises:
ValueError – If the given callback was not registered.
- class entities.collisions.CollisionMap(*args, **kwargs)¶
Bases:
BaseCollisionRules
Collision rules that overrides one-way collisions.
Example:
from entities.collisions import CollisionMap from events import Event from players.entity import Player m = CollisionMap() @Event('player_say') def player_say(game_event): player = Player.from_userid(game_event['userid']) entity = player.view_entity if entity is None: return # Toggle one-way collisions with aimed entity s = m[player] if entity in s: s.remove(entity) else: s.add(entity)
- __init__((object)arg1[, (CollisionMode)mode=_entities._collisions.CollisionMode.PREVENT[, (bool)solid_only=True]]) object : ¶
Constructs and initializes the collision map.
- Parameters:
mode (CollisionMode) – The collision mode for these rules.
solid_only (bool) – Whether these rules should affect solid contents only.
- clear((CollisionMap)self) None : ¶
Removes all entities from the map.
- class entities.collisions.CollisionMode¶
Bases:
enum
- ALLOW = _entities._collisions.CollisionMode.ALLOW¶
- PREVENT = _entities._collisions.CollisionMode.PREVENT¶
- names = {'ALLOW': _entities._collisions.CollisionMode.ALLOW, 'PREVENT': _entities._collisions.CollisionMode.PREVENT}¶
- values = {0: _entities._collisions.CollisionMode.ALLOW, 1: _entities._collisions.CollisionMode.PREVENT}¶
- class entities.collisions.CollisionSet(*args, **kwargs)¶
Bases:
BaseCollisionRules
Collision rules where contained entities never collide with anything.
Example:
from entities.collisions import CollisionSet from events import Event from players.entity import Player s = CollisionSet() @Event('player_say') def player_say(game_event): player = Player.from_userid(game_event['userid']) # Toggle collisions with everything if player in s: s.remove(player) else: s.add(player)
- __init__((object)arg1[, (CollisionMode)mode=_entities._collisions.CollisionMode.PREVENT[, (bool)solid_only=True]]) object : ¶
Constructs and initializes the collision set.
- Parameters:
mode (CollisionMode) – The collision mode for these rules.
solid_only (bool) – Whether these rules should affect solid contents only.
- add((CollisionSet)self, (_entities._entity.BaseEntity)entity) None : ¶
Adds the given entity to the set.
- Raises:
ValueError – If the given entity is not networked.
- clear((CollisionSet)self) None : ¶
Removes all entities from the set.
- remove((CollisionSet)self, (_entities._entity.BaseEntity)entity) None : ¶
Removes the given entity from the set.