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); }
public Level(ContentManager contentManager, SoundManager soundManager, GraphicsDevice device, bool editMode) : base() { mContentManager = contentManager; mSoundManager = soundManager; mDevice = device; mEditMode = editMode; var currentDirectoryPath = Directory.GetCurrentDirectory(); if (!currentDirectoryPath.EndsWith("Content") && !currentDirectoryPath.EndsWith("Content/") && !currentDirectoryPath.EndsWith("Content\\")) { Directory.SetCurrentDirectory("../../../../Content"); } mModelLoader = new ModelLoader(device); mQuadTree = new QuadTree <Actor>(new Rectangle(-128, -128, 256, 256), 4, 7); // Load silverback mSilverback = new Silverback(new Vector3(0.0f), new Vector2(0.0f), mModelLoader.LoadMesh("Mesh/gorilla_idle.fbx")); mSilverback.mQuadTree = mQuadTree; mHutMesh = mModelLoader.LoadMesh("Mesh/spawningcabin_scaled 0.015.fbx"); mHuts = new List <Hut>(); Hut.mAmount = 0; mGlobalSoundSourceBuffer = new AudioBuffer("Audio/ForestSoundMono.wav"); mGlobalSoundSource = new AudioSource(mGlobalSoundSourceBuffer); mGlobalSoundSource.Relative = true; mSoundManager.AddSound(mGlobalSoundSource); mInitialSilverbackLocation = new Vector3(0.0f); if (!mEditMode) { mSilverback.Actor.mAnimator.SetStandardAnimation("idle"); mModelLoader.LoadAnimation(mSilverback.Actor.mMesh, "Mesh/gorilla_walking.fbx"); mModelLoader.LoadAnimation(mSilverback.Actor.mMesh, "Mesh/gorilla_smash.fbx"); Add(mSilverback); mQuadTree.Insert(mSilverback.Actor, mSilverback.Actor.mBoundingRectangle.GetAxisAlignedRectangle(1)); // Load all the other meshes // Load Lumberjack mesh mLumberjackMesh = mModelLoader.LoadMesh("Mesh/lumberjack_idle.fbx"); mModelLoader.LoadAnimation(mLumberjackMesh, "Mesh/lumberjack_walk.fbx"); mModelLoader.LoadAnimation(mLumberjackMesh, "Mesh/lumberjack_hit.fbx"); mModelLoader.LoadAnimation(mLumberjackMesh, "Mesh/lumberjack_run.fbx"); mLumberjacks = new ActorBatch(mLumberjackMesh, true); mActorBatches.Add(mLumberjacks); // Load DoubleAxeKiller mesh mDoubleAxeKillerMesh = mModelLoader.LoadMesh("Mesh/lumberjack_distance_idle.fbx"); mModelLoader.LoadAnimation(mDoubleAxeKillerMesh, "Mesh/lumberjack_distance_walk.fbx"); mModelLoader.LoadAnimation(mDoubleAxeKillerMesh, "Mesh/lumberjack_distance_hit.fbx"); mModelLoader.LoadAnimation(mDoubleAxeKillerMesh, "Mesh/lumberjack_distance_run.fbx"); mDoubleAxeKillers = new ActorBatch(mDoubleAxeKillerMesh, true); mActorBatches.Add(mDoubleAxeKillers); // Load Baboon Mesh mBaboonMesh = mModelLoader.LoadMesh("Mesh/gibbon_idle.fbx"); mModelLoader.LoadAnimation(mBaboonMesh, "Mesh/gibbon_walk.fbx"); mModelLoader.LoadAnimation(mBaboonMesh, "Mesh/gibbon_singing.fbx"); mBaboonBatch = new ActorBatch(mBaboonMesh, true); mActorBatches.Add(mBaboonBatch); // Load Capuchin Mesh mCapuchinMesh = mModelLoader.LoadMesh("Mesh/kapuziner_idle.fbx"); mModelLoader.LoadAnimation(mCapuchinMesh, "Mesh/kapuziner_walk.fbx"); mModelLoader.LoadAnimation(mCapuchinMesh, "Mesh/kapuziner_heal.fbx"); mCapuchinBatch = new ActorBatch(mCapuchinMesh, true); mActorBatches.Add(mCapuchinBatch); // Load Chimpanezze Mesh mChimpanezzeMesh = mModelLoader.LoadMesh("Mesh/chimp_idle.fbx"); mModelLoader.LoadAnimation(mChimpanezzeMesh, "Mesh/chimp_walk.fbx"); mModelLoader.LoadAnimation(mChimpanezzeMesh, "Mesh/chimp_attack.fbx"); mChimpanezzeBatch = new ActorBatch(mChimpanezzeMesh, true); mActorBatches.Add(mChimpanezzeBatch); // Load Gibbon Mesh mGibbonMesh = mModelLoader.LoadMesh("Mesh/Gibbon_idle.fbx"); mModelLoader.LoadAnimation(mGibbonMesh, "Mesh/Gibbon_walk.fbx"); mModelLoader.LoadAnimation(mGibbonMesh, "Mesh/Gibbon_singing.fbx"); mGibbonBatch = new ActorBatch(mGibbonMesh, true); mActorBatches.Add(mGibbonBatch); // Load Orang Utan Mesh mOrangUtanMesh = mModelLoader.LoadMesh("Mesh/orangutan_idle.fbx"); mModelLoader.LoadAnimation(mOrangUtanMesh, "Mesh/orangutan_walk.fbx"); mModelLoader.LoadAnimation(mOrangUtanMesh, "Mesh/orangutan_throw.fbx"); mOrangutanBatch = new ActorBatch(mOrangUtanMesh, true); mActorBatches.Add(mOrangutanBatch); mAxeMesh = mModelLoader.LoadMesh("Mesh/axe.fbx"); } mPostProcessing.mBloom.Activated = Options.Bloom; mPostProcessing.mBloom.mPasses = Options.BloomPasses; mPostProcessing.mFxaa.Activated = Options.Fxaa; mSky.Light.mShadow.mActivated = Options.Shadows; mSky.Light.mShadow.mDistance = Options.ShadowDistance; mSky.Light.mShadow.mNumSamples = Options.ShadowSamples; mSky.Light.mShadow.mBias = Options.ShadowBias; Directory.SetCurrentDirectory(currentDirectoryPath); }