Exemplo n.º 1
0
        public static PrefabEntity CreatePrefab()
        {
            PrefabEntity pipe = new PrefabEntity {
                Name = "Pipe"
            };

            ShapePrefab pipeWall1 = new ShapePrefab
            {
                Density = 1f,
                Width   = 20f,
                Height  = 880f,
                Offset  = new Vector2(-80f, 425f),
                Type    = ShapeType.Rectangle
            };

            ShapePrefab pipeWall2 = new ShapePrefab
            {
                Density = 1f,
                Width   = 20f,
                Height  = 880f,
                Offset  = new Vector2(101f, 425f),
                Type    = ShapeType.Rectangle
            };

            BodyPrefab pipeBody = new BodyPrefab
            {
                Friction      = 0.3f,
                LocalPosition = Vector2.Zero,
                Name          = "PipeBody",
                Shapes        = new List <ShapePrefab> {
                    pipeWall1, pipeWall2
                },
                Restitution = 0.1f,
                Static      = true,
            };

            pipe.RegisterBody(pipeBody, true);

            MeshSceneNodePrefab pipeModel = new MeshSceneNodePrefab {
                Mesh = "models/pipe", Material = "PipeMaterial", Name = "PipeModel"
            };

            pipe.RegisterMeshSceneNode(pipeModel);

            ControllerPrefab controller = new ControllerPrefab {
                Body = "PipeBody", Transformable = "PipeModel", Name = "PipeBodyController", Type = ControllerType.BodyController
            };

            pipe.RegisterController(controller);

            return(pipe);
        }
Exemplo n.º 2
0
        public static PrefabEntity CreatePrefab()
        {
            PrefabEntity cube = new PrefabEntity {
                Name = "Menu Cube"
            };

            ShapePrefab cubeShape = new ShapePrefab
            {
                Density = 1f,
                Width   = 20f,
                Height  = 20f,
                Offset  = Vector2.Zero,
                Type    = ShapeType.Rectangle
            };

            BodyPrefab cubeBody = new BodyPrefab
            {
                Friction      = GetRandomFriction(),
                LocalPosition = Vector2.Zero,
                Name          = "MenuCubeBody",
                Shapes        = new List <ShapePrefab> {
                    cubeShape
                },
                Restitution = 0.25f,
                Static      = false
            };

            cube.RegisterBody(cubeBody, true);

            MeshSceneNodePrefab cubeSceneNode = new MeshSceneNodePrefab
            {
                Material = "MenuCubeMaterial",
                Mesh     = "models/menu_cube",
                Name     = "MenuCubeNode"
            };

            cube.RegisterMeshSceneNode(cubeSceneNode);


            ControllerPrefab cubeController = new ControllerPrefab
            {
                Name          = "MenuCubeBodyController",
                Type          = ControllerType.BodyController,
                Body          = "MenuCubeBody",
                Transformable = "MenuCubeNode"
            };

            cube.RegisterController(cubeController);

            return(cube);
        }
Exemplo n.º 3
0
        public static PrefabEntity CreatePrefab()
        {
            PrefabEntity floor = new PrefabEntity {
                Name = "Floor"
            };

            ShapePrefab floorShape = new ShapePrefab
            {
                Density = 1f,
                Width   = 60f,
                Height  = 10f,
                Offset  = Vector2.Zero,
                Type    = ShapeType.Rectangle
            };

            BodyPrefab floorBody = new BodyPrefab
            {
                Friction      = 1f,
                LocalPosition = Vector2.Zero,
                Name          = "FloorBody",
                Shapes        = new List <ShapePrefab> {
                    floorShape
                },
                Restitution = 0.1f,
                Static      = true,
            };

            floor.RegisterBody(floorBody, true);


            MeshSceneNodePrefab mesh = new MeshSceneNodePrefab
            {
                Name     = "FloorMesh",
                Mesh     = "models/floor_tile",
                Material = "TileMaterial",
            };

            floor.RegisterMeshSceneNode(mesh);
            ControllerPrefab meshController = new ControllerPrefab
            {
                Name          = "FloorController",
                Type          = ControllerType.BodyController,
                Body          = "FloorBody",
                Transformable = "FloorMesh"
            };

            floor.RegisterController(meshController);

            return(floor);
        }
