public void PositionScene(ARSCNView sceneView, string arLaunchType)
        {
            var arConfiguration = new ARWorldTrackingConfiguration
            {
                PlaneDetection         = ARPlaneDetection.Horizontal,
                LightEstimationEnabled = true
            };

            sceneView.Session.Run(arConfiguration, ARSessionRunOptions.ResetTracking);

            var sceneShipNode = sceneView.Scene.RootNode.FindChildNode("ship", true);

            sceneShipNode.Position = new SCNVector3(2f, -2f, -9f);

            var animationCycle  = SCNAction.RepeatActionForever(SCNAction.RotateBy(0f, 6f, 0, 5));
            var animationCrash  = SCNAction.RepeatActionForever(SCNAction.RotateBy(0, (float)Math.PI, (float)Math.PI, (float)1));
            var animationNormal = SCNAction.RepeatActionForever(SCNAction.RotateBy(0, 0, 0, 1));
            var animationRotate = SCNAction.RepeatActionForever(SCNAction.RotateBy(0, 0, 2, 1));


            var scenePivotNode = new SCNNode {
                Position = new SCNVector3(0.0f, 2.0f, 0.0f)
            };

            scenePivotNode.RunAction(SCNAction.RepeatActionForever(SCNAction.RotateBy(0, -2, 0, 10)));

            sceneShipNode.RemoveFromParentNode();
            scenePivotNode.AddChildNode(sceneShipNode);

            sceneView.Scene.RootNode.AddChildNode(scenePivotNode);

            sceneShipNode.Scale    = new SCNVector3(0.1f, 0.1f, 0.1f);
            sceneShipNode.Position = new SCNVector3(2f, -2f, -3f);


            switch (arLaunchType)
            {
            case "Rotate Fly":
                sceneShipNode.RunAction(animationRotate);
                break;

            case "Crash Fly":
                sceneShipNode.RunAction(animationCrash);
                break;

            case "Cycle Fly":
                sceneShipNode.RunAction(animationCycle);
                break;

            case "Normal Fly":
                sceneShipNode.RunAction(animationNormal);
                break;

            default:
                scenePivotNode.RemoveAllActions();
                scenePivotNode.RunAction(SCNAction.Unhide());
                break;
            }
        }
예제 #2
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());
        }
예제 #3
0
        private void HandlerLongPress(UILongPressGestureRecognizer sender)
        {
            ARSCNView longPressScene = sender.View as ARSCNView;

            CoreGraphics.CGPoint longPressLocation = sender.LocationInView(longPressScene);
            SCNHitTestResult[]   hitTest           = longPressScene.HitTest(longPressLocation, new SCNHitTestOptions());

            if (hitTest?.Any() != true)
            {
                return;
            }

            SCNNode node = hitTest.First().Node;

            if (sender.State == UIGestureRecognizerState.Began)
            {
                SCNAction rotateAction  = SCNAction.RotateBy(0, ConvertDegreesToRadians(360f), 0, 1f);
                SCNAction rotateForever = SCNAction.RepeatActionForever(rotateAction);
                node.RunAction(rotateForever);
            }
            else if (sender.State == UIGestureRecognizerState.Ended)
            {
                node.RemoveAllActions();
            }
        }
            public override void DidBeginContact(SCNPhysicsWorld world, SCNPhysicsContact contact)
            {
                var     nodeA  = contact.NodeA;
                var     nodeB  = contact.NodeB;
                SCNNode target = null;

                if (nodeA.PhysicsBody.CategoryBitMask == (int)BitMaskCategory.Pokemon)
                {
                    target = nodeA;
                }
                else if (nodeB.PhysicsBody.CategoryBitMask == (int)BitMaskCategory.Pokemon)
                {
                    target = nodeB;
                }

                if (target != null && !animatedNodes.Contains(target))
                {
                    var targetScale = target.Scale;

                    animatedNodes.Add(target);

                    target.RunAction(SCNAction.Sequence(new SCNAction[] {
                        SCNAction.ScaleTo(0, 1.0f),
                        SCNAction.ScaleTo(targetScale.X, 2.0f),
                    }), () => {
                        animatedNodes.Remove(target);
                    });
                }
            }
