Exemplo n.º 1
0
        void CreateSwingingTorch()
        {
            var     scnene     = SCNScene.FromFile("torch", GameSimulation.PathForArtResource("level/"), new NSDictionary());
            SCNNode torchSwing = scnene.RootNode.FindChildNode("dummy_master", true);

            RootNode.AddChildNode(torchSwing);
        }
Exemplo n.º 2
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;
        }
Exemplo n.º 3
0
        public GameSimulation()
        {
            // We create one level in our simulation.
            GameLevel        = new GameLevel();
            CurrentGameState = GameState.Paused;

            // Register ourself as a listener to physics callbacks.
            SCNNode levelNode = GameLevel.CreateLevel();

            RootNode.AddChildNode(levelNode);
            PhysicsWorld.WeakContactDelegate = this;
            PhysicsWorld.Gravity             = new SCNVector3(0f, -800f, 0f);

            SetupTechniques();
        }
Exemplo n.º 4
0
        void AddMonkeyAtPosition(SCNVector3 worldPos, nfloat rotation)
        {
            if (Monkeys == null)
            {
                Monkeys = new List <MonkeyCharacter> ();
            }

            SCNNode palmTree = CreateMonkeyPalmTree();

            palmTree.Position = worldPos;
            palmTree.Rotation = new SCNVector4(0f, 1f, 0f, rotation);
            RootNode.AddChildNode(palmTree);

            MonkeyCharacter monkey = (MonkeyCharacter)palmTree.FindChildNode("monkey", true);

            if (monkey != null)
            {
                Monkeys.Add(monkey);
            }
        }
Exemplo n.º 5
0
 public void Add(SCNNode node)
 {
     RootNode.AddChildNode(node);
 }
Exemplo n.º 6
0
    // Use this for initialization
    void Start()
    {
        RootNode.ShowSelf(true);
        // 构建树状结构
        // 一级菜单
        for (int i = 0; i < 2; ++i)
        {
            string       str   = "一级:" + i;
            Color        color = new Color(0, 0, 0);
            TreeViewNode node1 = InitNode(str, color);
            // 添加子节点
            RootNode.AddChildNode(node1);
            // 子节点的消隐
            node1.ShowSelf(true);
            // 节点的点击操作,这边用的是Toggle
            node1.gameObject.GetComponent <Toggle>().onValueChanged.AddListener((bool bValue) =>
            {
                node1.ShowChild(bValue);
            });

            // 二级菜单
            for (int j = 0; j < 3; ++j)
            {
                str   = "一级:" + i + "/二级:" + j;
                color = new Color(0.5f, 0.5f, 0.5f);
                TreeViewNode node2 = InitNode(str, color);
                node1.AddChildNode(node2);
                node2.ShowSelf(false);
                node2.gameObject.GetComponent <Toggle>().onValueChanged.AddListener((bool bValue) =>
                {
                    node2.ShowChild(bValue);
                });

                // 三级菜单
                for (int k = 0; k < 4; ++k)
                {
                    str   = "一级:" + i + "/二级:" + j + "/三级:" + k;
                    color = new Color(1.0f, 1.0f, 1.0f);
                    TreeViewNode node3 = InitNode(str, color);
                    node3.ShowSelf(false);

                    node2.AddChildNode(node3);
                }

                node2.ShowChild(false);
            }
        }

        // 对树状结构进行深度遍历,然后将其展开成数组
        List <TreeViewNode> listNodes = new List <TreeViewNode>();

        // 展开成数组
        RootNode.SortTreeIntoList(listNodes);
        listNodes.Remove(RootNode);

        /*
         *  设置UI中的父子关系,首先清除掉父子关系
         *  不清除掉的话,重新设置父子关系无法重新排布顺序
         *  因为原先都是属于RootNode的子物体
         */
        foreach (TreeViewNode node in listNodes)
        {
            node.gameObject.transform.SetParent(null);
        }

        foreach (TreeViewNode node in listNodes)
        {
            node.gameObject.transform.SetParent(RootNode.gameObject.transform);
        }
    }
Exemplo n.º 7
0
        public void ResetLevel()
        {
            Score            = 0;
            SecondsRemaining = 120;
            CoinsCollected   = 0;
            BananasCollected = 0;

            TimeAlongPath            = 0;
            PlayerCharacter.Position = LocationAlongPath(TimeAlongPath);
            PlayerCharacter.Rotation = GetPlayerDirectionFromCurrentPosition();
            HitByLavaReset           = false;

            // Remove dynamic objects from the level.
            SCNTransaction.Begin();

            if (Bananas != null)
            {
                foreach (SCNNode b in Coconuts)
                {
                    b.RemoveFromParentNode();
                }
            }

            if (Bananas != null)
            {
                foreach (SCNNode b in Bananas)
                {
                    b.RemoveFromParentNode();
                }
            }

            if (LargeBananas != null)
            {
                foreach (SCNNode largeBanana in LargeBananas)
                {
                    largeBanana.RemoveFromParentNode();
                }
            }

            SCNTransaction.Commit();

            // Add dynamic objects to the level, like bananas and large bananas
            Bananas  = new List <SCNNode> ();
            Coconuts = new List <Coconut> ();

            for (int i = 0; i < 10; i++)
            {
                SCNNode banana = CreateBanana();
                RootNode.Add(banana);
                SCNVector3 location = LocationAlongPath((i + 1) / 20.0f - 0.01f);
                location.Y     += 50;
                banana.Position = location;
                Bananas.Add(banana);
            }

            LargeBananas = new List <SCNNode> ();

            for (int i = 0; i < 6; i++)
            {
                SCNNode largeBanana = CreateLargeBanana();
                RootNode.AddChildNode(largeBanana);
                SCNVector3 location = LocationAlongPath(MathUtils.RandomPercent());
                location.Y          += 50;
                largeBanana.Position = location;
                LargeBananas.Add(largeBanana);
            }

            GameSimulation.Sim.PlayMusic("music.caf");
            GameSimulation.Sim.PlayMusic("night.caf");
        }
Exemplo n.º 8
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);
                }
            }
        }