Пример #1
0
import movement
import paddles
import tank


system_types = [
    # Attach the entity's Model. This gives an entity a node as
    # presence in the scene graph.
    panda3d.SetupModels,
    # Attach Geometry to the Model's node.
    panda3d.ManageGeometry,
    # If the Paddle's size has changed, apply it to the Model.
    paddles.ResizePaddles,
    # Read player input and store it on Movement
    tank.GiveTankMoveCommands,
    # Apply the Movement
    movement.MoveObject,
    # Did the paddle move too far? Back to the boundary with it!
    tank.TankTouchesBoundary,
]


base.ecs_world.create_entity(
    panda3d.Model(),
    panda3d.Geometry(file='tank.bam'),
    panda3d.Scene(node=base.aspect2d),
    panda3d.Position(value=Vec3(-1.1, 0, 0)),
    movement.Movement(value=Vec3(0, 0, 0)),
    paddles.Paddle(player=paddles.Players.LEFT),
)
Пример #2
0
    ]
    for sort, system_type in enumerate(system_types):
        base.add_system(system_type(), sort)

    # We don't use the default world here to set gravity manually.
    bullet_world = BulletWorld()
    bullet_world.set_gravity(Vec3(0, 0, -9.81))
    world = base.ecs_world.create_entity(
        panda3d.PhysicsWorld(
            world=bullet_world,
            clock=globalClock,
        ),
        panda3d.Scene(node=base.render),
    )

    bullet_body = BulletRigidBodyNode()
    bullet_body.set_linear_sleep_threshold(0)
    bullet_body.set_angular_sleep_threshold(0)
    bullet_body.set_mass(1.0)
    ball = base.ecs_world.create_entity(
        panda3d.Position(value=Point3(0, 0, 0)),
        panda3d.Model(model_name='ball.bam'),
        panda3d.PhysicsBody(
            body=bullet_body,
            world=world._uid,
            scene=world._uid,
        ),
    )

    base.run()
Пример #3
0
    system_types = [
        panda3d.LoadModels,
        paddles.ResizePaddles,
        paddles.GivePaddlesMoveCommands,
        movement.MoveObject,
        paddles.PaddleTouchesBoundary,
        ball.BallTouchesBoundary,
        ball.BallTouchesPaddleLine,
        ball.StartBallMotion,
    ]
    for sort, system_type in enumerate(system_types):
        base.add_system(system_type(), sort)

    # Paddles and ball
    paddle_left = base.ecs_world.create_entity(
        panda3d.Model(model_name='paddle.bam'),
        panda3d.Scene(root=base.aspect2d),
        panda3d.Position(value=Vec3(-1.1, 0, 0)),
        movement.Movement(value=Vec3(0, 0, 0)),
        paddles.Paddle(
            player=0,
            size=0.3,
            speed=0.2,
        ),
    )

    paddle_right = base.ecs_world.create_entity(
        panda3d.Model(model_name='paddle.bam'),
        panda3d.Scene(root=base.aspect2d),
        panda3d.Position(value=Point3(1.1, 0, 0)),
        movement.Movement(value=Vec3(0, 0, 0)),