예제 #5
0
        private async Task AnimateNode(SCNNode node)
        {
            var sourcePosition = new SCNVector3(node.PresentationNode.Position.X, node.PresentationNode.Position.Y, node.PresentationNode.Position.Z);
            var targetPosition = new SCNVector3(node.PresentationNode.Position.X - 0.2f, node.PresentationNode.Position.Y - 0.2f, node.PresentationNode.Position.Z - 0.2f);

            for (int i = 0; i < 3; i++)
            {
                SCNAction toTarget = SCNAction.MoveTo(targetPosition, 0.2f);
                node.RunAction(toTarget);
                await Task.Delay(200);

                SCNAction toSource = SCNAction.MoveTo(sourcePosition, 0.2f);
                node.RunAction(toSource);
                await Task.Delay(200);
            }
        }
예제 #6
0
        private void AddPlanet(SCNVector3 sunPosition, float radious, string diffuse, string specular, string emission, string normal, float xPosition, double selfRotation, double sunRotation)
        {
            SCNNode parent = new SCNNode();

            parent.Position = sunPosition;
            sceneView.Scene.RootNode.AddChildNode(parent);

            SCNNode planet = new SCNNode();

            planet.Geometry = SCNSphere.Create(radious);
            planet.Geometry.FirstMaterial.Diffuse.Contents  = string.IsNullOrWhiteSpace(diffuse) ? null : new UIImage(diffuse);
            planet.Geometry.FirstMaterial.Specular.Contents = string.IsNullOrWhiteSpace(specular) ? null : new UIImage(specular);
            planet.Geometry.FirstMaterial.Emission.Contents = string.IsNullOrWhiteSpace(emission) ? null : new UIImage(emission);
            planet.Geometry.FirstMaterial.Normal.Contents   = string.IsNullOrWhiteSpace(normal) ? null : new UIImage(normal);
            planet.Position = new SCNVector3(xPosition, 0, 0);

            //TODO 3.2 Movimientos
            SCNAction selfAction  = SCNAction.RotateBy(0, ConvertDegreesToRadians(360), 0, selfRotation);
            SCNAction selfForever = SCNAction.RepeatActionForever(selfAction);

            planet.RunAction(selfForever);

            SCNAction sunAction  = SCNAction.RotateBy(0, ConvertDegreesToRadians(360), 0, sunRotation);
            SCNAction sunForever = SCNAction.RepeatActionForever(sunAction);

            parent.RunAction(sunForever);

            parent.AddChildNode(planet);
        }
예제 #7
0
        void CollectFlower(SCNNode node)
        {
            if (node.ParentNode == null)
            {
                return;
            }

            SCNNode soundEmitter = SCNNode.Create();

            soundEmitter.Position = node.Position;
            node.ParentNode.AddChildNode(soundEmitter);
            soundEmitter.RunAction(SCNAction.Sequence(new [] {
                SCNAction.PlayAudioSource(collectFlowerSound, true),
                SCNAction.RemoveFromParentNode()
            }));

            node.RemoveFromParentNode();

            // Check if game is complete.
            bool gameComplete = GameView.DidCollectAFlower();

            // Edit some particles.
            SCNMatrix4 particlePosition = soundEmitter.WorldTransform;

            particlePosition.M42 += 0.1f;
            GameView.Scene.AddParticleSystem(collectParticles, particlePosition);

            if (gameComplete)
            {
                ShowEndScreen();
            }
        }
        public static void AddRotationAction(this SCNNode node, SCNActionTimingMode mode, double secs, bool loop = false)
        {
            SCNAction rotateAction = SCNAction.RotateBy(0, (float)Math.PI, 0, secs);

            rotateAction.TimingMode = mode;

            if (loop)
            {
                SCNAction indefiniteRotation = SCNAction.RepeatActionForever(rotateAction);
                node.RunAction(indefiniteRotation, "rotation");
            }
            else
            {
                node.RunAction(rotateAction, "rotation");
            }
        }
