Example #1
0
        public void LoadContent(GraphicsDeviceManager deviceManager,
                                ContentManager contentManager,
                                int windowWidth,
                                int windowHeight)
        {
            var currentDirectoryPath = Directory.GetCurrentDirectory();

            Directory.SetCurrentDirectory("../../../../Content");

            var graphicsDevice = deviceManager.GraphicsDevice;

            // Create a new content manager so we can unload all its content later
            mContentManager = new ContentManager(contentManager.ServiceProvider, contentManager.RootDirectory);


            mSpriteBatch = new SpriteBatch(graphicsDevice);

            var font        = mContentManager.Load <SpriteFont>("Font");
            var modelLoader = new ModelLoader(graphicsDevice);

            var texture2D = UIv2.Menu.CreateTexture2D(graphicsDevice,
                                                      50,
                                                      30,
                                                      pixel => Color.Black);

            mMenu = new UIv2.Menu(graphicsDevice, 0, 0, 100, 4);
            mMenu.NonSolid();
            mLabel = new UIv2.Components.Label(graphicsDevice, 0, 0, 25, 100, "", font, Color.Orange);
            mLabel.AddTo(mMenu);

            var backButton = new UIv2.Components.Button(graphicsDevice, 90, 0, 10, 100, texture2D, "Back", font, Color.White);

            backButton.AddTo(mMenu);

            backButton.AddListener(MouseButtons.Left, InputState.Pressed, () =>
            {
                ScreenManager.Remove(this);
                IsVisible = false;
            });

            mRenderTarget = new RenderTarget(graphicsDevice,
                                             Options.ResolutionWidth,
                                             Options.ResolutionHeight,
                                             1);
            mMasterRenderer = new MasterRenderer(graphicsDevice, mContentManager)
            {
                DebugMode = false
            };

            mCamera = new Camera(farPlane: Options.ViewingDistance,
                                 nearPlane: 0.5f,
                                 thirdPerson: true,
                                 location: new Vector3(0.0f, 0.0f, -110.0f));
            mCameraHandler = new CameraHandler(mCamera, 4.0f, 2.0f, .3f);

            mScene = new Scene();

            var staticObjectsRectangles = new List <CollisionRectangle>();

            mScene.mQuadTree = new QuadTree <Actor>(new Rectangle(-128, -128, 256, 256), 4, 10);

            mScene.mTerrain = new Terrain(mContentManager,
                                          graphicsDevice,
                                          "Terrain/level1 heightmap.png",
                                          "Terrain/techdemoTexture.png");
            mScene.Add(mScene.mTerrain);

            var obstacleMesh = modelLoader.LoadMesh("Mesh/beerbottle2.obj");

            var random = new Random();

            for (var i = 0; i < ObstacleCount; i++)
            {
                var x = (2.0f * (float)random.NextDouble() - 1.0f) * ObstacleRadius;
                var z = (2.0f * (float)random.NextDouble() - 1.0f) * ObstacleRadius;

                var vector = new Vector3(x, 0.0f, z) + new Vector3(20.0f, 0.0f, -100.0f);

                vector.Y = mScene.mTerrain.GetHeight(vector);

                var actor = new Actor(obstacleMesh)
                {
                    ModelMatrix = Matrix.CreateTranslation(vector)
                };

                mScene.Add(actor);
                mScene.mQuadTree.Insert(actor, actor.mBoundingRectangle.GetAxisAlignedRectangle(1));
                staticObjectsRectangles.Add(actor.mBoundingRectangle);
            }

            mScene.mVisibilityGraph = new Pathfinding.VisibilityGraph(staticObjectsRectangles, new Rectangle(-128, -128, 256, 256), 0.0f, false);

            var hutMesh = modelLoader.LoadMesh("Mesh/spawningcabin_scaled 0.015.fbx");

            var lumberjackMesh = modelLoader.LoadMesh("Mesh/lumberjack_minimal_noanimation.obj");

            var doubleAxeKillerMesh = modelLoader.LoadMesh("Mesh/lumberjack_distance_idle.fbx");

            modelLoader.LoadAnimation(doubleAxeKillerMesh, "Mesh/lumberjack_distance_walk.fbx");
            modelLoader.LoadAnimation(doubleAxeKillerMesh, "Mesh/lumberjack_distance_hit.fbx");
            modelLoader.LoadAnimation(doubleAxeKillerMesh, "Mesh/lumberjack_distance_run.fbx");

            var axeMesh = modelLoader.LoadMesh("Mesh/axe.fbx");

            var silverbackMesh = modelLoader.LoadMesh("Mesh/gorilla_idle.fbx");

            modelLoader.LoadAnimation(silverbackMesh, "Mesh/gorilla_walking.fbx");
            modelLoader.LoadAnimation(silverbackMesh, "Mesh/gorilla_smash.fbx");

            var capuchinMesh = modelLoader.LoadMesh("Mesh/kapuziner_idle.fbx");

            modelLoader.LoadAnimation(capuchinMesh, "Mesh/kapuziner_walk.fbx");
            modelLoader.LoadAnimation(capuchinMesh, "Mesh/kapuziner_heal.fbx");

            mSilverback = new Silverback(new Vector3(0.0f, 0.0f, -110.0f), new Vector2(0.0f), silverbackMesh);
            mScene.Add(mSilverback);

            var otherSilverback = new Silverback(new Vector3(0.0f, 0.0f, -110.0f), new Vector2(0.0f), silverbackMesh);

            mSubApe = new Capuchin(capuchinMesh, mScene.mTerrain, otherSilverback, mScene, ref random);
            mScene.Add(mSubApe);

            var hut = new Hut(hutMesh, lumberjackMesh, doubleAxeKillerMesh, axeMesh, mSilverback, mScene, 1000, 100.0f, 110.0f, true);

            mScene.Add(hut);

            mScene.mPostProcessing.mBloom.Activated = false;
            mScene.mPostProcessing.mFxaa.Activated  = false;
            mScene.mSky.Light.mShadow.mActivated    = false;

            mCamera.UpdatePerspective();

            Directory.SetCurrentDirectory(currentDirectoryPath);
        }