Exemplo n.º 4
0
        public static PrefabEntity CreatePrefab()
        {
            PrefabEntity entity = new PrefabEntity {
                Name = "UpradePlatform"
            };

            ShapePrefab shape = new ShapePrefab
            {
                Density = 1f,
                Width   = 180f,
                Height  = 10f,
                Offset  = Vector2.Zero,
                Type    = ShapeType.Rectangle
            };

            BodyPrefab body = new BodyPrefab
            {
                Friction      = 1f,
                LocalPosition = Vector2.Zero,
                Name          = "UpgradePlatformBody",
                Shapes        = new List <ShapePrefab> {
                    shape
                },
                Restitution = 0.1f,
                Static      = true,
            };

            entity.RegisterBody(body, true);


            MeshSceneNodePrefab mesh = new MeshSceneNodePrefab
            {
                Name     = "UpgradePlatformMesh",
                Mesh     = "models/upgrade_platform",
                Material = "UPlatformMaterial",
            };

            entity.RegisterMeshSceneNode(mesh);
            ControllerPrefab meshController = new ControllerPrefab
            {
                Name          = "UpgradePlatformController",
                Type          = ControllerType.BodyController,
                Body          = "UpgradePlatformBody",
                Transformable = "UpgradePlatformMesh"
            };

            entity.RegisterController(meshController);

            return(entity);
        }
Exemplo n.º 5
0
		public static PrefabEntity CreatePrefab()
		{
			PrefabEntity crate = new PrefabEntity { Name = "Crate" };

			ShapePrefab crateShape = new ShapePrefab
			{
				Density = 0.4f,
				Width = 18f,
				Height = 18f,
				Offset = Vector2.Zero,
				Type = ShapeType.Rectangle
			};

			BodyPrefab crateBody = new BodyPrefab
			{
				Friction = 0.3f,
				LocalPosition = Vector2.Zero,
				Name = "CrateBody",
				Shapes = new List<ShapePrefab> { crateShape },
				Restitution = 0.1f,
				Static = false,
				CollisionSounds = new List<string> { "sounds/hit1", "sounds/hit2", "sounds/hit3", "sounds/hit4" }
			};

			crate.RegisterBody( crateBody, true );

			MeshSceneNodePrefab crateSceneNode = new MeshSceneNodePrefab
			{
				Material = "CrateMaterial",
				Mesh = "models/crate00",
				Name = "CrateNode"
			};


			crate.RegisterMeshSceneNode( crateSceneNode );

			ControllerPrefab crateController = new ControllerPrefab
			{
				Name = "CrateBodyController",
				Type = ControllerType.BodyController,
				Body = "CrateBody",
				Transformable = "CrateNode"
			};

			crate.RegisterController( crateController );

			return crate;
		}
Exemplo n.º 6
0
 public void RegisterController(ControllerPrefab controller)
 {
     _controllersPrefab[controller.Name] = controller;
 }
Exemplo n.º 7
0
        public static PrefabEntity CreatePrefab()
        {
            PrefabEntity liftedDoor = new PrefabEntity {
                Name = "LiftedDoor"
            };

            ShapePrefab caseTop = new ShapePrefab
            {
                Density = 1f,
                Width   = 60f,
                Height  = 5f,
                Offset  = new Vector2(0f, -5f),
                Type    = ShapeType.Rectangle
            };

            ShapePrefab caseWall1 = new ShapePrefab
            {
                Density = 1f,
                Width   = 10f,
                Height  = 180f,
                Offset  = new Vector2(-25f, -100f),
                Type    = ShapeType.Rectangle
            };

            ShapePrefab caseWall2 = new ShapePrefab
            {
                Density = 1f,
                Width   = 10f,
                Height  = 180f,
                Offset  = new Vector2(25f, -100f),
                Type    = ShapeType.Rectangle
            };

            BodyPrefab doorCaseBody = new BodyPrefab
            {
                Friction      = 1f,
                LocalPosition = Vector2.Zero,
                Name          = "DoorCase",
                Shapes        = new List <ShapePrefab> {
                    caseTop, caseWall1, caseWall2
                },
                Restitution = 0.1f,
                Static      = true
            };

            liftedDoor.RegisterBody(doorCaseBody, true);

            ShapePrefab doorShape = new ShapePrefab
            {
                Density = 0.3f,
                Width   = 38f,
                Height  = 180f,
                Offset  = Vector2.Zero,
                Type    = ShapeType.Rectangle
            };

            BodyPrefab doorBody = new BodyPrefab
            {
                Friction      = 1f,
                LocalPosition = new Vector2(0f, -180f),
                Name          = "Door",
                Shapes        = new List <ShapePrefab> {
                    doorShape
                },
                Restitution = 0.1f,
                Static      = false
            };

            liftedDoor.RegisterBody(doorBody);

            JointPrefab prismaticJoint = new JointPrefab
            {
                Name             = "DoorJoint1",
                Type             = JointType.Prismatic,
                Body1            = "DoorCase",
                Body2            = "Door",
                Anchor           = new Vector2(0f, 0f),
                Anchor2          = new Vector2(0f, 0f),
                Axis             = new Vector2(0f, 1f),
                CollideConnected = false,
                UpperLimit       = 240f,
                LowerLimit       = 100f,
                LimitEnabled     = true,
                MaxMotorForce    = 6.5f,
                MotorSpeed       = 2f,
                MotorEnabled     = true
            };

            liftedDoor.RegisterJoint(prismaticJoint);

            MeshSceneNodePrefab innerDoorMesh = new MeshSceneNodePrefab
            {
                Mesh     = "models/door_inner",
                Material = "InnerDoorMaterial",
                Name     = "InnerDoorNode"
            };

            liftedDoor.RegisterMeshSceneNode(innerDoorMesh);

            ControllerPrefab innerDoorController = new ControllerPrefab
            {
                Name          = "InnerDoorController",
                Type          = ControllerType.BodyController,
                Body          = "Door",
                Transformable = "InnerDoorNode"
            };

            MeshSceneNodePrefab outerDoorMesh = new MeshSceneNodePrefab
            {
                Name     = "OuterDoorNode",
                Mesh     = "models/door_outer",
                Material = "OuterDoorMaterial",
            };

            liftedDoor.RegisterMeshSceneNode(outerDoorMesh);
            ControllerPrefab outerDoorController = new ControllerPrefab
            {
                Name          = "OuterDoorController",
                Type          = ControllerType.BodyController,
                Body          = "DoorCase",
                Transformable = "OuterDoorNode"
            };

            liftedDoor.RegisterController(innerDoorController);
            liftedDoor.RegisterController(outerDoorController);

            return(liftedDoor);
        }