예제 #9
0
        void ShowEndScreen()
        {
            gameIsComplete = true;

            // Add confettis
            SCNMatrix4 particlePosition = SCNMatrix4.CreateTranslation(0f, 8f, 0f);

            GameView.Scene.AddParticleSystem(confetti, particlePosition);

            // Congratulation title
            SKSpriteNode congrat = SKSpriteNode.FromImageNamed("Images/congratulations.png");

            congrat.Position = new CGPoint(GameView.Bounds.Width / 2, GameView.Bounds.Height / 2);
            SKScene overlay = GameView.OverlayScene;

            congrat.XScale = congrat.YScale = 0;
            congrat.Alpha  = 0;
            congrat.RunAction(SKAction.Group(new [] {
                SKAction.FadeInWithDuration(0.25),
                SKAction.Sequence(new [] {
                    SKAction.ScaleTo(.55f, 0.25),
                    SKAction.ScaleTo(.3f, 0.1),
                })
            }));

            // Panda Image
            SKSpriteNode congratPanda = SKSpriteNode.FromImageNamed("Images/congratulations_pandaMax.png");

            congratPanda.Position    = new CGPoint(GameView.Bounds.Width / 2f, GameView.Bounds.Height / 2f - 90f);
            congratPanda.AnchorPoint = new CGPoint(.5f, 0f);
            congratPanda.XScale      = congratPanda.YScale = 0f;
            congratPanda.Alpha       = 0;

            congratPanda.RunAction(SKAction.Sequence(new [] {
                SKAction.WaitForDuration(.5f),
                SKAction.Sequence(new [] {
                    SKAction.ScaleTo(.5f, 0.25),
                    SKAction.ScaleTo(.4f, 0.1)
                })
            }));

            overlay.AddChild(congratPanda);
            overlay.AddChild(congrat);

            // Stop music
            GameView.Scene.RootNode.RemoveAllAudioPlayers();

            // Play the congrat sound.
            GameView.Scene.RootNode.AddAudioPlayer(SCNAudioPlayer.FromSource(victoryMusic));

            // Animate the camera forever
            DispatchQueue.MainQueue.DispatchAfter(new DispatchTime(DispatchTime.Now, 1 * NanoSecondsPerSeond), () => {
                cameraYHandle.RunAction(SCNAction.RepeatActionForever(SCNAction.RotateBy(0f, -1f, 0f, 3.0)));
                cameraXHandle.RunAction(SCNAction.RotateTo(-(float)Math.PI / 4f, 0f, 0f, 5.0));
            });
        }
예제 #10
0
        public static SCNNode RotateForever(this SCNNode node, double duration)
        {
            var action =
                SCNAction.RepeatActionForever(
                    SCNAction.RotateBy(0, .05f, 0, duration));

            node.RunAction(action);

            return(node);
        }
예제 #11
0
 private void PlayFootStep()
 {
     if (this.groundNode != null && this.IsWalking)
     {
         // We are in the air, no sound to play.
         // Play a random step sound.
         int randSnd        = (new Random().Next(0, 32767) * Character.StepsCount);
         var stepSoundIndex = Math.Min(Character.StepsCount - 1, randSnd);
         characterNode.RunAction(SCNAction.PlayAudioSource(this.steps[stepSoundIndex], false));
     }
 }
예제 #12
0
        public void CollideWithCoconut(SCNNode coconut, SCNVector3 contactPoint)
        {
            // No more collisions. Let it bounce away and fade out.
            coconut.PhysicsBody.CollisionBitMask = 0;
            coconut.RunAction(SCNAction.Sequence(new SCNAction[] {
                SCNAction.Wait(1.0),
                SCNAction.FadeOut(1.0),
                SCNAction.RemoveFromParentNode()
            }), () => {
                Coconuts.Remove((Coconut)coconut);
            });

            // Decrement score
            int amountToDrop = Score / 10;

            amountToDrop = Math.Max(1, amountToDrop);
            amountToDrop = Math.Min(10, amountToDrop);

            if (amountToDrop > Score)
            {
                amountToDrop = Score;
            }

            Score -= amountToDrop;

            // Throw bananas
            float spacing = 40f;

            for (int x = 0; x < amountToDrop; x++)
            {
                SCNNode banana = CreateBanana();
                RootNode.AddChildNode(banana);
                banana.Position = contactPoint;
                banana.PhysicsBody.CategoryBitMask  = GameCollisionCategory.NoCollide;
                banana.PhysicsBody.CollisionBitMask = GameCollisionCategory.Ground;
                SCNVector3 endPoint = SCNVector3.Zero;
                endPoint.X -= (spacing * x) + spacing;

                SCNAction flyoff = SCNAction.MoveBy(endPoint, MathUtils.RandomPercent() * 0.750f);
                flyoff.TimingMode = SCNActionTimingMode.EaseInEaseOut;

                banana.RunAction(flyoff, () => {
                    banana.PhysicsBody.CategoryBitMask  = GameCollisionCategory.Banana;
                    banana.PhysicsBody.CollisionBitMask = GameCollisionCategory.Ground | GameCollisionCategory.Player;
                });

                Bananas.Add(banana);
            }

            PlayerCharacter.InHitAnimation = true;
        }
