Beispiel #1
0
        SCNNode CreateBanana()
        {
            //Create model
            if (bananaCollectable == null)
            {
                bananaCollectable       = GameSimulation.LoadNodeWithName("banana", GameSimulation.PathForArtResource("level/banana.dae"));
                bananaCollectable.Scale = new SCNVector3(0.5f, 0.5f, 0.5f);


                SCNSphere       sphereGeometry = SCNSphere.Create(40);
                SCNPhysicsShape physicsShape   = SCNPhysicsShape.Create(sphereGeometry, new SCNPhysicsShapeOptions());
                bananaCollectable.PhysicsBody = SCNPhysicsBody.CreateBody(SCNPhysicsBodyType.Kinematic, physicsShape);

                // Only collide with player and ground
                bananaCollectable.PhysicsBody.CollisionBitMask = GameCollisionCategory.Player | GameCollisionCategory.Ground;
                // Declare self in the banana category
                bananaCollectable.PhysicsBody.CategoryBitMask = GameCollisionCategory.Banana;

                // Rotate and Hover forever.
                bananaCollectable.Rotation = new SCNVector4(0.5f, 1f, 0.5f, -(nfloat)Math.PI / 4);
                SCNAction idleHoverGroupAction = SCNAction.Group(new SCNAction[] { BananaIdleAction, HoverAction });
                SCNAction repeatForeverAction  = SCNAction.RepeatActionForever(idleHoverGroupAction);
                bananaCollectable.RunAction(repeatForeverAction);
            }

            return(bananaCollectable.Clone());
        }
Beispiel #2
0
        SCNNode CreateMonkeyPalmTree()
        {
            SCNNode palmTreeProtoObject = null;

            string palmTreeDae = "art.scnassets/characters/monkey/monkey_palm_tree.dae";

            palmTreeProtoObject = GameSimulation.LoadNodeWithName("PalmTree", palmTreeDae);

            SCNNode monkeyNode = GameSimulation.LoadNodeWithName(string.Empty, "art.scnassets/characters/monkey/monkey_skinned.dae");

            var monkey = new MonkeyCharacter(monkeyNode);

            monkey.CreateAnimations();
            palmTreeProtoObject.AddChildNode(monkey);

            return(palmTreeProtoObject);
        }
Beispiel #3
0
        SCNNode CreateLargeBanana()
        {
            //Create model
            if (largeBananaCollectable == null)
            {
                var   node      = GameSimulation.LoadNodeWithName("banana", GameSimulation.PathForArtResource("level/banana.dae"));
                float scaleMode = 0.5f * 10 / 4;
                node.Scale = new SCNVector3(scaleMode, scaleMode, scaleMode);


                SCNSphere       sphereGeometry = SCNSphere.Create(100);
                SCNPhysicsShape physicsShape   = SCNPhysicsShape.Create(sphereGeometry, new SCNPhysicsShapeOptions());
                node.PhysicsBody = SCNPhysicsBody.CreateBody(SCNPhysicsBodyType.Kinematic, physicsShape);

                // Only collide with player and ground
                node.PhysicsBody.CollisionBitMask = GameCollisionCategory.Player | GameCollisionCategory.Ground;
                // Declare self in the banana category
                node.PhysicsBody.CategoryBitMask = GameCollisionCategory.Coin;

                // Rotate forever.
                SCNAction rotateCoin = SCNAction.RotateBy(0f, 8f, 0f, 2f);
                SCNAction repeat     = SCNAction.RepeatActionForever(rotateCoin);

                node.Rotation = new SCNVector4(0f, 1f, 0f, (nfloat)Math.PI / 2);
                node.RunAction(repeat);

                largeBananaCollectable = node;
            }

            SCNNode nodeSparkle = largeBananaCollectable.Clone();

            SCNParticleSystem newSystem = GameSimulation.LoadParticleSystemWithName("sparkle");

            nodeSparkle.AddParticleSystem(newSystem);

            return(nodeSparkle);
        }
