Ejemplo n.º 1
0
    private void Update()
    {
        timer += Time.deltaTime;

        if (timer > delay)
        {
            timer = 0;
            PalmTree tree = spawner.GetPooledObject();
            if (tree != null)
            {
                tree.Initialize(spawner.spawnLocations[Random.Range(0, spawner.spawnLocations.Length)]);
            }
        }
    }
Ejemplo n.º 2
0
        static void ProcessTrees( ForesterArgs args, IList<Tree> treeList ) {
            TreeShape[] shapeChoices;
            switch( args.Shape ) {
                case TreeShape.Stickly:
                    shapeChoices = new[]{ TreeShape.Normal,
                                          TreeShape.Bamboo,
                                          TreeShape.Palm };
                    break;
                case TreeShape.Procedural:
                    shapeChoices = new[]{ TreeShape.Round,
                                          TreeShape.Cone };
                    break;
                default:
                    shapeChoices = new[] { args.Shape };
                    break;
            }

            for( int i = 0; i < treeList.Count; i++ ) {
                TreeShape newShape = shapeChoices[args.Rand.Next( 0, shapeChoices.Length )];
                Tree newTree;
                switch( newShape ) {
                    case TreeShape.Normal:
                        newTree = new NormalTree();
                        break;
                    case TreeShape.Bamboo:
                        newTree = new BambooTree();
                        break;
                    case TreeShape.Palm:
                        newTree = new PalmTree();
                        break;
                    case TreeShape.Round:
                        newTree = new RoundTree();
                        break;
                    case TreeShape.Cone:
                        newTree = new ConeTree();
                        break;
                    case TreeShape.Rainforest:
                        newTree = new RainforestTree();
                        break;
                    case TreeShape.Mangrove:
                        newTree = new MangroveTree();
                        break;
                    default:
                        throw new ArgumentException( "Unknown tree shape type" );
                }
                newTree.Copy( treeList[i] );

                if( args.MapHeightLimit ) {
                    int height = newTree.Height;
                    int yBase = newTree.Pos[1];
                    int mapHeight = args.Map.Height;
                    int foliageHeight;
                    if( args.Shape == TreeShape.Rainforest ) {
                        foliageHeight = 2;
                    } else {
                        foliageHeight = 4;
                    }
                    if( yBase + height + foliageHeight > mapHeight ) {
                        newTree.Height = mapHeight - yBase - foliageHeight;
                    }
                }

                if( newTree.Height < 1 ) newTree.Height = 1;
                newTree.Prepare();
                treeList[i] = newTree;
            }
        }
Ejemplo n.º 3
0
        static void ProcessTrees(ForesterArgs args, IList <Tree> treelist)
        {
            TreeShape[] shapeChoices;
            switch (args.Shape)
            {
            case TreeShape.Stickly:
                shapeChoices = new[] { TreeShape.Normal,
                                       TreeShape.Bamboo,
                                       TreeShape.Palm };
                break;

            case TreeShape.Procedural:
                shapeChoices = new[] { TreeShape.Round,
                                       TreeShape.Cone };
                break;

            default:
                shapeChoices = new[] { args.Shape };
                break;
            }

            for (int i = 0; i < treelist.Count; i++)
            {
                TreeShape newshape = shapeChoices[args.Rand.Next(0, shapeChoices.Length)];
                Tree      newTree;
                switch (newshape)
                {
                case TreeShape.Normal:
                    newTree = new NormalTree();
                    break;

                case TreeShape.Bamboo:
                    newTree = new BambooTree();
                    break;

                case TreeShape.Palm:
                    newTree = new PalmTree();
                    break;

                case TreeShape.Round:
                    newTree = new RoundTree();
                    break;

                case TreeShape.Cone:
                    newTree = new ConeTree();
                    break;

                case TreeShape.Rainforest:
                    newTree = new RainforestTree();
                    break;

                case TreeShape.Mangrove:
                    newTree = new MangroveTree();
                    break;

                default:
                    throw new ArgumentException("Unknown tree shape type");
                }
                newTree.Copy(treelist[i]);

                if (args.MapHeightLimit)
                {
                    int height    = newTree.Height;
                    int ybase     = newTree.Pos[1];
                    int mapHeight = args.Map.Height;
                    int foliageHeight;
                    if (args.Shape == TreeShape.Rainforest)
                    {
                        foliageHeight = 2;
                    }
                    else
                    {
                        foliageHeight = 4;
                    }
                    if (ybase + height + foliageHeight > mapHeight)
                    {
                        newTree.Height = mapHeight - ybase - foliageHeight;
                    }
                }

                if (newTree.Height < 1)
                {
                    newTree.Height = 1;
                }
                newTree.Prepare();
                treelist[i] = newTree;
            }
        }