예제 #13
0
        public SCNNode Create3DNode()
        {
            SCNScene jellyfishScn  = SCNScene.FromFile("art.scnassets/Jellyfish");
            SCNNode  jellyfishNode = jellyfishScn.RootNode.FindChildNode("Jellyfish", false);

            jellyfishNode.Scale    = new SCNVector3(0.019f, 0.019f, 0.019f);
            jellyfishNode.Position = new SCNVector3(0, 0, 0);

            // Animate the opacity to 100% over 0.75 seconds
            jellyfishNode.Opacity = 0;
            jellyfishNode.RunAction(SCNAction.FadeIn(0.75));

            return(jellyfishNode);
        }
        public override void ViewWillAppear(bool animated)
        {
            base.ViewWillAppear(animated);

            // Create a session configuration
            var configuration = new ARWorldTrackingConfiguration {
                PlaneDetection         = ARPlaneDetection.Horizontal,
                LightEstimationEnabled = true
            };

            // Run the view's session
            SceneView.Session.Run(configuration, ARSessionRunOptions.ResetTracking);

            // randomly choose a point to place the Earth
            var pos = new SCNVector3(-2f, 0f, -2f);


            // earth r=0.2
            var globe     = SCNSphere.Create(0.2f);
            var globeNode = new SCNNode {
                Position = pos, Geometry = globe
            };

            globeNode.Geometry.Materials = LoadMaterials();
            //globeNode.Transform = SCNMatrix4.CreateRotationX(0.4101524f); // 23.5 degrees
            SceneView.Scene.RootNode.AddChildNode(globeNode);

            globeNode.RunAction(SCNAction.RepeatActionForever(SCNAction.RotateBy(0, 1, 0, 3)));


            //moon r=0.08, orbit=0.6
            var pivotNode = new SCNNode {
                Position = new SCNVector3(0, 0, 0)
            };

            pivotNode.RunAction(SCNAction.RepeatActionForever(SCNAction.RotateBy(0, 1, 0, 5)));

            var moon     = SCNSphere.Create(0.08f);
            var moonNode = new SCNNode {
                Geometry = moon
            };

            //moonNode.Position = new SCNVector3(pos.X - 0.6f, pos.Y + 0.1f, pos.Z);
            moonNode.Position           = new SCNVector3(0.6f, 0.1f, pos.Z);
            moonNode.Geometry.Materials = LoadMoonMaterials();
            pivotNode.AddChildNode(moonNode);

            globeNode.AddChildNode(pivotNode);
        }
예제 #15
0
        void UpdateCameraWithCurrentGround(SCNNode node)
        {
            if (gameIsComplete)
            {
                return;
            }

            if (currentGround == null)
            {
                currentGround = node;
                return;
            }

            if (node != null && node != currentGround)
            {
                currentGround = node;

                if (groundToCameraPosition.ContainsKey(node))
                {
                    var position = groundToCameraPosition [node];

                    if (node == mainGround && Character.Node.Position.X < 2.5)
                    {
                        position = new SCNVector3(-0.098175f, 3.926991f, 0f);
                    }

                    SCNAction actionY = SCNAction.RotateTo(0f, position.Y, 0f, 3.0, true);
                    actionY.TimingMode = SCNActionTimingMode.EaseInEaseOut;
                    SCNAction actionX = SCNAction.RotateTo(position.X, 0f, 0f, 3.0, true);
                    actionX.TimingMode = SCNActionTimingMode.EaseInEaseOut;

                    cameraXHandle.RunAction(actionY);
                    cameraXHandle.RunAction(actionX);
                }
            }
        }
