2021-05-23 18:03:16 +02:00
|
|
|
from survival import esper, GameMap
|
2021-03-28 18:05:52 +02:00
|
|
|
from survival.components.movement_component import MovementComponent
|
|
|
|
from survival.components.moving_component import MovingComponent
|
|
|
|
from survival.components.position_component import PositionComponent
|
|
|
|
from survival.components.sprite_component import SpriteComponent
|
|
|
|
|
|
|
|
|
|
|
|
class MovementSystem(esper.Processor):
|
2021-05-23 18:03:16 +02:00
|
|
|
def __init__(self, game_map: GameMap):
|
|
|
|
self.map = game_map
|
2021-03-28 18:05:52 +02:00
|
|
|
|
|
|
|
def process(self, dt):
|
|
|
|
for ent, (mov, pos, moving, sprite) in self.world.get_components(MovementComponent, PositionComponent,
|
|
|
|
MovingComponent,
|
|
|
|
SpriteComponent):
|
2021-06-06 19:55:55 +02:00
|
|
|
# cost = self.map.get_cost(moving.target)
|
|
|
|
# pos.position[0] += moving.direction_vector[0] * mov.speed * dt / 100 / cost
|
|
|
|
# pos.position[1] += moving.direction_vector[1] * mov.speed * dt / 100 / cost
|
|
|
|
#
|
|
|
|
# if abs(moving.target[0] * 32 - pos.position[0]) < 1 * mov.speed and abs(
|
|
|
|
# pos.position[1] - moving.target[1] * 32) < 1 * mov.speed:
|
|
|
|
# pos.position = [moving.target[0] * 32, moving.target[1] * 32]
|
|
|
|
# self.world.remove_component(ent, MovingComponent)
|
|
|
|
pos.position = [moving.target[0] * 32, moving.target[1] * 32]
|
|
|
|
self.world.remove_component(ent, MovingComponent)
|