Esempio n. 1
0
        void SetupTauntAnimation()
        {
            string      path  = GameSimulation.PathForArtResource("characters/monkey/monkey_tree_hang_taunt");
            CAAnimation taunt = LoadAndCacheAnimation(path, "monkey_tree_hang_taunt-1");

            taunt.RepeatCount = 0;

            SCNAnimationEventHandler ackBlock = (CAAnimation animation, NSObject animatedObject, bool playingBackward) => {
                GameSimulation.Sim.PlaySound("ack.caf");
            };

            SCNAnimationEventHandler idleBlock = (CAAnimation animation, NSObject animatedObject, bool playingBackward) => {
                isIdle = true;
            };

            taunt.AnimationEvents = new SCNAnimationEvent[] {
                SCNAnimationEvent.Create(0.35f, ackBlock),
                SCNAnimationEvent.Create(1.0f, idleBlock)
            };
        }
Esempio n. 2
0
        SCNNode CreateTorchNode()
        {
            SCNGeometry geometry = SCNBox.Create(20f, 100f, 20f, 0f);

            geometry.FirstMaterial.Diffuse.Contents = AppKit.NSColor.Brown;
            var template = new SCNNode {
                Geometry = geometry
            };

            var particleEmitter = new SCNNode {
                Position = new SCNVector3(0f, 50f, 0f)
            };

            SCNParticleSystem fire = GameSimulation.LoadParticleSystemWithName("torch", "spark");

            particleEmitter.AddParticleSystem(fire);
            particleEmitter.Light = TorchLight;

            template.AddChildNode(particleEmitter);
            return(template);
        }
Esempio n. 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);
        }
Esempio n. 4
0
        void SetupGetCoconutAnimation()
        {
            SCNAnimationEventHandler pickupEventBlock = (CAAnimation animation, NSObject animatedObject, bool playingBackward) => {
                if (coconutInHand != null)
                {
                    coconutInHand.RemoveFromParentNode();
                }

                coconutInHand = Coconut.CoconutProtoObject;
                rightHand.AddChildNode(coconutInHand);
                hasCoconut = true;
            };

            CAAnimation getAnimation = LoadAndCacheAnimation(GameSimulation.PathForArtResource("characters/monkey/monkey_get_coconut"), "monkey_get_coconut-1");

            if (getAnimation.AnimationEvents == null)
            {
                getAnimation.AnimationEvents = new SCNAnimationEvent[] { SCNAnimationEvent.Create(0.4f, pickupEventBlock) }
            }
            ;

            getAnimation.RepeatCount = 1;
        }

        void SetupThrowAnimation()
        {
            CAAnimation throwAnimation = LoadAndCacheAnimation(GameSimulation.PathForArtResource("characters/monkey/monkey_throw_coconut"), "monkey_throw_coconut-1");

            throwAnimation.Speed = 1.5f;

            if (throwAnimation.AnimationEvents == null || throwAnimation.AnimationEvents.Length == 0)
            {
                SCNAnimationEventHandler throwEventBlock = ThrowCoconut;

                throwAnimation.AnimationEvents = new SCNAnimationEvent[] { SCNAnimationEvent.Create(0.35f, throwEventBlock) };
            }

            throwAnimation.RepeatCount = 0;
        }

        void ThrowCoconut(CAAnimation animation, NSObject animatedObject, bool playingBackward)
        {
            if (!hasCoconut)
            {
                return;
            }

            SCNMatrix4 worldMtx = coconutInHand.PresentationNode.WorldTransform;

            coconutInHand.RemoveFromParentNode();

            Coconut         node = Coconut.CoconutThrowProtoObject;
            SCNPhysicsShape coconutPhysicsShape = Coconut.CoconutPhysicsShape;

            node.PhysicsBody                  = SCNPhysicsBody.CreateBody(SCNPhysicsBodyType.Dynamic, coconutPhysicsShape);
            node.PhysicsBody.Restitution      = 0.9f;
            node.PhysicsBody.CollisionBitMask = GameCollisionCategory.Player | GameCollisionCategory.Ground;
            node.PhysicsBody.CategoryBitMask  = GameCollisionCategory.Coconut;

            node.Transform = worldMtx;
            GameSimulation.Sim.RootNode.AddChildNode(node);
            GameSimulation.Sim.GameLevel.Coconuts.Add(node);
            node.PhysicsBody.ApplyForce(new SCNVector3(-200, 500, 300), true);
            hasCoconut = false;
            isIdle     = true;
        }
    }
Esempio n. 5
0
        void SetupHangAnimation()
        {
            CAAnimation hang = LoadAndCacheAnimation(GameSimulation.PathForArtResource("characters/monkey/monkey_tree_hang"), "monkey_tree_hang-1");

            hang.RepeatCount = float.MaxValue;
        }
Esempio n. 6
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);
        }