예제 #16
0
        public void CollectBanana(SCNNode banana)
        {
            // Flyoff the banana to the screen space position score label.
            // Don't increment score until the banana hits the score label.

            // ignore collisions
            banana.PhysicsBody = null;
            BananasCollected++;

            int    variance = 60;
            nfloat duration = 0.25f;

            nfloat apexY = worldSpaceLabelScorePosition.Y * 0.8f + (new Random().Next(0, variance) - variance / 2);

            worldSpaceLabelScorePosition.Z = banana.Position.Z;
            var apex = new SCNVector3(banana.Position.X + 10 + (new Random().Next(0, variance) - variance / 2), apexY, banana.Position.Z);

            SCNAction startFlyOff = SCNAction.MoveTo(apex, duration);

            startFlyOff.TimingMode = SCNActionTimingMode.EaseOut;

            SCNAction endFlyOff = SCNAction.CustomAction(duration, new SCNActionNodeWithElapsedTimeHandler((node, elapsedTime) => {
                nfloat t = elapsedTime / duration;
                var v    = new SCNVector3(
                    apex.X + ((worldSpaceLabelScorePosition.X - apex.X) * t),
                    apex.Y + ((worldSpaceLabelScorePosition.Y - apex.Y) * t),
                    apex.X + ((worldSpaceLabelScorePosition.Z - apex.Z) * t));
                node.Position = v;
            }));

            endFlyOff.TimingMode = SCNActionTimingMode.EaseInEaseOut;
            SCNAction flyoffSequence = SCNAction.Sequence(new SCNAction[] { startFlyOff, endFlyOff });

            banana.RunAction(flyoffSequence, () => {
                Bananas.Remove(banana);
                banana.RemoveFromParentNode();
                // Add to score.
                Score++;
                GameSimulation.Sim.PlaySound("deposit.caf");

                // Game Over
                if (Bananas.Count == 0)
                {
                    DoGameOver();
                }
            });
        }
예제 #17
0
        private void HandlerPick(UIPinchGestureRecognizer sender)
        {
            ARSCNView pinchScene = sender.View as ARSCNView;

            CoreGraphics.CGPoint pinchLocation = sender.LocationInView(pinchScene);
            SCNHitTestResult[]   hitTest       = pinchScene.HitTest(pinchLocation, new SCNHitTestOptions());

            if (hitTest?.Any() != true)
            {
                return;
            }

            SCNNode   node        = hitTest.First().Node;
            SCNAction pinchAction = SCNAction.ScaleBy(sender.Scale, 0);

            node.RunAction(pinchAction);
            sender.Scale = 1.0f;
        }
예제 #18
0
        void CollectPearl(SCNNode node)
        {
            if (node.ParentNode == null)
            {
                return;
            }

            SCNNode soundEmitter = SCNNode.Create();

            soundEmitter.Position = node.Position;
            node.ParentNode.AddChildNode(soundEmitter);
            soundEmitter.RunAction(SCNAction.Sequence(new [] {
                SCNAction.PlayAudioSource(collectPearlSound, true),
                SCNAction.RemoveFromParentNode()
            }));

            node.RemoveFromParentNode();
            GameView.DidCollectAPearl();
        }