Ejemplo n.º 4
0
        public override void PresentStep(int index, PresentationViewController presentationViewController)
        {
            switch (index)
            {
            case 0:
                break;

            case 1:
                TextManager.HighlightBullet(0);

                StaticShadowNode.Opacity = 1;

                var node = TextManager.AddCode("#aMaterial.#multiply#.contents = aShadowMap;#");
                node.Position = new SCNVector3(node.Position.X, node.Position.Y - 4, node.Position.Z);
                foreach (var child in node.ChildNodes)
                {
                    child.RenderingOrder = 1;
                    foreach (var m in child.Geometry.Materials)
                    {
                        m.ReadsFromDepthBuffer = false;
                    }
                }
                break;

            case 2:
                //move the tree
                PalmTree.RunAction(SCNAction.RotateBy(0, NMath.PI * 4, 0, 8));
                break;

            case 3:
                TextManager.FadesIn = true;
                TextManager.FadeOutText(SlideTextManager.TextType.Code);
                TextManager.AddEmptyLine();

                node = TextManager.AddCode("#aLight.#castsShadow# = YES;#");
                foreach (SCNNode child in node.ChildNodes)
                {
                    child.RenderingOrder = 1;
                    foreach (SCNMaterial m in child.Geometry.Materials)
                    {
                        m.ReadsFromDepthBuffer = false;
                        m.WritesToDepthBuffer  = false;
                    }
                }

                node.Position = new SCNVector3(node.Position.X, node.Position.Y - 6, node.Position.Z);

                SCNTransaction.Begin();
                SCNTransaction.AnimationDuration = 0.75f;

                var spot = presentationViewController.SpotLight;
                OldSpotShadowColor      = spot.Light.ShadowColor;
                spot.Light.ShadowColor  = NSColor.Black;
                spot.Light.ShadowRadius = 3;

                var tp = TextManager.TextNode.Position;

                var superNode = presentationViewController.CameraNode.ParentNode.ParentNode;

                var p0 = GroundNode.ConvertPositionToNode(SCNVector3.Zero, null);
                var p1 = GroundNode.ConvertPositionToNode(new SCNVector3(20, 0, 0), null);
                var tr = new SCNVector3(p1.X - p0.X, p1.Y - p0.Y, p1.Z - p0.Z);

                var p = superNode.Position;
                p.X  += tr.X;
                p.Y  += tr.Y;
                p.Z  += tr.Z;
                tp.X += 20;
                tp.Y += 0;
                tp.Z += 0;
                superNode.Position            = p;
                TextManager.TextNode.Position = tp;
                SCNTransaction.Commit();

                TextManager.HighlightBullet(1);

                break;

            case 4:
                //move the light
                var lightPivot = SCNNode.Create();
                lightPivot.Position = Character.Position;
                GroundNode.AddChildNode(lightPivot);

                spot            = presentationViewController.SpotLight;
                OldSpotPosition = spot.Position;
                OldSpotParent   = spot.ParentNode;
                OldSpotZNear    = spot.Light.ZNear;

                spot.Light.ZNear = 20;
                spot.Position    = lightPivot.ConvertPositionFromNode(spot.Position, spot.ParentNode);
                lightPivot.AddChildNode(spot);

                //add an object to represent the light
                var lightModel  = SCNNode.Create();
                var lightHandle = SCNNode.Create();
                var cone        = SCNCone.Create(0, 0.5f, 1);
                cone.RadialSegmentCount = 10;
                cone.HeightSegmentCount = 5;
                lightModel.Geometry     = cone;
                lightModel.Geometry.FirstMaterial.Emission.Contents = NSColor.Yellow;
                lightHandle.Position   = new SCNVector3(spot.Position.X * DIST, spot.Position.Y * DIST, spot.Position.Z * DIST);
                lightModel.CastsShadow = false;
                lightModel.EulerAngles = new SCNVector3(NMath.PI / 2, 0, 0);
                lightHandle.AddChildNode(lightModel);
                lightHandle.Constraints = new SCNConstraint[] { SCNLookAtConstraint.Create(Character) };
                lightPivot.AddChildNode(lightHandle);
                LightHandle = lightHandle;

                var animation = CABasicAnimation.FromKeyPath("eulerAngles.z");
                animation.From           = new NSNumber((nfloat)(Math.PI / 4) * 1.7f);
                animation.To             = new NSNumber((nfloat)(-Math.PI / 4) * 0.3f);
                animation.Duration       = 4;
                animation.AutoReverses   = true;
                animation.RepeatCount    = float.MaxValue;
                animation.TimingFunction = CAMediaTimingFunction.FromName(CAMediaTimingFunction.EaseInEaseOut);
                animation.TimeOffset     = animation.Duration / 2;
                lightPivot.AddAnimation(animation, new NSString("lightAnim"));
                break;

            case 5:
                TextManager.FadeOutText(SlideTextManager.TextType.Code);
                var text = TextManager.AddCode("#aLight.#shadowMode# =\n#SCNShadowModeModulated#;\naLight.#gobo# = anImage;#");
                text.Position = new SCNVector3(text.Position.X, text.Position.Y - 6, text.Position.Z);
                text.EnumerateChildNodes((SCNNode child, out bool stop) => {
                    stop = false;
                    child.RenderingOrder = 1;
                    foreach (var m in child.Geometry.Materials)
                    {
                        m.ReadsFromDepthBuffer = false;
                        m.WritesToDepthBuffer  = false;
                    }
                    return(stop);
                });

                LightHandle.RemoveFromParentNode();

                RestoreSpotPosition(presentationViewController);
                TextManager.HighlightBullet(2);


                spot = presentationViewController.SpotLight;
                spot.Light.CastsShadow = false;

                var head = Character.FindChildNode("Bip001_Pelvis", true);

                node                      = SCNNode.Create();
                node.Light                = SCNLight.Create();
                node.Light.LightType      = SCNLightType.Spot;
                node.Light.SpotOuterAngle = 30;
                node.Constraints          = new SCNConstraint[] { SCNLookAtConstraint.Create(head) };
                node.Position             = new SCNVector3(0, 220, 0);
                node.Light.ZNear          = 10;
                node.Light.ZFar           = 1000;
                node.Light.Gobo.Contents  = new NSImage(NSBundle.MainBundle.PathForResource("SharedTextures/blobShadow", "jpg"));
                node.Light.Gobo.Intensity = 0.65f;
                node.Light.ShadowMode     = SCNShadowMode.Modulated;

                //exclude character from shadow
                node.Light.CategoryBitMask = 0x1;
                Character.FindNodes((SCNNode child, out bool stop) => {
                    stop = false;
                    child.CategoryBitMask = 0x2;
                    return(stop);
                });

                Projector = node;
                Character.AddChildNode(node);

                break;
            }
        }