Beispiel #4
0
        public SCNNode CreateLevel()
        {
            RootNode = new SCNNode();

            // load level dae and add all root children to the scene.
            var options = new SCNSceneLoadingOptions {
                ConvertToYUp = true
            };
            SCNScene scene = SCNScene.FromFile("level", GameSimulation.PathForArtResource("level/"), options);

            foreach (SCNNode node in scene.RootNode.ChildNodes)
            {
                RootNode.AddChildNode(node);
            }

            // retrieve the main camera
            Camera = RootNode.FindChildNode("camera_game", true);

            // create our path that the player character will follow.
            CalculatePathPositions();

            // Sun/Moon light
            SunLight                         = RootNode.FindChildNode("FDirect001", true);
            SunLight.EulerAngles             = new SCNVector3(7.1f * (nfloat)Math.PI / 4, (nfloat)Math.PI / 4, 0f);
            SunLight.Light.ShadowSampleCount = 1;
            lightOffsetFromCharacter         = new SCNVector3(1500f, 2000f, 1000f);

            //workaround directional light deserialization issue
            SunLight.Light.ZNear             = 100f;
            SunLight.Light.ZFar              = 5000f;
            SunLight.Light.OrthographicScale = 1000f;

            // Torches
            var torchesPos = new float[] { 0f, -1f, 0.092467f, -1f, -1f, 0.5f, 0.792f, 0.95383f };

            for (int i = 0; i < torchesPos.Length; i++)
            {
                if (torchesPos [i] != -1)
                {
                    SCNVector3 location = LocationAlongPath(torchesPos [i]);
                    location.Y += 50;
                    location.Z += 150;

                    SCNNode node = CreateTorchNode();

                    node.Position = location;
                    RootNode.AddChildNode(node);
                }
            }

            // After load, we add nodes that are dynamic / animated / or otherwise not static.
            CreateLavaAnimation();
            CreateSwingingTorch();
            AnimateDynamicNodes();

            // Create our player character
            SCNNode characterRoot = GameSimulation.LoadNodeWithName(string.Empty, "art.scnassets/characters/explorer/explorer_skinned.dae");

            PlayerCharacter = new PlayerCharacter(characterRoot);
            TimeAlongPath   = 0;

            PlayerCharacter.Position = LocationAlongPath(TimeAlongPath);
            PlayerCharacter.Rotation = GetPlayerDirectionFromCurrentPosition();
            RootNode.AddChildNode(PlayerCharacter);

            // Optimize lighting and shadows
            // only the charadcter should cast shadows
            foreach (var child in RootNode.ChildNodes)
            {
                child.CastsShadow = false;
            }

            foreach (var child in PlayerCharacter.ChildNodes)
            {
                child.CastsShadow = true;
            }

            // Add some monkeys to the scene.
            AddMonkeyAtPosition(new SCNVector3(0f, -30f, -400f), 0f);
            AddMonkeyAtPosition(new SCNVector3(3211f, 146f, -400f), -(nfloat)Math.PI / 4f);
            AddMonkeyAtPosition(new SCNVector3(5200f, 330f, 600f), 0f);

            // Volcano
            SCNNode oldVolcano     = RootNode.FindChildNode("volcano", true);
            string  volcanoDaeName = GameSimulation.PathForArtResource("level/volcano_effects.dae");
            SCNNode newVolcano     = GameSimulation.LoadNodeWithName("dummy_master", volcanoDaeName);

            oldVolcano.AddChildNode(newVolcano);
            oldVolcano.Geometry = null;
            oldVolcano          = newVolcano.FindChildNode("volcano", true);
            oldVolcano          = oldVolcano.ChildNodes [0];

            // Animate our dynamic volcano node.
            string shaderCode = "uniform float speed;\n" +
                                "_geometry.color = vec4(a_color.r, a_color.r, a_color.r, a_color.r);\n" +
                                "_geometry.texcoords[0] += (vec2(0.0, 1.0) * 0.05 * u_time);\n";

            string fragmentShaderCode = "#pragma transparent\n";

            // Dim background
            SCNNode back = RootNode.FindChildNode("dumy_rear", true);

            foreach (var child in back.ChildNodes)
            {
                child.CastsShadow = false;

                if (child.Geometry == null)
                {
                    continue;
                }

                foreach (SCNMaterial material in child.Geometry.Materials)
                {
                    material.LightingModelName = SCNLightingModel.Constant;
                    material.Multiply.Contents = AppKit.NSColor.FromDeviceWhite(0.3f, 1f);

                    material.Multiply.Intensity = 1;
                }
            }

            SCNNode backMiddle = RootNode.FindChildNode("dummy_middle", true);

            foreach (var child in backMiddle.ChildNodes)
            {
                if (child.Geometry == null)
                {
                    continue;
                }

                foreach (SCNMaterial material in child.Geometry.Materials)
                {
                    material.LightingModelName = SCNLightingModel.Constant;
                }
            }

            foreach (var child in newVolcano.ChildNodes)
            {
                foreach (var volc in child.ChildNodes)
                {
                    if (volc != oldVolcano && volc.Geometry != null)
                    {
                        volc.Geometry.FirstMaterial.LightingModelName = SCNLightingModel.Constant;
                        volc.Geometry.FirstMaterial.Multiply.Contents = AppKit.NSColor.White;

                        volc.Geometry.ShaderModifiers = new SCNShaderModifiers {
                            EntryPointGeometry = shaderCode,
                            EntryPointFragment = fragmentShaderCode
                        };
                    }
                }
            }

            Coconuts = new List <Coconut> ();
            return(RootNode);
        }