예제 #19
0
 void BtnRun_TouchUpInside(object sender, EventArgs e)
 {
     if (planetsMove)
     {
         planetsMove = false;
         eartParentNode.RemoveAllActions();
         marsParentNode.RemoveAllActions();
         sunNode.RemoveAllActions();
         earthNode.RemoveAllActions();
         btnRun.SetTitle("PLAY", UIControlState.Normal);
     }
     else
     {
         planetsMove = true;
         eartParentNode.RunAction(RotationY(rotationEarth));
         marsParentNode.RunAction(RotationY(rotationMars));
         sunNode.RunAction(RotationY(rotationSun));
         earthNode.RunAction(RotationY(rotationMoon));
         btnRun.SetTitle("STOP", UIControlState.Normal);
     }
 }
        // after "happy" expressions, we add a ness node orbiting the face
        // however, the face currently seems to be able to sit in front of everything else..
        // probably easy to fix
        private static void AddOrbitingNode(SCNNode node)
        {
            var helperNode = new SCNNode()
            {
                Position = new SCNVector3(0, 0, -1.5f)
            };

            node.AddChildNode(helperNode);

            var b = SCNScene.FromFile("art.scnassets/basic-prefab.scn")
                    .RootNode
                    .ChildNodes
                    .First(x => x.Name.StartsWith("char", StringComparison.Ordinal)).Clone();

            b.RemoveFromParentNode();
            b.Scale    = new SCNVector3(.25f, .25f, .000001f);
            b.Position = new SCNVector3(0, 0, 1.25f);
            helperNode.AddChildNode(b);

            var rot      = SCNAction.RotateBy(0, 3, 0, 1.5);
            var infinite = SCNAction.RepeatActionForever(rot);

            helperNode.RunAction(infinite);
        }
예제 #21
0
        public override void ViewWillAppear(bool animated)
        {
            base.ViewWillAppear(animated);

            // Create a session configuration
            var configuration = new ARWorldTrackingConfiguration
            {
                PlaneDetection         = ARPlaneDetection.Horizontal,
                LightEstimationEnabled = true
            };

            // Run the view's session
            SceneView.Session.Run(configuration, ARSessionRunOptions.ResetTracking);

            // Find the ship and position it just in front of the camera
            var ship = SceneView.Scene.RootNode.FindChildNode("ship", true);

            //ship.Position = new SCNVector3(2f, -2f, -9f);
            //HACK: to see the jet move (circle around the viewer in a roll), comment out the ship.Position line above
            // and uncomment the code below (courtesy @lobrien)

            var animation = SCNAction.RepeatActionForever(SCNAction.RotateBy(0, (float)Math.PI, (float)Math.PI, (float)1));
            var pivotNode = new SCNNode {
                Position = new SCNVector3(0.0f, 2.0f, 0.0f)
            };

            pivotNode.RunAction(SCNAction.RepeatActionForever(SCNAction.RotateBy(0, -2, 0, 10)));
            ship.RemoveFromParentNode();
            pivotNode.AddChildNode(ship);
            SceneView.Scene.RootNode.AddChildNode(pivotNode);
            ship.Scale    = new SCNVector3(0.1f, 0.1f, 0.1f);
            ship.Position = new SCNVector3(2f, -2f, -3f);
            ship.RunAction(SCNAction.RepeatActionForever(SCNAction.RotateBy(0, 0, 2, 1)));

            //ENDHACK
        }