Exemplo n.º 8
0
        public static PrefabEntity CreatePrefab()
        {
            PrefabEntity robot = new PrefabEntity {
                Name = "Robot"
            };

            /* gear bodies */
            ShapePrefab gearShape = new ShapePrefab {
                Type = ShapeType.Circle, XRadius = 14f, Density = 1f
            };

            BodyPrefab gear1 = new BodyPrefab
            {
                Name          = "Gear1",
                Friction      = 0.5f,
                Restitution   = 0.1f,
                LocalPosition = new Vector2(-27.93f, -20.13f),
                Static        = false,
                Shapes        = new List <ShapePrefab> {
                    gearShape
                },
            };

            BodyPrefab gear2 = new BodyPrefab
            {
                Name          = "Gear2",
                Friction      = 0.5f,
                Restitution   = 0.1f,
                LocalPosition = new Vector2(27.93f, -20.13f),
                Static        = false,
                Shapes        = new List <ShapePrefab> {
                    gearShape
                },
            };

            BodyPrefab gear3 = new BodyPrefab
            {
                Name          = "Gear3",
                Friction      = 0.5f,
                Restitution   = 0.1f,
                LocalPosition = new Vector2(0f, 28.25f),
                Static        = false,
                Shapes        = new List <ShapePrefab> {
                    gearShape
                },
            };

            robot.RegisterBody(gear1);
            robot.RegisterBody(gear2);
            robot.RegisterBody(gear3);

            /* chassis body */
            ShapePrefab chassisShape = new ShapePrefab {
                Type = ShapeType.Polygon, Density = 4f, Polygon = new List <Vertices> {
                    new Vertices()
                }
            };

            chassisShape.Polygon[0].Add(new Vector2(-15.41f, -13.87f));
            chassisShape.Polygon[0].Add(new Vector2(0f, 13.74f));
            chassisShape.Polygon[0].Add(new Vector2(15.41f, -13.87f));

            BodyPrefab chassis = new BodyPrefab
            {
                Name          = "Chassis",
                Restitution   = 0.1f,
                Friction      = 0.5f,
                LocalPosition = Vector2.Zero,
                Static        = false,
                Shapes        = new List <ShapePrefab> {
                    chassisShape
                },
            };

            robot.RegisterBody(chassis, true);               // is main body

            /* gear joints */
            const float jointLengthModifier = 1f;

            JointPrefab gearJoint1 = new JointPrefab
            {
                Type           = JointType.Line,
                Name           = "GearJoint1",
                Body1          = "Chassis",
                Body2          = "Gear1",
                Anchor         = gear1.LocalPosition,
                Axis           = new Vector2(0.66f, -0.33f) * jointLengthModifier,
                MaxMotorTorque = 10f,
                Frequency      = 10f,
                DampingRatio   = 0.85f,
                MotorEnabled   = true,
            };

            JointPrefab gearJoint2 = new JointPrefab
            {
                Type           = JointType.Line,
                Name           = "GearJoint2",
                Body1          = "Chassis",
                Body2          = "Gear2",
                Anchor         = gear2.LocalPosition,
                Axis           = new Vector2(-0.66f, -0.33f) * jointLengthModifier,
                MaxMotorTorque = 10f,
                Frequency      = 10f,
                DampingRatio   = 0.85f,
                MotorEnabled   = true
            };

            JointPrefab gearJoint3 = new JointPrefab
            {
                Type           = JointType.Line,
                Name           = "GearJoint3",
                Body1          = "Chassis",
                Body2          = "Gear3",
                Anchor         = gear3.LocalPosition,
                Axis           = new Vector2(0f, 0.76f) * jointLengthModifier,
                MaxMotorTorque = 10f,
                Frequency      = 10f,
                DampingRatio   = 0.85f,
                MotorEnabled   = true
            };

            robot.RegisterJoint(gearJoint1);
            robot.RegisterJoint(gearJoint2);
            robot.RegisterJoint(gearJoint3);

            ShapePrefab linkShape = new ShapePrefab
            {
                Type    = ShapeType.Rectangle,
                Width   = 2.51f,
                Height  = 8.88f,
                Density = 2f,
                Offset  = Vector2.Zero
            };

            ShapePrefab linkFeetShape = new ShapePrefab
            {
                Type    = ShapeType.Rectangle,
                Width   = 2.51f,
                Height  = 4f,
                Density = 2f,
                Offset  = new Vector2(2f, 0f)
            };

            BodyPrefab link = new BodyPrefab
            {
                Name   = "Link",
                Shapes = new List <ShapePrefab> {
                    linkShape, linkFeetShape
                },
                Friction    = 1f,
                Restitution = 0f,
            };

            PathPrefab track = new PathPrefab
            {
                Name                = "Track",
                Anchor1             = new Vector2(-1.5f, -4.4f),
                Anchor2             = new Vector2(-1.5f, 4.4f),
                BodyCount           = 29,
                CollideConnected    = false,
                ConnectFirstAndLast = true,
                JointType           = JointType.Revolute,
                Path                = new List <Vector2>
                {
                    new Vector2(60f, -32f),
                    new Vector2(0f, 51f),
                    new Vector2(-50f, -32f),
                    new Vector2(55f, -38f)
                },
                Body = link
            };

            robot.RegisterPath(track);

            /* scene nodes */
            MeshSceneNodePrefab gearNode1 = new MeshSceneNodePrefab
            {
                Name     = "Gear1",
                Mesh     = "models/robo_wheel",
                Material = "RobotMaterial",
            };

            MeshSceneNodePrefab gearNode2 = new MeshSceneNodePrefab
            {
                Name     = "Gear2",
                Mesh     = "models/robo_wheel",
                Material = "RobotMaterial",
            };

            MeshSceneNodePrefab gearNode3 = new MeshSceneNodePrefab
            {
                Name     = "Gear3",
                Mesh     = "models/robo_wheel",
                Material = "RobotMaterial",
            };

            robot.RegisterMeshSceneNode(gearNode1);
            robot.RegisterMeshSceneNode(gearNode2);
            robot.RegisterMeshSceneNode(gearNode3);


            MeshSceneNodePrefab chassisNode = new MeshSceneNodePrefab
            {
                Name     = "ChassisNode",
                Mesh     = "models/robo_body",
                Material = "RobotMaterial",
            };

            robot.RegisterMeshSceneNode(chassisNode);

            ArrayMeshSceneNodePrefab linkNode = new ArrayMeshSceneNodePrefab
            {
                Name       = "Links",
                Mesh       = "models/robo_link",
                Material   = "RobotMaterial",
                Path       = "Track",
                StartIndex = 0,
                EndIndex   = 28
            };

            robot.RegisterArrayMeshSceneNode(linkNode);

            ControllerPrefab gear1Controller = new ControllerPrefab
            {
                Name          = "Gear1BodyController",
                Type          = ControllerType.BodyController,
                Body          = "Gear1",
                Transformable = "Gear1"
            };

            robot.RegisterController(gear1Controller);

            ControllerPrefab gear2Controller = new ControllerPrefab
            {
                Name          = "Gear2BodyController",
                Type          = ControllerType.BodyController,
                Body          = "Gear2",
                Transformable = "Gear2"
            };

            robot.RegisterController(gear2Controller);

            ControllerPrefab gear3Controller = new ControllerPrefab
            {
                Name          = "Gear3BodyController",
                Type          = ControllerType.BodyController,
                Body          = "Gear3",
                Transformable = "Gear3"
            };

            ControllerPrefab chassisController = new ControllerPrefab
            {
                Name          = "ChassisController",
                Type          = ControllerType.BodyController,
                Body          = "Chassis",
                Transformable = "ChassisNode"
            };

            robot.RegisterController(chassisController);

            robot.RegisterController(gear3Controller);

            return(robot);
        }
