Fix names in OnCollisionComponent

This commit is contained in:
Kanewersa 2021-06-19 00:04:34 +02:00
parent 094e33bb0c
commit 005beb224d
4 changed files with 8 additions and 9 deletions

View File

@ -7,9 +7,9 @@ class OnCollisionComponent:
callbacks = []
self.callbacks = callbacks
def callAll(self):
def call_all(self):
for func in self.callbacks:
func()
def addCallback(self, fn, **kwargs):
def add_callback(self, fn, **kwargs):
self.callbacks.append(partial(fn, **kwargs))

View File

@ -1,4 +1,4 @@
from survival.components.OnCollisionComponent import OnCollisionComponent
from survival.components.on_collision_component import OnCollisionComponent
from survival.components.camera_target_component import CameraTargetComponent
from survival.components.consumption_component import ConsumptionComponent
from survival.components.input_component import InputComponent

View File

@ -1,7 +1,7 @@
import random
from survival import GameMap
from survival.components.OnCollisionComponent import OnCollisionComponent
from survival.components.on_collision_component import OnCollisionComponent
from survival.components.inventory_component import InventoryComponent
from survival.components.learning_component import LearningComponent
from survival.components.position_component import PositionComponent
@ -35,7 +35,7 @@ class ResourceGenerator:
resource_type = random.choice(list(ResourceType))
sprite = SpriteComponent(sprites[resource_type])
col = OnCollisionComponent()
col.addCallback(self.remove_resource, world=self.world, game_map=self.map, resource_ent=obj, player=player)
col.add_callback(self.remove_resource, world=self.world, game_map=self.map, resource_ent=obj, player=player)
self.world.add_component(obj, pos)
self.world.add_component(obj, sprite)
self.world.add_component(obj, col)

View File

@ -1,10 +1,9 @@
import operator
from survival import esper
from survival.components.OnCollisionComponent import OnCollisionComponent
from survival.components.on_collision_component import OnCollisionComponent
from survival.components.moving_component import MovingComponent
from survival.components.position_component import PositionComponent
from survival.components.learning_component import LearningComponent
from survival.enums import Direction
@ -24,14 +23,14 @@ class CollisionSystem(esper.Processor):
moving.direction_vector = vector
if self.check_collision(moving.target):
self.world.remove_component(ent, MovingComponent)
onCol.callAll()
onCol.call_all()
colliding_object: int = self.map.get_entity(moving.target)
if colliding_object is None or not self.world.entity_exists(colliding_object):
continue
if self.world.has_component(colliding_object, OnCollisionComponent):
self.world.component_for_entity(colliding_object, OnCollisionComponent).callAll()
self.world.component_for_entity(colliding_object, OnCollisionComponent).call_all()
else:
self.map.move_entity(pos.grid_position, moving.target)