Example #1
0
        public BackGround(TextureManager _texturemanager, int level, Particle.Particles _p = null)
        {
            if (_p != null)
            {
                particles = _p;
                allowrunParticles = true;
            }

            this.level = level;
            renderer = Stage1State._renderer;
            this.texturemanager = _texturemanager;

            Texture texture = _texturemanager.Get("shade1");
            background = new Sprite();
            background.Texture = texture;
            background.SetPosition(0, 225);
            background.SetHeight(450);
            background.SetWidth(385+10);

            tree = new List<Tree>();

            //添加一开始就有的树
            for (int i = 0; i < 3; i++)
            {
                backgroundimage = new BackGroundImage(_texturemanager, renderer, "stg1bg", new Rectangle(0.01f, 0.01f, 0.48f, 0.48f), 385+10, 450);
                SpeedY = 0.05f;
                backgroundimage.SetPosition(0, 225);

                Tree tree1 = new Tree(texturemanager, renderer, "stg1bg", false, 200, 200);
                tree1.setTop(400);
                tree1.setPosition(16 + 30 * (float)random.NextDouble() - 15, i*200 + 60 * (float)random.NextDouble() - 30);
                tree.Add(tree1);

                tree1 = new Tree(texturemanager, renderer, "stg1bg", true, 200, 200);
                tree1.setTop(400);
                tree1.setPosition(-100 + 30 * (float)random.NextDouble() - 15, i * 200 + 100 * (float)random.NextDouble() - 50);
                tree.Add(tree1);

                tree1 = new Tree(texturemanager, renderer, "stg1bg", true, 200, 200);
                tree1.setTop(400);
                tree1.setPosition(160 + 30 * (float)random.NextDouble() - 15, i * 200 + 60 * (float)random.NextDouble() - 30);
                tree.Add(tree1);
            }
        }
Example #2
0
        public void Update(double elapsedTime)
        {
            if (allowrunParticles)
            {
                particles.Update(elapsedTime);
            }
            foreach (Particle.Particles p in ParticlesList)
            {
                p.Update(elapsedTime);
            }

            move_y += elapsedTime * SpeedY*680;

            if (move_y > each_m)
            {
                move_y = 0;

                switch (current_index)
                {
                    case 0:
                        Tree Tr = new Tree(texturemanager, renderer, "stg1bg", false, 200, 200);
                         Tr = new Tree(texturemanager, renderer, "stg1bg", false, 200, 200);
                         Tr.setTop(400);
                         Tr.setPosition(31, 430);
                         tree.Add(Tr);
                         Tr = new Tree(texturemanager, renderer, "stg1bg", true, 200, 200);
                         Tr.setTop(400);
                         Tr.setPosition(-115, 450);
                         tree.Add(Tr);
                         Tr = new Tree(texturemanager, renderer, "stg1bg", true, 200, 200);
                         Tr.setTop(400);
                         Tr.setPosition(175, 405);
                         tree.Add(Tr);
                        current_index++;
                        break;
                    case 1:
                        Tree Tr1 = new Tree(texturemanager, renderer, "stg1bg", false,200,200);
                        Tr1.setTop(400);
                        Tr1.setPosition(60, 430);
                        tree.Add(Tr1);
                        Tr1 = new Tree(texturemanager, renderer, "stg1bg", true, 200, 200);
                        Tr1.setTop(400);
                        Tr1.setPosition(-75, 430);
                        tree.Add(Tr1);
                        Tr1 = new Tree(texturemanager, renderer, "stg1bg", true, 200, 200);
                        Tr1.setTop(400);
                        Tr1.setPosition(155, 418);
                        tree.Add(Tr1);
                        current_index++;
                        break;
                    case 2:
                        Tree Tr2 = new Tree(texturemanager, renderer, "stg1bg", false,200,200);
                        Tr2.setTop(400);
                        Tr2.setPosition(10, 430);
                        tree.Add(Tr2);
                        Tr2 = new Tree(texturemanager, renderer, "stg1bg", true, 200, 200);
                        Tr2.setTop(400);
                        Tr2.setPosition(-100, 425);
                        tree.Add(Tr2);
                        Tr2 = new Tree(texturemanager, renderer, "stg1bg", true, 200, 200);
                        Tr2.setTop(400);
                        Tr2.setPosition(165, 408);
                        tree.Add(Tr2);
                        current_index++;
                        break;
                    case 3:
                        Tree Tr3 = new Tree(texturemanager, renderer, "stg1bg", false,200,200);
                        Tr3.setTop(400);
                        Tr3.setPosition(-10, 410);
                        tree.Add(Tr3);
                        Tr3 = new Tree(texturemanager, renderer, "stg1bg", true, 200, 200);
                        Tr3.setTop(400);
                        Tr3.setPosition(-120, 435);
                        tree.Add(Tr3);
                        Tr3 = new Tree(texturemanager, renderer, "stg1bg", true, 200, 200);
                        Tr3.setTop(400);
                        Tr3.setPosition(135, 428);
                        tree.Add(Tr3);
                        current_index = 0;
                        break;
                }

                //Tree tree1 = new Tree(texturemanager, renderer, "stg1bg", false,200,200);
                //tree1.setTop(400);
                //tree1.setPosition(16+ 30*(float)random.NextDouble() - 15, 400+60*(float)random.NextDouble() - 30);
                //tree.Add(tree1);

                //tree1 = new Tree(texturemanager, renderer, "stg1bg", true, 200, 200);
                //tree1.setTop(400);
                //tree1.setPosition(-100 + 30 * (float)random.NextDouble() - 15, 400 + 100 * (float)random.NextDouble() - 50);
                //tree.Add(tree1);

                //tree1 = new Tree(texturemanager, renderer, "stg1bg", true, 200, 200);
                //tree1.setTop(400);
                //tree1.setPosition(160 + 30 * (float)random.NextDouble() - 15, 400 + 10 * (float)random.NextDouble() - 5);
                //tree.Add(tree1);

            }
            SpeedY = SpeedY;

            backgroundimage.Update(elapsedTime);

            foreach (Tree t in tree)
                t.Update(elapsedTime);

            for (int i = 0; i < tree.Count; i++)
            {
                if (tree[i].Y < -150)
                    ToRemove.Add(tree[i]);
            }
            for (int i = 0; i < ToRemove.Count; i++)
            {
                tree.Remove(ToRemove[i]);
            }
            ToRemove.Clear();
        }