Example #1
0
     panda3d.CollidableGeometry,
     panda3d.FlattenStrong,
    ],
    overrides={
        mechanics.Clock: dict(clock=panda3d.panda_clock),
        panda3d.Geometry: dict(file='roadE.bam'),
        panda3d.Scene: dict(node=base.render),
    },
)


# Populate the world with the map, the player character, and a few NPCs

# Map
map_entity = base.ecs_world.create_entity(name="Level geometry")
game_map.add(map_entity)

# Player
player_avatar = Aspect(
    [
        aspects.player_character,
        panda3d.Stamina,
        cefconsole.WatchedEntity,
    ])
player_avatar.add(
    base.ecs_world.create_entity(name="Playerbecca"),
    overrides={
        mechanics.Clock: dict(parent=map_entity._uid),
        panda3d.Position: dict(value=Point3(50, 290, 0)),
    },
)
Example #2
0
    avatar,
    npc_mind,
], )

# Load the map

parser = argparse.ArgumentParser()
parser.add_argument('map_file')
args = parser.parse_args()

map_node = base.loader.load_model(args.map_file)

if not map_node.find('**/+GeomNode').is_empty():
    # There's geometry in the map; It's actually a map!
    game_map.add(base.ecs_world.create_entity(name="Map"),
                 overrides={
                     wecs.panda3d.prototype.Geometry: dict(node=map_node),
                 })
else:
    base.ecs_world.create_entity(
        wecs.panda3d.spawnpoints.SpawnMap(),
        wecs.panda3d.prototype.Model(node=map_node),
        name="Map",
    )

# Scan map for spawn points and instantiate


def create_character(model, spawn_point, aspect):
    # FIXME: There are a lot of constants here that should be drawn
    # from the model itself and the spawn point node.
    bumper_node = model.find('**/=bumper')
Example #3
0
    [
        wecs.panda3d.prototype.Model,
        wecs.panda3d.prototype.Geometry,
        wecs.panda3d.prototype.CollidableGeometry,
        wecs.panda3d.prototype.FlattenStrong,
    ],
    overrides={
        wecs.panda3d.prototype.Geometry:
        dict(file='roadE.bam'),
        wecs.panda3d.prototype.CollidableGeometry:
        dict(mask=FALLING_MASK | BUMPING_MASK, ),
    },
)

map_entity = base.ecs_world.create_entity(name="Level geometry")
game_map.add(map_entity)

# Player

character = Aspect(
    [
        wecs.mechanics.clock.Clock,
        wecs.panda3d.prototype.Model,
        wecs.panda3d.prototype.Geometry,
        wecs.panda3d.character.CharacterController,
    ],
    overrides={
        wecs.mechanics.clock.Clock:
        dict(clock=lambda: factory(wecs.mechanics.clock.panda3d_clock), ),
    },
)
Example #4
0
def test_aspect_in_entity(world):
    aspect = Aspect([Component_A])
    entity = world.create_entity()
    aspect.add(entity)
    world._flush_component_updates()
    assert aspect.in_entity(entity)
Example #5
0
        wecs.panda3d.prototype.Geometry,
        wecs.panda3d.prototype.CollidableGeometry,
        wecs.panda3d.prototype.FlattenStrong,
        wecs.panda3d.mouseover.MouseOverableGeometry,
        wecs.panda3d.mouseover.Pointable,
    ],
    overrides={
        wecs.panda3d.prototype.Geometry:
        dict(file='../../assets/roadE.bam', ),
        wecs.panda3d.prototype.CollidableGeometry:
        dict(mask=FALLING_MASK | BUMPING_MASK | CAMERA_MASK, ),
    },
)

map_entity = base.ecs_world.create_entity(name="Level geometry")
game_map.add(map_entity)

# There are characters, which are points in space that can be moved
# around using the `CharacterController`, using either player input or
# AI control.

character = Aspect(
    [
        wecs.mechanics.clock.Clock,
        wecs.panda3d.prototype.Model,
        wecs.panda3d.character.CharacterController,
    ],
    overrides={
        wecs.mechanics.clock.Clock:
        dict(clock=lambda: factory(wecs.mechanics.clock.panda3d_clock), ),
        wecs.panda3d.character.CharacterController:
Example #6
0
def test_adding_aspect_to_entity(world):
    aspect = Aspect([Component_A])
    entity = world.create_entity()
    aspect.add(entity)
    world._flush_component_updates()
    assert Component_A in entity
Example #7
0
def test_adding_clashing_aspect_to_entity(world):
    aspect = Aspect([Component_A])
    entity = world.create_entity(Component_A())
    with pytest.raises(KeyError):
        aspect.add(entity)
Example #8
0
    panda3d.ExecuteMovement,  # Turn intention into actual movement.
    panda3d.AnimateCharacter,
    panda3d.Animate,
    # We're done with character movement, now update the cameras and console.
    panda3d.UpdateCameras,
    # panda3d.CollideCamerasWithTerrain,
    cefconsole.UpdateWecsSubconsole,
    cefconsole.WatchEntitiesInSubconsole,
]

# Aspects are basically classes for entities. Here are two that we will use.
game_map = Aspect(
    [
        panda3d.Position,
        panda3d.Model,
        panda3d.Scene,
        panda3d.CollidableGeometry,
        panda3d.FlattenStrong,
        cefconsole.WatchedEntity,
    ],
    overrides={
        panda3d.Model: dict(model_name='grid.bam'),
        panda3d.Scene: dict(node=base.render),
    },
)
lab_character = Aspect([aspects.player_character, cefconsole.WatchedEntity])

# Create entities
game_map.add(base.ecs_world.create_entity())
lab_character.add(base.ecs_world.create_entity(name="Rebecca"))
Example #9
0
File: game.py Project: BMaxV/wecs
    panda3d.CollideCamerasWithTerrain,
]