Ejemplo n.º 5
0
        void ProcessTrees(List<Tree> treelist)
        {
            TreeShape[] shape_choices;
            switch (args.SHAPE)
            {
                case TreeShape.Stickly:
                    shape_choices = new TreeShape[]{ TreeShape.Normal,
                                                     TreeShape.Bamboo,
                                                     TreeShape.Palm};
                    break;
                case TreeShape.Procedural:
                    shape_choices = new TreeShape[]{ TreeShape.Round,
                                                     TreeShape.Cone };
                    break;
                default:
                    shape_choices = new TreeShape[] { args.SHAPE };
                    break;
            }

            for (int i = 0; i < treelist.Count; i++)
            {
                TreeShape newshape = shape_choices[args.rand.Next(0, shape_choices.Length)];
                Tree newtree;
                switch (newshape)
                {
                    case TreeShape.Normal:
                        newtree = new NormalTree();
                        break;
                    case TreeShape.Bamboo:
                        newtree = new BambooTree();
                        break;
                    case TreeShape.Palm:
                        newtree = new PalmTree();
                        break;
                    case TreeShape.Round:
                        newtree = new RoundTree();
                        break;
                    case TreeShape.Cone:
                        newtree = new ConeTree();
                        break;
                    case TreeShape.Rainforest:
                        newtree = new RainforestTree();
                        break;
                    case TreeShape.Mangrove:
                        newtree = new MangroveTree();
                        break;
                    default:
                        throw new ArgumentException();
                }
                newtree.Copy(treelist[i]);

                if (args.MAPHEIGHTLIMIT)
                {
                    int height = newtree.height;
                    int ybase = newtree.pos[1];
                    int mapheight = args.inMap.MapSizeZ;
                    int foliageheight;
                    if (args.SHAPE == TreeShape.Rainforest)
                    {
                        foliageheight = 2;
                    }
                    else
                    {
                        foliageheight = 4;
                    }
                    if (ybase + height + foliageheight > mapheight)
                    {
                        newtree.height = mapheight - ybase - foliageheight;
                    }
                }

                if (newtree.height < 1) newtree.height = 1;
                newtree.Prepare();
                treelist[i] = newtree;
            }
        }