예제 #22
0
        public void CollectLargeBanana(SCNNode largeBanana)
        {
            // When the player hits a large banana, explode it into smaller bananas.
            // We explode into a predefined pattern: square, diamond, letterA, letterB

            // ignore collisions
            largeBanana.PhysicsBody = null;
            CoinsCollected++;

            LargeBananas.Remove(largeBanana);
            largeBanana.RemoveAllParticleSystems();
            largeBanana.RemoveFromParentNode();

            // Add to score.
            Score += 100;

            var square = new string[] {
                "1", "1", "1", "1", "1",
                "1", "1", "1", "1", "1",
                "1", "1", "1", "1", "1",
                "1", "1", "1", "1", "1",
                "1", "1", "1", "1", "1"
            };

            var diamond = new string[] {
                "0", "0", "1", "0", "0",
                "0", "1", "1", "1", "0",
                "1", "1", "1", "1", "1",
                "0", "1", "1", "1", "0",
                "0", "0", "1", "0", "0"
            };

            var letterA = new string[] {
                "1", "0", "0", "1", "0",
                "1", "0", "0", "1", "0",
                "1", "1", "1", "1", "0",
                "1", "0", "0", "1", "0",
                "0", "1", "1", "0", "0"
            };

            var letterB = new string[] {
                "1", "1", "0", "0", "0",
                "1", "0", "1", "0", "0",
                "1", "1", "0", "0", "0",
                "1", "0", "1", "0", "0",
                "1", "1", "0", "0", "0"
            };

            var choices = new List <string[]> {
                square, diamond, letterA, letterB
            };
            float vertSpacing = 40f;
            float spacing     = 0.0075f;

            string[] choice = choices [new Random().Next(0, choices.Count)];
            for (int y = 0; y < 5; y++)
            {
                for (int x = 0; x < 5; x++)
                {
                    int place = Int32.Parse(choice [(y * 5) + x]);
                    if (place != 1)
                    {
                        continue;
                    }

                    SCNNode banana = CreateBanana();
                    RootNode.AddChildNode(banana);
                    banana.Position = largeBanana.Position;
                    banana.PhysicsBody.CategoryBitMask  = GameCollisionCategory.NoCollide;
                    banana.PhysicsBody.CollisionBitMask = GameCollisionCategory.Ground;

                    SCNVector3 endPoint = LocationAlongPath(TimeAlongPath + spacing * (x + 1));
                    endPoint.Y += (vertSpacing * (y + 1));

                    SCNAction flyoff = SCNAction.MoveTo(endPoint, MathUtils.RandomPercent() * 0.25f);
                    flyoff.TimingMode = SCNActionTimingMode.EaseInEaseOut;

                    banana.RunAction(flyoff, () => {
                        banana.PhysicsBody.CategoryBitMask  = GameCollisionCategory.Banana;
                        banana.PhysicsBody.CollisionBitMask = GameCollisionCategory.Ground | GameCollisionCategory.Player;
                        GameSimulation.Sim.PlaySound("deposit.caf");
                    });

                    Bananas.Add(banana);
                }
            }
        }
예제 #23
0
		public void CollideWithCoconut (SCNNode coconut, SCNVector3 contactPoint)
		{
			// No more collisions. Let it bounce away and fade out.
			coconut.PhysicsBody.CollisionBitMask = 0;
			coconut.RunAction (SCNAction.Sequence (new SCNAction[] {
				SCNAction.Wait (1.0),
				SCNAction.FadeOut (1.0),
				SCNAction.RemoveFromParentNode ()
			}), () => {
				Coconuts.Remove ((Coconut)coconut);
			});

			// Decrement score
			int amountToDrop = Score / 10;

			amountToDrop = Math.Max (1, amountToDrop);
			amountToDrop = Math.Min (10, amountToDrop);

			if (amountToDrop > Score)
				amountToDrop = Score;

			Score -= amountToDrop;

			// Throw bananas
			float spacing = 40f;
			for (int x = 0; x < amountToDrop; x++) {
				SCNNode banana = CreateBanana ();
				RootNode.AddChildNode (banana);
				banana.Position = contactPoint;
				banana.PhysicsBody.CategoryBitMask = GameCollisionCategory.NoCollide;
				banana.PhysicsBody.CollisionBitMask = GameCollisionCategory.Ground;
				SCNVector3 endPoint = SCNVector3.Zero;
				endPoint.X -= (spacing * x) + spacing;

				SCNAction flyoff = SCNAction.MoveBy (endPoint, MathUtils.RandomPercent () * 0.750f);
				flyoff.TimingMode = SCNActionTimingMode.EaseInEaseOut;

				banana.RunAction (flyoff, () => {
					banana.PhysicsBody.CategoryBitMask = GameCollisionCategory.Banana;
					banana.PhysicsBody.CollisionBitMask = GameCollisionCategory.Ground | GameCollisionCategory.Player;
				});

				Bananas.Add (banana);
			}

			PlayerCharacter.InHitAnimation = true;
		}
