development #12
@ -7,9 +7,9 @@ class OnCollisionComponent:
|
|||||||
callbacks = []
|
callbacks = []
|
||||||
self.callbacks = callbacks
|
self.callbacks = callbacks
|
||||||
|
|
||||||
def callAll(self):
|
def call_all(self):
|
||||||
for func in self.callbacks:
|
for func in self.callbacks:
|
||||||
func()
|
func()
|
||||||
|
|
||||||
def addCallback(self, fn, **kwargs):
|
def add_callback(self, fn, **kwargs):
|
||||||
self.callbacks.append(partial(fn, **kwargs))
|
self.callbacks.append(partial(fn, **kwargs))
|
@ -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.camera_target_component import CameraTargetComponent
|
||||||
from survival.components.consumption_component import ConsumptionComponent
|
from survival.components.consumption_component import ConsumptionComponent
|
||||||
from survival.components.input_component import InputComponent
|
from survival.components.input_component import InputComponent
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import random
|
import random
|
||||||
|
|
||||||
from survival import GameMap
|
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.inventory_component import InventoryComponent
|
||||||
from survival.components.learning_component import LearningComponent
|
from survival.components.learning_component import LearningComponent
|
||||||
from survival.components.position_component import PositionComponent
|
from survival.components.position_component import PositionComponent
|
||||||
@ -35,7 +35,7 @@ class ResourceGenerator:
|
|||||||
resource_type = random.choice(list(ResourceType))
|
resource_type = random.choice(list(ResourceType))
|
||||||
sprite = SpriteComponent(sprites[resource_type])
|
sprite = SpriteComponent(sprites[resource_type])
|
||||||
col = OnCollisionComponent()
|
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, pos)
|
||||||
self.world.add_component(obj, sprite)
|
self.world.add_component(obj, sprite)
|
||||||
self.world.add_component(obj, col)
|
self.world.add_component(obj, col)
|
||||||
|
@ -1,10 +1,9 @@
|
|||||||
import operator
|
import operator
|
||||||
|
|
||||||
from survival import esper
|
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.moving_component import MovingComponent
|
||||||
from survival.components.position_component import PositionComponent
|
from survival.components.position_component import PositionComponent
|
||||||
from survival.components.learning_component import LearningComponent
|
|
||||||
from survival.enums import Direction
|
from survival.enums import Direction
|
||||||
|
|
||||||
|
|
||||||
@ -24,14 +23,14 @@ class CollisionSystem(esper.Processor):
|
|||||||
moving.direction_vector = vector
|
moving.direction_vector = vector
|
||||||
if self.check_collision(moving.target):
|
if self.check_collision(moving.target):
|
||||||
self.world.remove_component(ent, MovingComponent)
|
self.world.remove_component(ent, MovingComponent)
|
||||||
onCol.callAll()
|
onCol.call_all()
|
||||||
colliding_object: int = self.map.get_entity(moving.target)
|
colliding_object: int = self.map.get_entity(moving.target)
|
||||||
|
|
||||||
if colliding_object is None or not self.world.entity_exists(colliding_object):
|
if colliding_object is None or not self.world.entity_exists(colliding_object):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if self.world.has_component(colliding_object, OnCollisionComponent):
|
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:
|
else:
|
||||||
self.map.move_entity(pos.grid_position, moving.target)
|
self.map.move_entity(pos.grid_position, moving.target)
|
||||||
|
Loading…
Reference in New Issue
Block a user