Ejemplo n.º 6
0
        void ProcessTrees(List <Tree> treelist)
        {
            TreeShape[] shape_choices;
            switch (args.SHAPE)
            {
            case TreeShape.Stickly:
                shape_choices = new TreeShape[] { TreeShape.Normal,
                                                  TreeShape.Bamboo,
                                                  TreeShape.Palm };
                break;

            case TreeShape.Procedural:
                shape_choices = new TreeShape[] { TreeShape.Round,
                                                  TreeShape.Cone };
                break;

            default:
                shape_choices = new TreeShape[] { args.SHAPE };
                break;
            }

            for (int i = 0; i < treelist.Count; i++)
            {
                TreeShape newshape = shape_choices[args.rand.Next(0, shape_choices.Length)];
                Tree      newtree;
                switch (newshape)
                {
                case TreeShape.Normal:
                    newtree = new NormalTree();
                    break;

                case TreeShape.Bamboo:
                    newtree = new BambooTree();
                    break;

                case TreeShape.Palm:
                    newtree = new PalmTree();
                    break;

                case TreeShape.Round:
                    newtree = new RoundTree();
                    break;

                case TreeShape.Cone:
                    newtree = new ConeTree();
                    break;

                case TreeShape.Rainforest:
                    newtree = new RainforestTree();
                    break;

                case TreeShape.Mangrove:
                    newtree = new MangroveTree();
                    break;

                default:
                    throw new ArgumentException();
                }
                newtree.Copy(treelist[i]);

                if (args.MAPHEIGHTLIMIT)
                {
                    int height    = newtree.height;
                    int ybase     = newtree.pos[1];
                    int mapheight = args.inMap.MapSizeZ;
                    int foliageheight;
                    if (args.SHAPE == TreeShape.Rainforest)
                    {
                        foliageheight = 2;
                    }
                    else
                    {
                        foliageheight = 4;
                    }
                    if (ybase + height + foliageheight > mapheight)
                    {
                        newtree.height = mapheight - ybase - foliageheight;
                    }
                }

                if (newtree.height < 1)
                {
                    newtree.height = 1;
                }
                newtree.Prepare();
                treelist[i] = newtree;
            }
        }