game_map = Aspect(
    [panda3d.Position, panda3d.Model, panda3d.Scene, Map],
    overrides={
        panda3d.Position: dict(value=factory(lambda: Point3(0, 0, 0))),
        panda3d.Model: dict(model_name='roadE.bam'),
        panda3d.Scene: dict(node=base.render),
    },
)

# Populate the world with the map, the player character, and a few NPCs

# Map
game_map.add(base.ecs_world.create_entity())

# Player
player_avatar = Aspect([aspects.player_character, mechanics.Stamina])
player_avatar.add(
    base.ecs_world.create_entity(),
    overrides={panda3d.Position: dict(value=Point3(50, 290, 0))},
)

# Non-moving NPC
aspects.non_player_character.add(
    base.ecs_world.create_entity(),
    overrides={panda3d.Position: dict(value=Point3(60, 290, 0))},
)

# Small circle NPC
Example #10
0
    [
        wecs.panda3d.prototype.Model,
        wecs.panda3d.prototype.Geometry,
        wecs.panda3d.mouseover.MouseOverableGeometry,
        wecs.panda3d.mouseover.Targetable,
        Takeable,
     ],
)


scenery.add(
    base.ecs_world.create_entity(name="Ball 1"),
    overrides={
        wecs.panda3d.prototype.Model: dict(
            post_attach=lambda: wecs.panda3d.prototype.transform(
                pos=Vec3(-1, 0, 1),
            ),
        ),
        wecs.panda3d.prototype.Geometry: dict(file='models/smiley'),
    },
)


scenery.add(
    base.ecs_world.create_entity(name="Ball 2"),
    overrides={
        wecs.panda3d.prototype.Model: dict(
            post_attach=lambda: wecs.panda3d.prototype.transform(
                pos=Vec3(1, 10, -1),
            ),
        ),
Example #11
0
    [
        wecs.panda3d.prototype.Model,
        wecs.panda3d.prototype.Geometry,
        wecs.panda3d.prototype.CollidableGeometry,
        wecs.panda3d.prototype.FlattenStrong,
    ],
    overrides={
        wecs.panda3d.prototype.Geometry:
        dict(file='roadE.bam'),
        wecs.panda3d.prototype.CollidableGeometry:
        dict(mask=FALLING_MASK | BUMPING_MASK | CAMERA_MASK, ),
    },
)

map_entity = base.ecs_world.create_entity(name="Level geometry")
game_map.add(map_entity)

# Player
#
# * A player is character is an avatar with a PC mind, an animated
#   appearance, and a third person camera.
#   * An avatar is a walking character.
#     * A character is a `CharacterController` with a `Clock` and a
#       `Model`.
#     * An entity that is walking performs `WalkingMovement`,
#       `BumpingMovement`, and `FallingMovement`.
#   * A PC mind means that this entity's "AI" is user `Input`.
#   * A third person camera is a `Camera` in `ObjectCentricCameraMode`.
#   * An animated appearance is simply an `Actor`.
#
# Note how the Aspects form a tree that eventually ends in component
Example #12
0
        panda3d.Scene,
        panda3d.CollidableGeometry,
        panda3d.FlattenStrong,
    ],
    overrides={
        mechanics.Clock: dict(clock=panda3d.panda_clock),
        panda3d.Model: dict(model_name='roadE.bam'),
        panda3d.Scene: dict(node=base.render),
    },
)

# Populate the world with the map, the player character, and a few NPCs

# Map
map_entity = base.ecs_world.create_entity(name="Level geometry")
game_map.add(map_entity)

# Player
player_avatar = Aspect([
    aspects.player_character,
    panda3d.Stamina,
    cefconsole.WatchedEntity,
])
player_avatar.add(
    base.ecs_world.create_entity(name="Playerbecca"),
    overrides={
        mechanics.Clock: dict(parent=map_entity._uid),
        panda3d.Position: dict(value=Point3(50, 290, 0)),
    },
)