Exemplo n.º 9
0
        public static PrefabEntity CreatePrefab()
        {
            PrefabEntity button = new PrefabEntity {
                Name = "Button"
            };

            ShapePrefab caseBottom = new ShapePrefab
            {
                Density = 1f,
                Width   = 26f,
                Height  = 0.5f,
                Offset  = new Vector2(0f, 0.25f),
                Type    = ShapeType.Rectangle
            };

            ShapePrefab caseWall1 = new ShapePrefab {
                Type = ShapeType.Polygon, Density = 1f, Polygon = new List <Vertices> {
                    new Vertices()
                }
            };

            caseWall1.Polygon[0].Add(new Vector2(8.25f, 0.5f));
            caseWall1.Polygon[0].Add(new Vector2(8.25f, 4f));
            caseWall1.Polygon[0].Add(new Vector2(13f, 0.5f));

            ShapePrefab caseWall2 = new ShapePrefab {
                Type = ShapeType.Polygon, Density = 1f, Polygon = new List <Vertices> {
                    new Vertices()
                }
            };

            caseWall2.Polygon[0].Add(new Vector2(-8.25f, 4f));
            caseWall2.Polygon[0].Add(new Vector2(-8.25f, 0.5f));
            caseWall2.Polygon[0].Add(new Vector2(-13f, 0.5f));

            BodyPrefab buttonCaseBody = new BodyPrefab
            {
                Friction      = 1f,
                LocalPosition = Vector2.Zero,
                Name          = "ButtonCase",
                Shapes        = new List <ShapePrefab> {
                    caseBottom, caseWall1, caseWall2
                },
                Restitution = 0.1f,
                Static      = true
            };

            button.RegisterBody(buttonCaseBody, true);

            ShapePrefab buttonShape = new ShapePrefab
            {
                Density = 0.3f,
                Width   = 16f,
                Height  = 2.4f,
                Offset  = Vector2.Zero,
                Type    = ShapeType.Rectangle
            };

            BodyPrefab buttonBody = new BodyPrefab
            {
                Friction      = 1f,
                LocalPosition = new Vector2(0f, 2.5f),
                Name          = "Button",
                Shapes        = new List <ShapePrefab> {
                    buttonShape
                },
                Restitution = 0.1f,
                Static      = false
            };

            button.RegisterBody(buttonBody);

            JointPrefab prismaticJoint = new JointPrefab
            {
                Name             = "ButtonJoint1",
                Type             = JointType.Prismatic,
                Body1            = "Button",
                Body2            = "ButtonCase",
                Anchor           = new Vector2(0f, -1.25f),
                Anchor2          = new Vector2(0f, 0f),
                Axis             = new Vector2(0f, 1f),
                CollideConnected = false,
                UpperLimit       = 2.25f,
                LowerLimit       = 0f,
                LimitEnabled     = true,
                MaxMotorForce    = 0.2f,
                MotorSpeed       = 1f,
                MotorEnabled     = true
            };

            button.RegisterJoint(prismaticJoint);

            MeshSceneNodePrefab caseNode = new MeshSceneNodePrefab
            {
                Name     = "CaseNode",
                Mesh     = "models/button_body",
                Material = "ButtonMaterial",
            };

            MeshSceneNodePrefab buttonNode = new MeshSceneNodePrefab
            {
                Name     = "ButtonNode",
                Mesh     = "models/button_head",
                Material = "ButtonMaterial",
            };

            button.RegisterMeshSceneNode(caseNode);
            button.RegisterMeshSceneNode(buttonNode);

            ControllerPrefab buttonController = new ControllerPrefab
            {
                Name          = "ButtonController",
                Type          = ControllerType.BodyController,
                Body          = "Button",
                Transformable = "ButtonNode"
            };

            ControllerPrefab caseController = new ControllerPrefab
            {
                Name          = "CaseController",
                Type          = ControllerType.BodyController,
                Body          = "ButtonCase",
                Transformable = "CaseNode"
            };

            button.RegisterController(buttonController);
            button.RegisterController(caseController);

            return(button);
        }