Planet and spaceship creation, travel and destruction
This commit is contained in:
1 parent
ca9e8a2f19
commit
90e421909a
7 files changed
+307
No files matched your search
+64
@@ -0,0 +1,64 @@
|
||||
from pyglet.shapes import Circle
|
||||
|
||||
from libs.ecs import World
|
||||
from components import (
|
||||
PlanetMarker,
|
||||
Position,
|
||||
Color,
|
||||
Radius,
|
||||
SpaceShipMarker,
|
||||
Target,
|
||||
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: Target = component_storage[Target]
|
||||
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: Target = component_storage[Target]
|
||||
|
||||
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
|
||||
Reference in new issue
Block a user