예제 #24
0
		//present spritekit integration slide
		void ShowSpriteKitSlide ()
		{
			//place camera
			SCNTransaction.Begin ();
			SCNTransaction.AnimationDuration = 2;
			CameraHandle.Position = new SCNVector3 (CameraHandle.Position.X + 200, 60, 0);
			SCNTransaction.Commit ();

			//load plok particles
			Plok = SCNParticleSystem.Create ("plok.scnp", "assets.scnassets/particles");

			//create a spinning object
			Torus = SCNNode.Create ();
			Torus.Position = new SCNVector3 (CameraHandle.Position.X, 60, 10);
			Torus.Geometry = SCNTorus.Create (W / 2, W / 6);
			Torus.PhysicsBody = SCNPhysicsBody.CreateStaticBody ();
			Torus.Opacity = 0.0f;

			var material = Torus.Geometry.FirstMaterial;
			material.Specular.Contents = SKColorHelper.FromCommonWhiteAlpha (0.5f, 1);
			material.Shininess = 2.0f;

			#if __IOS__
			material.Normal.Contents = new UIImage ("images/wood-normal.png");
			#else
			material.Normal.Contents = new NSImage (NSBundle.MainBundle.PathForResource ("images/wood-normal", "png"));
			#endif

			Scene.RootNode.AddChildNode (Torus);
			Torus.RunAction (SCNAction.RepeatActionForever (SCNAction.RotateBy (NMath.PI * 2, new SCNVector3 (0.4f, 1, 0), 8)));

			//preload it to avoid frame drop
			//[(SCNView*)self.view prepareObject:_scene shouldAbortBlock:nil];

			Scene.PhysicsWorld.WeakContactDelegate = this;

			//setup material
			var skScene = SKScene.FromSize (new CGSize (SPRITE_SIZE, SPRITE_SIZE));
			skScene.BackgroundColor = SKColor.White;
			material.Diffuse.Contents = skScene;

			SCNTransaction.Begin ();
			SCNTransaction.AnimationDuration = 1;
			SCNTransaction.SetCompletionBlock (StartLaunchingColors);

			Torus.Opacity = 1.0f;

			SCNTransaction.Commit ();
		}
예제 #25
0
		public void CollectBanana (SCNNode banana)
		{
			// Flyoff the banana to the screen space position score label.
			// Don't increment score until the banana hits the score label.

			// ignore collisions
			banana.PhysicsBody = null;
			BananasCollected++;

			int variance = 60;
			nfloat duration = 0.25f;

			nfloat apexY = worldSpaceLabelScorePosition.Y * 0.8f + (new Random ().Next (0, variance) - variance / 2);
			worldSpaceLabelScorePosition.Z = banana.Position.Z;
			var apex = new SCNVector3 (banana.Position.X + 10 + (new Random ().Next (0, variance) - variance / 2), apexY, banana.Position.Z);

			SCNAction startFlyOff = SCNAction.MoveTo (apex, duration);
			startFlyOff.TimingMode = SCNActionTimingMode.EaseOut;

			SCNAction endFlyOff = SCNAction.CustomAction (duration, new SCNActionNodeWithElapsedTimeHandler ((node, elapsedTime) => {
				nfloat t = elapsedTime / duration;
				var v = new SCNVector3 (
					        apex.X + ((worldSpaceLabelScorePosition.X - apex.X) * t),
					        apex.Y + ((worldSpaceLabelScorePosition.Y - apex.Y) * t),
					        apex.X + ((worldSpaceLabelScorePosition.Z - apex.Z) * t));
				node.Position = v;
			}));

			endFlyOff.TimingMode = SCNActionTimingMode.EaseInEaseOut;
			SCNAction flyoffSequence = SCNAction.Sequence (new SCNAction[] { startFlyOff, endFlyOff });

			banana.RunAction (flyoffSequence, () => {
				Bananas.Remove (banana);
				banana.RemoveFromParentNode ();
				// Add to score.
				Score++;
				GameSimulation.Sim.PlaySound ("deposit.caf");

				// Game Over
				if (Bananas.Count == 0)
					DoGameOver ();
			});
		}
예제 #26
0
 public static void MoveTo(this SCNNode node, SCNNode target, double timeInSeconds, SCNActionTimingMode timingMode = SCNActionTimingMode.EaseOut)
 => node.RunAction(SCNAction.MoveTo(new SCNVector3(target.Position.X, target.Position.Y, target.Position.Z), timeInSeconds).Ease(timingMode));
예제 #27
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 ();
		}
예제 #28
0
 public static void RotateBy(this SCNNode node, float x, float y, float z, double timeInSeconds, SCNActionTimingMode timingMode = SCNActionTimingMode.EaseOut)
 => node.RunAction(SCNAction.RotateBy(x, y, z, timeInSeconds).Ease(timingMode));