Example #2
0
        public void LoadContent(GraphicsDeviceManager deviceManager,
                                ContentManager contentManager,
                                int windowWidth,
                                int windowHeight)
        {
            mScreenWidth  = windowWidth;
            mScreenHeight = windowHeight;

            //Load SoundEffects
            mClickSound = contentManager.Load <SoundEffect>("Audio/click2");

            mGraphicsDevice = deviceManager.GraphicsDevice;

            mPauseScreen = new PauseScreen(this);

            mWinScreen  = new WinScreen(this);
            mLoseScreen = new LoseScreen(this);

            mGameScreen = new GameScreen(mLevelPath);
            ScreenManager.Add(mGameScreen);
            mTotalCunter = mGameScreen.mLevel.mSpawnablePrimatesCount;

            mSpriteBatch = new SpriteBatch(mGraphicsDevice);

            // Load font
            var font          = contentManager.Load <SpriteFont>("Font");
            var subHeaderFont = contentManager.Load <SpriteFont>("SubHeaderFont");

            IsVisible = true;

            // Instantiate a new menu
            mMenuList = new List <UIv2.Menu>();

            mButtonTexture = UIv2.Menu.CreateTexture2D(mGraphicsDevice, 200, 30, pixel => Color.Black);
            var textureTransparent = UIv2.Menu.CreateTexture2D(mGraphicsDevice, 10, 10, pixel => Color.Transparent);

            //Highlighted Button
            mHighlightedButtonTexture = UIv2.Menu.CreateTexture2D(mGraphicsDevice, 200, 30, pixel => Color.Orange);

            var menu = new UIv2.Menu(mGraphicsDevice, 0, 95, 100, 5);

            menu.WithBackground(UIv2.Menu.CreateTexture2D(deviceManager.GraphicsDevice,
                                                          windowWidth,
                                                          200,
                                                          pixel => new Color(0.0f, 0.0f, 0.0f, 0.15f)),
                                0,
                                0,
                                100,
                                100);
            mMenuList.Add(menu);

            mCounterMenu = new UIv2.Menu(mGraphicsDevice, 40, 15, 20, 4);
            mCounterMenu.WithBackground(UIv2.Menu.CreateTexture2D(deviceManager.GraphicsDevice,
                                                                  windowWidth,
                                                                  200,
                                                                  pixel => new Color(0.0f, 0.0f, 0.0f, 0.15f)),
                                        0,
                                        0,
                                        100,
                                        100);
            mCounterMenu.NonSolid();
            mMenuList.Add(mCounterMenu);

            var counterLabel = new UIv2.Components.Label(mGraphicsDevice, 0, 0, 100, 100, "Available apes to spawn: " + mGameScreen.mLevel.mSpawnablePrimatesCount, font, Color.White);

            counterLabel.AddTo(mCounterMenu);

            var pauseButton =
                new UIv2.Components.Button(mGraphicsDevice, 90, 0, 7, 100, mButtonTexture, "Pause", font, Color.White);

            pauseButton.AddTo(menu);
            pauseButton.AddListener(MouseButtons.Left,
                                    InputState.Pressed,
                                    () =>
            {
                SoundManager.AddSound(mClickSound);
                ScreenManager.Add(mPauseScreen);
                mGameScreen.mCameraHandler.Lock();
                IsVisible             = false;
                mWasVisible           = false;
                mGameScreen.IsVisible = false;
            });

            mHPLabel = new UIv2.Components.Label(mGraphicsDevice,
                                                 0,
                                                 0,
                                                 45,
                                                 100,
                                                 "HP: ",
                                                 font,
                                                 Color.White);
            mHPLabel.AddTo(menu);

            mTimeLabel = new UIv2.Components.Label(mGraphicsDevice,
                                                   0,
                                                   0,
                                                   10,
                                                   100,
                                                   "",
                                                   font,
                                                   Color.White);
            mTimeLabel.AddTo(menu);

            var levelLabel = new UIv2.Components.Label(mGraphicsDevice,
                                                       10,
                                                       0,
                                                       7,
                                                       100,
                                                       "Level: Tutorial",
                                                       font,
                                                       Color.White);

            levelLabel.AddTo(menu);
            for (var i = 0; i < 0; i++)
            {
                var morang = new OrangUtan(mGameScreen.mLevel.mOrangUtanMesh,
                                           mGameScreen.mLevel.mTerrain,
                                           mGameScreen.mLevel.mSilverback,
                                           mGameScreen.mLevel,
                                           ref mRandom);
                //morang.mScene = mGameScreen.mLevel;
                mGameScreen.mLevel.Add(morang);
            }

            // Create selection button for Baboon
            mApe1Button =
                new UIv2.Components.Button(mGraphicsDevice, 30, 0, 7, 100, mButtonTexture, "Orang", font, Color.White);
            mApe1Button.AddTo(menu);
            mApe1Button.AddListener(MouseButtons.Left,
                                    InputState.Pressed,
                                    () =>
            {
                SoundManager.AddSound(mClickSound);

                if (mGameScreen.mLevel.mSpawnablePrimatesCount == 0)
                {
                    if (mGameScreen.mLevel.mOrangutanBatch.mActors.Count > 0)
                    {
                        UnHiglightSelectedActorBatch();
                        mActorBatch      = mGameScreen.mLevel.mOrangutanBatch;
                        mHighlitedButton = mApe1Button;
                        HighlightSelectedActorBatch();
                    }
                }
                else if (mGameScreen.mLevel.mSpawnablePrimatesCount > 0)
                {
                    mGameScreen.mLevel.mSpawnablePrimatesCount--;
                    mOrangCounter++;
                    counterLabel.Text = "Available apes to spawn: " + mGameScreen.mLevel.mSpawnablePrimatesCount;

                    var morang = new OrangUtan(mGameScreen.mLevel.mOrangUtanMesh,
                                               mGameScreen.mLevel.mTerrain,
                                               mGameScreen.mLevel.mSilverback,
                                               mGameScreen.mLevel,
                                               ref mRandom);
                    //morang.mScene = mGameScreen.mLevel;
                    mGameScreen.mLevel.Add(morang);
                    LumberChoice.AddApe(2);
                }

                if (mGameScreen.mLevel.mSpawnablePrimatesCount == 0)
                {
                    mCounterMenu.mIsVisible = false;
                    DisableUnusedApeSelectorButtons();
                }
            });

            // Create selection button for Capuchin
            mApe2Button = new UIv2.Components.Button(mGraphicsDevice,
                                                     41,
                                                     0,
                                                     7,
                                                     100,
                                                     mButtonTexture,
                                                     "Capuchin",
                                                     font,
                                                     Color.White);
            mApe2Button.AddTo(menu);
            mApe2Button.AddListener(MouseButtons.Left,
                                    InputState.Pressed,
                                    () =>
            {
                SoundManager.AddSound(mClickSound);

                if (mGameScreen.mLevel.mSpawnablePrimatesCount == 0)
                {
                    if (mGameScreen.mLevel.mCapuchinBatch.mActors.Count > 0)
                    {
                        UnHiglightSelectedActorBatch();
                        mActorBatch      = mGameScreen.mLevel.mCapuchinBatch;
                        mHighlitedButton = mApe2Button;
                        HighlightSelectedActorBatch();
                    }
                }
                else if (mGameScreen.mLevel.mSpawnablePrimatesCount > 0)
                {
                    mCapuchinCounter++;
                    counterLabel.Text = "Available apes to spawn: " + mGameScreen.mLevel.mSpawnablePrimatesCount;
                    mGameScreen.mLevel.mSpawnablePrimatesCount--;
                    var mcapuchin = new Capuchin(mGameScreen.mLevel.mCapuchinMesh,
                                                 mGameScreen.mLevel.mTerrain,
                                                 mGameScreen.mLevel.mSilverback,
                                                 mGameScreen.mLevel,
                                                 ref mRandom);
                    mGameScreen.mLevel.Add(mcapuchin);
                    LumberChoice.AddApe(3);
                }

                if (mGameScreen.mLevel.mSpawnablePrimatesCount == 0)
                {
                    mCounterMenu.mIsVisible = false;
                    DisableUnusedApeSelectorButtons();
                }
            });

            // Create selection button for Chimpaneeze
            mApe3Button =
                new UIv2.Components.Button(mGraphicsDevice, 52, 0, 7, 100, mButtonTexture, "Chimp", font, Color.White);
            mApe3Button.AddTo(menu);

            mApe3Button.AddListener(MouseButtons.Left,
                                    InputState.Pressed,
                                    () =>
            {
                SoundManager.AddSound(mClickSound);

                if (mGameScreen.mLevel.mSpawnablePrimatesCount == 0)
                {
                    if (mGameScreen.mLevel.mChimpanezzeBatch.mActors.Count > 0)
                    {
                        UnHiglightSelectedActorBatch();
                        mActorBatch      = mGameScreen.mLevel.mChimpanezzeBatch;
                        mHighlitedButton = mApe3Button;
                        HighlightSelectedActorBatch();
                    }
                }
                else if (mGameScreen.mLevel.mSpawnablePrimatesCount > 0)
                {
                    mChimpCounter++;
                    mGameScreen.mLevel.mSpawnablePrimatesCount--;
                    counterLabel.Text = "Available apes to spawn: " + mGameScreen.mLevel.mSpawnablePrimatesCount;
                    var mchimpanezee  = new Chimpanezee(mGameScreen.mLevel.mChimpanezzeMesh,
                                                        mGameScreen.mLevel.mTerrain,
                                                        mGameScreen.mLevel.mSilverback,
                                                        mGameScreen.mLevel,
                                                        ref mRandom);
                    mGameScreen.mLevel.Add(mchimpanezee);
                    LumberChoice.AddApe(1);
                }

                if (mGameScreen.mLevel.mSpawnablePrimatesCount == 0)
                {
                    mCounterMenu.mIsVisible = false;
                    DisableUnusedApeSelectorButtons();
                }
            }
                                    );

            // Create selection button for Gibbon
            mApe4Button =
                new UIv2.Components.Button(mGraphicsDevice, 63, 0, 7, 100, mButtonTexture, "Gibbon", font, Color.White);
            mApe4Button.AddTo(menu);
            mApe4Button.AddListener(MouseButtons.Left,
                                    InputState.Pressed,
                                    () =>
            {
                SoundManager.AddSound(mClickSound);

                if (mGameScreen.mLevel.mSpawnablePrimatesCount == 0)
                {
                    if (mGameScreen.mLevel.mGibbonBatch.mActors.Count > 0)
                    {
                        UnHiglightSelectedActorBatch();
                        mActorBatch      = mGameScreen.mLevel.mGibbonBatch;
                        mHighlitedButton = mApe4Button;
                        HighlightSelectedActorBatch();
                    }
                }
                else if (mGameScreen.mLevel.mSpawnablePrimatesCount > 0)
                {
                    mGibbonCounter++;
                    mGameScreen.mLevel.mSpawnablePrimatesCount--;
                    counterLabel.Text = "Available apes to spawn: " + mGameScreen.mLevel.mSpawnablePrimatesCount;

                    var mgibbon = new Gibbon(mGameScreen.mLevel.mGibbonMesh,
                                             mGameScreen.mLevel.mTerrain,
                                             mGameScreen.mLevel.mSilverback,
                                             mGameScreen.mLevel,
                                             ref mRandom);
                    mGameScreen.mLevel.Add(mgibbon);
                    LumberChoice.AddApe(4);
                }

                if (mGameScreen.mLevel.mSpawnablePrimatesCount == 0)
                {
                    mCounterMenu.mIsVisible = false;
                    DisableUnusedApeSelectorButtons();
                }
            });

            // Display the level text before the level starts
            if (mGameScreen.mLevel.mLevelStory != null)
            {
                mGameScreen.mCameraHandler.Lock();
                var textMenu = new UIv2.Menu(mGraphicsDevice, 5, 5, 90, 90);
                textMenu.WithBackground(UIv2.Menu.CreateTexture2D(deviceManager.GraphicsDevice, 50, 30, pixel => new Color(0.0f, 0.0f, 0.0f, 0.15f)), 5, 5, 90, 90);
                var heading = new UIv2.Components.Label(mGraphicsDevice, 5, 5, 90, 15, mGameScreen.mLevel.mLevelTitle, subHeaderFont, Color.DarkSlateGray);
                heading.FontType = FontManager.FontType.Subheading;
                heading.AddTo(textMenu);
                var textLabel = new UIv2.Components.Label(mGraphicsDevice, 25, 28, 50, 35, mGameScreen.mLevel.mLevelStory, font, Color.White);
                textLabel.DisableAutobreak();
                textLabel.AddTo(textMenu);
                mContinueLabel = new UIv2.Components.Label(mGraphicsDevice, 25, 80, 50, 10, "Press the left mouse button to continue", font, Color.White);
                mContinueLabel.AddTo(textMenu);
                var textButton = new UIv2.Components.Button(mGraphicsDevice, 0, 0, 100, 100, textureTransparent, "", font, Color.White);
                textButton.AddTo(textMenu);
                textButton.AddListener(MouseButtons.Left,
                                       InputState.Pressed,
                                       () =>
                {
                    menu.mIsVisible         = true;
                    mCounterMenu.mIsVisible = true;
                    textMenu.mIsVisible     = false;
                    mGameScreen.mCameraHandler.Unlock();
                });
                mMenuList.Add(textMenu);
                menu.mIsVisible         = false;
                mCounterMenu.mIsVisible = false;
            }

            mMenuList.Add(menu);
        }