65 lines
2.2 KiB
Python
65 lines
2.2 KiB
Python
from pyglet.shapes import Circle
|
|
|
|
from libs.ecs.world import World
|
|
from components import (
|
|
PlanetMarker,
|
|
Position,
|
|
Color,
|
|
Radius,
|
|
SpaceShipMarker,
|
|
Destination,
|
|
Vector2D,
|
|
)
|
|
from settings import SPACESHIP_COLOR, SPACESHIP_RADIUS, SPACESHIP_SPEED
|
|
|
|
|
|
class PlanetRenderSyncSystem:
|
|
@classmethod
|
|
def process(cls, world: World, **args):
|
|
for _, component_storage in world.query(PlanetMarker):
|
|
pos: Position = component_storage[Position]
|
|
color: Color = component_storage[Color]
|
|
radius: Radius = component_storage[Radius]
|
|
circle: Circle = component_storage[Circle]
|
|
circle.radius = radius.value
|
|
circle.x, circle.y = pos.x, pos.y
|
|
circle.color = color.value
|
|
|
|
|
|
class SpaceShipRenderSyncSystem:
|
|
@classmethod
|
|
def process(cls, world: World, **args):
|
|
for _, component_storage in world.query(SpaceShipMarker):
|
|
pos: Position = component_storage[Position]
|
|
circle: Circle = component_storage[Circle]
|
|
circle.radius = SPACESHIP_RADIUS
|
|
circle.x, circle.y = pos.x, pos.y
|
|
circle.color = SPACESHIP_COLOR
|
|
|
|
|
|
class SpaceShipKillSystem:
|
|
@classmethod
|
|
def process(cls, world: World, **args):
|
|
marked_for_death = []
|
|
for entity, component_storage in world.query(SpaceShipMarker):
|
|
pos: Position = component_storage[Position]
|
|
target: Destination = component_storage[Destination]
|
|
approach_radius = component_storage[Radius]
|
|
if abs(pos - target) < approach_radius.value:
|
|
marked_for_death.append(entity)
|
|
for entity in marked_for_death:
|
|
world.get_components(entity=entity, pop=True)
|
|
|
|
|
|
class SpaceShipTravelSystem:
|
|
@classmethod
|
|
def process(cls, world: World, **args):
|
|
for _, component_storage in world.query(SpaceShipMarker):
|
|
pos: Position = component_storage[Position]
|
|
target: Destination = component_storage[Destination]
|
|
|
|
diff: Vector2D = target - pos
|
|
diff_mag = abs(diff)
|
|
pos.x = pos.x + args["dt"] * SPACESHIP_SPEED * diff.x / diff_mag
|
|
pos.y = pos.y + args["dt"] * SPACESHIP_SPEED * diff.y / diff_mag
|