Пример #1
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            startScreen     = Content.Load <Texture2D>("startPage");
            howToPlayScreen = Content.Load <Texture2D>("howtoplay");

            letterFont = Content.Load <SpriteFont>("LetterFont");

            cartSound         = Content.Load <SoundEffect>("WheelingACart");
            cartSoundInstance = cartSound.CreateInstance();

            cartSqueak         = Content.Load <SoundEffect>("Squeak");
            cartSqueakInstance = cartSqueak.CreateInstance();

            gruntSound     = Content.Load <SoundEffect>("grunt");
            jumpGruntSound = Content.Load <SoundEffect>("jumpGrunt");

            metalDragSound    = Content.Load <SoundEffect>("metal_drag");
            metalDragInstance = metalDragSound.CreateInstance();

            crowdSound = Content.Load <SoundEffect>("crowd_noises");

            introJazzSong           = Content.Load <Song>("Walking Sax2");
            jazzSong                = Content.Load <Song>("Jazz club1 130");
            bluesJazzSong           = Content.Load <Song>("bluesJazzSong");
            MediaPlayer.IsRepeating = true;

            cardboardBox = Content.Load <SoundEffect>("cardboardBox");

            models["floor"]         = Content.Load <Model>("floor");
            models["walls"]         = Content.Load <Model>("walls");
            models["ceiling"]       = Content.Load <Model>("ceiling");
            models["cerealBox"]     = Content.Load <Model>("cerealBox");
            models["cerealBoxBlue"] = Content.Load <Model>("cerealBoxBlue");
            models["cart"]          = Content.Load <Model>("cart");
            models["shelf"]         = Content.Load <Model>("shelf");
            models["Larm"]          = Content.Load <Model>("Larm");
            models["Rarm"]          = Content.Load <Model>("Rarm");

            Texture2D crowd_woman_tex = Content.Load <Texture2D>("personBillboard_woman");
            Texture2D crowd_man_tex   = Content.Load <Texture2D>("personBillboard_man");

            Random random = new Random();

            SoundEmitter crowdEmitter;

            //back
            for (int j = 0; j < 3; j++)
            {
                float offset = 0f;
                if (j % 2 == 0)
                {
                    offset = 1f;
                }
                for (int i = 0; i < 10 + offset; i++)
                {
                    crowdEmitter = new SoundEmitter(crowdSound, new Vector3(-10 - offset + i * 2.234f, 4 - 2 * j, -15 + j * 2.2345f));
                    crowdEmitter.soundEffectInstance.IsLooped = true;
                    crowdNoises.Add(crowdEmitter);

                    if (random.Next() % 2 == 1)
                    {
                        crowd.Add(new Billboard(crowd_woman_tex, GraphicsDevice, 1, 2, 2, new Vector3(-10 - offset + i * 2.234f, 4 - 2 * j, -15 + j * 2.2345f), Quaternion.CreateFromAxisAngle(Vector3.Up, MathHelper.Pi), 5));
                    }
                    else
                    {
                        crowd.Add(new Billboard(crowd_man_tex, GraphicsDevice, 1, 2, 2, new Vector3(-10 - offset + i * 2.234f, 4 - 2 * j, -15 + j * 2.2345f), Quaternion.CreateFromAxisAngle(Vector3.Up, MathHelper.Pi), 5));
                    }
                }
            }

            // left
            for (int j = 0; j < 3; j++)
            {
                float offset = 0f;
                if (j % 2 == 0)
                {
                    offset = 1f;
                }
                for (int i = 0; i < 15 + offset; i++)
                {
                    crowdEmitter = new SoundEmitter(crowdSound, new Vector3(20 - j * 2.234f, 4 - 2 * j, -3 - offset + i * 2.2345f));
                    crowdEmitter.soundEffectInstance.IsLooped = true;
                    crowdNoises.Add(crowdEmitter);
                    if (random.Next() % 2 == 1)
                    {
                        crowd.Add(new Billboard(crowd_woman_tex, GraphicsDevice, 1, 2, 2, new Vector3(20 - j * 2.234f, 4 - 2 * j, -3 - offset + i * 2.2345f), Quaternion.CreateFromAxisAngle(Vector3.Up, MathHelper.PiOver2), 5));
                    }
                    else
                    {
                        crowd.Add(new Billboard(crowd_man_tex, GraphicsDevice, 1, 2, 2, new Vector3(20 - j * 2.234f, 4 - 2 * j, -3 - offset + i * 2.2345f), Quaternion.CreateFromAxisAngle(Vector3.Up, MathHelper.PiOver2), 5));
                    }
                }
            }

            // right
            for (int j = 0; j < 3; j++)
            {
                float offset = 0f;
                if (j % 2 == 0)
                {
                    offset = 1f;
                }
                for (int i = 0; i < 15 + offset; i++)
                {
                    crowdEmitter = new SoundEmitter(crowdSound, new Vector3(-20 + j * 2.234f, 4 - 2 * j, -3 - offset + i * 2.2345f));
                    crowdEmitter.soundEffectInstance.IsLooped = true;
                    crowdNoises.Add(crowdEmitter);
                    if (random.Next() % 2 == 1)
                    {
                        crowd.Add(new Billboard(crowd_woman_tex, GraphicsDevice, 1, 2, 2, new Vector3(-20 + j * 2.234f, 4 - 2 * j, -3 - offset + i * 2.2345f), Quaternion.CreateFromAxisAngle(Vector3.Up, -MathHelper.PiOver2), 5));
                    }
                    else
                    {
                        crowd.Add(new Billboard(crowd_man_tex, GraphicsDevice, 1, 2, 2, new Vector3(-20 + j * 2.234f, 4 - 2 * j, -3 - offset + i * 2.2345f), Quaternion.CreateFromAxisAngle(Vector3.Up, -MathHelper.PiOver2), 5));
                    }
                }
            }

            // front
            for (int j = 0; j < 3; j++)
            {
                float offset = 0f;
                if (j % 2 == 0)
                {
                    offset = 1f;
                }
                for (int i = 0; i < 10 + offset; i++)
                {
                    crowdEmitter = new SoundEmitter(crowdSound, new Vector3(-10 - offset + i * 2.234f, 4 - 2 * j, 40 - j * 2.2345f));
                    crowdEmitter.soundEffectInstance.IsLooped = true;
                    crowdNoises.Add(crowdEmitter);

                    if (random.Next() % 2 == 1)
                    {
                        crowd.Add(new Billboard(crowd_woman_tex, GraphicsDevice, 1, 2, 2, new Vector3(-10 - offset + i * 2.234f, 4 - 2 * j, 40 - j * 2.2345f), Quaternion.Identity, 5));
                    }
                    else
                    {
                        crowd.Add(new Billboard(crowd_man_tex, GraphicsDevice, 1, 2, 2, new Vector3(-10 - offset + i * 2.234f, 4 - 2 * j, 40 - j * 2.2345f), Quaternion.Identity, 5));
                    }
                }
            }

            // Add game specific objectss
            floor           = new GameObject(new Vector3(0, -1f, 0), Quaternion.Identity, 1f, models["floor"]);
            floor.Immovable = true;

            walls = new GameObject(new Vector3(0, 0, 0), Quaternion.Identity, .5f, models["walls"]);

            ceiling = new GameObject[6 * 6];
            for (int i = 0; i < 6; i++)
            {
                for (int j = 0; j < 6; j++)
                {
                    ceiling[6 * i + j] = new GameObject(new Vector3(-39 + i * 14, 10, -28 + j * 15), Quaternion.Identity, .01f, models["ceiling"]);
                }
            }


            cart = new GameObject(new Vector3(0, .1f, 1), Quaternion.Identity, .01f, models["cart"]);

            //cart.Collider.EnableBounce = false;
            cart.Collider.EnableRotate       = false;
            cart.Collider.UseMeshBoundingBox = false;
            cart.Collider.BBGroup            = new BoundingBox[] { // construct collision boxes for cart
                new BoundingBox(new Vector3(-2f, 0, -1), new Vector3(2, .8f, 6.5f)),
                new BoundingBox(new Vector3(-2f, .8f, -1), new Vector3(-1.5f, 3f, 6.5f)),
                new BoundingBox(new Vector3(1.5f, .8f, -1), new Vector3(2f, 3f, 6.5f)),
                new BoundingBox(new Vector3(-1.5f, .8f, -1), new Vector3(1.5f, 3f, -.5f)),
                new BoundingBox(new Vector3(-1.5f, .8f, 5.5f), new Vector3(1.5f, 3f, 6.5f))
            };

            //arms
            larm = new GameObject(
                new Vector3(0, 0, 0), LArmAnimations.slerp(0),
                .01f,
                models["Larm"]);
            rarm = new GameObject(
                new Vector3(0, 0, 0), RArmAnimations.slerp(0),
                .01f,
                models["Rarm"]);

            larmAnimator = new LArmAnimations(larm);
            rarmAnimator = new RArmAnimations(rarm);

            Random r = new Random();

            // build shelves
            for (int shelfno = 0; shelfno < 4; shelfno++)
            {
                //add shelf
                GameObject shelf = new GameObject(new Vector3(5, 2.5f, 10 * shelfno), Quaternion.CreateFromAxisAngle(Vector3.Up, MathHelper.Pi), 0.01f, models["shelf"]);
                shelf.Collider.UseMeshBoundingBox = false;
                shelf.Collider.EnableRotate       = false;
                BoundingBox[] shelfBBs = new BoundingBox[] {
                    new BoundingBox(new Vector3(-1, -2.55f, -2.7f), new Vector3(1, -2.35f, 2.8f)),
                    new BoundingBox(new Vector3(-1, -1.2f, -2.7f), new Vector3(1, -.95f, 2.8f)),
                    new BoundingBox(new Vector3(-1, 0f, -2.7f), new Vector3(1, .3f, 2.8f)),
                    new BoundingBox(new Vector3(-1, 1.3f, -2.7f), new Vector3(1, 1.5f, 2.8f)),
                    new BoundingBox(new Vector3(.2f, -3f, -2.7f), new Vector3(.9f, 2.2f, 2.8f)),
                };
                shelf.Collider.BBGroup = shelfBBs;
                shelves.Add(shelf);

                GameObject shelf2 = new GameObject(new Vector3(-5, 2.5f, 10 * shelfno), Quaternion.Identity, 0.01f, models["shelf"]);
                shelf2.Collider.UseMeshBoundingBox = false;
                shelf2.Collider.EnableRotate       = false;
                BoundingBox[] shelf2BBs = new BoundingBox[] {
                    new BoundingBox(new Vector3(-1, -2.55f, -2.7f), new Vector3(1, -2.35f, 2.8f)),
                    new BoundingBox(new Vector3(-1, -1.2f, -2.7f), new Vector3(1, -.95f, 2.8f)),
                    new BoundingBox(new Vector3(-1, 0f, -2.7f), new Vector3(1, .3f, 2.8f)),
                    new BoundingBox(new Vector3(-1, 1.3f, -2.7f), new Vector3(1, 1.5f, 2.8f)),
                    new BoundingBox(new Vector3(-.2f, -3f, -2.7f), new Vector3(-.9f, 2.2f, 2.8f)),
                };
                shelf2.Collider.BBGroup = shelf2BBs;
                shelves.Add(shelf2);

                for (int shelfLevels = 0; shelfLevels < 4; shelfLevels++)
                {
                    BoundingBox s = shelfBBs[shelfLevels];
                    //add boxes on shelf
                    for (int col = 0; col < 4; col++)
                    {
                        Model boxModel;
                        if (r.Next() % 10 == 0)
                        {
                            boxModel = models["cerealBoxBlue"];
                        }
                        else
                        {
                            boxModel = models["cerealBox"];
                        }

                        GameObject box = new GameObject(
                            shelf.Pos +
                            new Vector3(s.Min.X, s.Max.Y, s.Min.Z) +
                            new Vector3(.1f, 0, col * 1.5f + .5f),
                            Quaternion.Identity, 0.01f, boxModel
                            );
                        box.Collider.EnableRotate = false;
                        gameObjects.Add(box);


                        GameObject box2 = new GameObject(
                            shelf2.Pos +
                            new Vector3(s.Max.X, s.Max.Y, s.Min.Z) +
                            new Vector3(-.1f, .1f, col * 1.5f + .5f),
                            Quaternion.Identity, 0.01f, boxModel
                            );
                        box2.Collider.EnableRotate = false;
                        gameObjects.Add(box2);
                    }
                }
            }

            /*
             * for (int i = 0; i < 10; i++)
             * {
             *  GameObject shelf = new GameObject(new Vector3(-10, 2.5f, 10 * i), Quaternion.Identity, 0.01f, models["shelf"]);
             *  shelf.Immovable = true;
             *
             *  shelves.Add(shelf);
             * }*/

            // generic games
            cam          = new Camera(new Vector3(0, 0, 0), MathHelper.Pi);
            lamp         = new Lamp(new Vector3(30, 30, 30));
            windowCenter = new Point(graphics.PreferredBackBufferWidth / 2, graphics.PreferredBackBufferHeight / 2);
        }