public override void LoadContent()
        {
            if (content == null)
            {
                content = new ContentManager(ScreenManager.Game.Services, "Content");
            }

            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GameScreenManager.GraphicsDevice);
            background  = content.Load <Texture2D>("back");

            // Setting up render target
            PresentationParameters pp = ScreenManager.GraphicsDevice.PresentationParameters;

            renderTarget = new RenderTarget2D(ScreenManager.GraphicsDevice, pp.BackBufferWidth, pp.BackBufferHeight, true, SurfaceFormat.Color, DepthFormat.Depth24);
            postProcess  = content.Load <Effect>("PostProcess");
            postProcess.Parameters["darkenFactor"].SetValue(1f);

            virtualTerrain               = content.Load <Effect>("virtualTerrain");
            CustomTerrainRenderer.wire   = content.Load <Texture2D>("wire");
            CustomTerrainRenderer.effect = virtualTerrain;

            terrainRenderer = new CustomTerrainRenderer(Vector2.One * 200);

            terrainObject       = GameObject3d.Initialize();
            terrainRenderer.obj = terrainObject;

            terrainObject.material = terrainRenderer;

            //SET CAM
            camera = new Camera();
            camera.Transform.LocalPosition += new Vector3(100, 0, 10);
            camera.Transform.Rotate(Vector3.Up, (float)Math.PI);
            Vector3 pos = camera.Transform.Position;

            pos.Y = 2 + terrainRenderer.GetAltitude(camera.Transform.Position);
            camera.Transform.LocalPosition = pos;
            camera.NearPlane = 0.001f;

            // Setup skybox
            camera.skybox = new Skybox {
                skyboxModel = content.Load <Model>("Box"), skyboxTexture = background
            };
            Skybox.shader = content.Load <Effect>("skybox");

            //SET HOOP
            hoopLogic.player   = camera;
            hoopObject.lastPos = camera.Transform.LocalPosition + new Vector3(0, 2, 100);
            hoopObject.Initialize();

            //sfx
            staticNoise        = content.Load <Song>("static");
            MediaPlayer.Volume = 0.2f;

            foreach (GameObject3d gameObject in GameObject3d.activeGameObjects)
            {
                gameObject.Start();
            }
            GameObject.gameStarted = true;
        }
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            StandardLightingMaterial.effect = Content.Load <Effect>("Standard");
            text = new SpriteBatch(GraphicsDevice);
            // *** ScreenManager ***********************
            ScreenManager.Setup(false, 1080, 720);
            camera.Transform.LocalPosition = Vector3.Up * 20;
            camera.Transform.Rotate(camera.Transform.Left, (float)Math.PI / 2);
            camera.FieldOfView = 2.6f;

            mapCam.orthographic            = true;
            mapCam.Transform.LocalPosition = Vector3.Up * 100;
            mapCam.Transform.Rotate(mapCam.Transform.Left, (float)Math.PI / 2);

            mapCam.Size     = Vector2.One * 100;
            mapCam.Position = new Vector2(0.9f, 0.01f);
            //***************************************

            // F*****g around
            backgrounds = new SpriteBatch(GraphicsDevice);
            background  = Content.Load <Texture2D>("DOGGIE");
            offset      = Content.Load <Effect>("offset");

            Enemy.enemyModel = Content.Load <Model>("sphere");

            terrain = new TerrainRenderer(
                Content.Load <Texture2D>("HeightMap"),
                Vector2.One * 100, Vector2.One * 200);

            terrain.NormalMap = Content.Load <Texture2D>("NormalMap");

            terrainObject = GameObject3d.Initialize();

            terrain.ourObject = terrainObject;

            terrainObject.material              = terrain;
            terrainObject.transform.LocalScale *= new Vector3(1, 5, 1);

            font = Content.Load <SpriteFont>("font");

            TerrainRenderer.effect = Content.Load <Effect>("TerrainShader");

            Enemy.terrain = terrain;

            // Create Player
            playerObject = GameObject3d.Initialize();
            playerObject.addBehavior(new PlayerBehav(terrain));
            playerObject.mesh = Content.Load <Model>("sphere");

            Enemy.createEnemy(playerObject);
            Enemy.createEnemy(playerObject);
            Enemy.createEnemy(playerObject);

            foreach (GameObject3d gameObject in GameObject3d.activeGameObjects)
            {
                gameObject.Start();
            }
            GameObject.gameStarted = true;
        }
        public override void Update(GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen)
        {
            InputManager.Update();
            Time.Update(gameTime);

            GameObject3d.UpdateObjects();

            while (terrainRenderer.lastRowDepth < camera.Transform.Position.Z - 5)
            {
                terrainRenderer.updateNormals(Math.Abs(terrainRenderer.lastRowDepth - 5), Vector3.Up);
                terrainRenderer.updateDepth(terrainRenderer.lastRowDepth);
                terrainRenderer.updateNormals(terrainRenderer.lastRowDepth + 1, Vector3.Down);
            }

            terrainRenderer.songPos = (float)waveOut.GetPosition() / (float)reader.Length;
            if (terrainRenderer.songPos < 1)
            {
                terrainRenderer.avgE = 1 / (float)(avgE[(int)(avgE.Length * terrainRenderer.songPos)] - 100);
            }

            if (!songStarted && terrainRenderer.lastRowDepth > 100)
            {
                songStarted = true;
                newHoop();
                waveOut.Play();
            }

            if (InputManager.IsKeyPressed(Keys.T))
            {
                postToggle = !postToggle;
            }
            if (InputManager.IsKeyPressed(Keys.N))
            {
                noisyToggle = !noisyToggle;
            }
            if (InputManager.IsKeyPressed(Keys.F))
            {
                GameScreenManager.graphics.ToggleFullScreen();
            }

            if (InputManager.IsKeyDown(Keys.Up))
            {
                camera.FieldOfView += 0.01f;
            }
            if (InputManager.IsKeyDown(Keys.Down))
            {
                camera.FieldOfView -= 0.01f;
            }

            if (!noisyToggle)
            {
                updateCam();
            }

            checkSongEnding();
            //pos.Y += terrainRenderer.avgE;
            //terrainRenderer.totalFrames = mp3Frames.Count();
        }
示例#4
0
        protected override void LoadContent()
        {
            spriteBatch = new SpriteBatch(GameScreenManager.GraphicsDevice);

            // F*****g around
            backgrounds = new SpriteBatch(GraphicsDevice);
            background  = Content.Load <Texture2D>("DOGGIE");
            offset      = Content.Load <Effect>("offset");


            // *** Lab 8 Item ***********************
            GameScreenManager.Setup(false, 1080, 720);
            //***************************************

            particleManager                 = new ParticleManager(GraphicsDevice, 100);
            particleEffect                  = Content.Load <Effect>("ParticleShader");
            PlayerBehav.bulletMesh          = Content.Load <Model>("Sphere");
            AsteroidObject.AstroidModel     = Content.Load <Model>("Sphere");
            AsteroidObject.tex              = Content.Load <Texture2D>("lunaTexture");
            StandardLightingMaterial.effect = Content.Load <Effect>("StandardShading");
            particleTex = Content.Load <Texture2D>("fire");
            font        = Content.Load <SpriteFont>("font");

            Player = GameObject3d.Initialize();
            Player.transform.LocalScale *= 0.01f;
            Player.transform.Rotate(Vector3.Left, -(float)Math.PI / 2);
            PlayerBehav.bulletMesh = Content.Load <Model>("Sphere");
            Player.addBehavior(new PlayerBehav());
            Rigidbody r = new Rigidbody();

            Player.addBehavior(r);
            SphereCollider s = new SphereCollider();

            Player.addBehavior(s);
            Player.mesh = Content.Load <Model>("PlayerModel");

            // Sound shit
            gunSound      = Content.Load <SoundEffect>("Gun");
            soundInstance = gunSound.CreateInstance();
            AudioListener listener = new AudioListener();

            listener.Position = camera.Transform.Position;
            listener.Forward  = camera.Transform.Forward;
            AudioEmitter emitter = new AudioEmitter();

            emitter.Position = Vector3.Zero;
            soundInstance.Apply3D(listener, emitter);

            foreach (GameObject3d gameObject in GameObject3d.activeGameObjects)
            {
                gameObject.Start();
            }
            GameObject.gameStarted = true;
        }
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            ScreenManager.Setup(false, 1080, 720);
            // Create a new SpriteBatch, which can be used to draw textures.
            backgrounds = new SpriteBatch(GraphicsDevice);
            text        = new SpriteBatch(GraphicsDevice);

            // Load Font
            font = Content.Load <SpriteFont>("font");

            // Load shaders
            SpeedAndCollideEffect.effect         = Content.Load <Effect>("SpeedEffectShader");
            SpeedAndCollideEffect.disperseSample = Content.Load <Texture2D>("noiseTexture");
            offset     = Content.Load <Effect>("offset");
            background = Content.Load <Texture2D>("DOGGIE");

            // Load the models
            sphere = Content.Load <Model>("Sphere");
            foreach (ModelMesh mesh in sphere.Meshes)
            {
                foreach (BasicEffect e in mesh.Effects)
                {
                    e.EnableDefaultLighting();
                }
            }

            // Misc Setup
            camera.Transform.LocalPosition = new Vector3(0, 0, 20);

            random = new Random();

            BoxCollider boxCollider;

            boxCollider      = new BoxCollider();
            boxCollider.Size = 10;

            GameObject3d b = GameObject3d.Initialize();

            b.drawable = false;
            b.addBehavior(boxCollider);

            for (int i = 0; i < 2; i++)
            {
                makeThatSphere();
            }

            //init
            foreach (GameObject3d gameObject in GameObject3d.activeGameObjects)
            {
                gameObject.Start();
            }
            GameObject.gameStarted = true;
        }
        protected override void Update(GameTime gameTime)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                Exit();
            }

            InputManager.Update();
            Time.Update(gameTime);

            if (InputManager.IsKeyPressed(Keys.R))
            {
                Enemy.createEnemy(playerObject);
            }

            GameObject3d.UpdateObjects();
            base.Update(gameTime);
        }
示例#7
0
        // Static method for creating new enemies
        public static GameObject3d createEnemy(GameObject3d player)
        {
            GameObject3d g = GameObject3d.Initialize();
            Enemy        e = new Enemy(player);

            g.addBehavior(e);
            g.mesh     = enemyModel;
            g.material = new StandardLightingMaterial();
            (g.material as StandardLightingMaterial).diffuseColor = Vector3.Up;

            //SETUPSEARCH
            int size = 100;

            e.search = new AStarSearch(size, size); // size of grid

            // use heightmap
            foreach (AStarNode node in e.search.Nodes)
            {
                node.Passable = (terrain.GetAltitude(node.Position) < 0.5);
            }
            //******

            GameObject3d child = GameObject3d.Initialize();

            child.transform.LocalPosition  = g.transform.LocalPosition;
            child.transform.LocalPosition += Vector3.Forward;
            child.transform.LocalScale    *= 0.5f;
            child.transform.Parent         = g.transform;

            e.heldObject = child;

            child.mesh = enemyModel;
            StandardLightingMaterial s = new StandardLightingMaterial();

            s.ambientColor = Vector3.Down;
            child.material = s;

            g.transform.LocalScale = Vector3.One * 2;
            e.reposition();

            return(g);
        }
示例#8
0
        protected override void Update(GameTime gameTime)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                Exit();
            }

            InputManager.Update();
            Time.Update(gameTime);
            Collider.Update(gameTime);
            particleManager.Update();

            GameObject3d.UpdateObjects();

            if (InputManager.IsKeyPressed(Keys.R))
            {
                ResetAsteroids();
            }

            base.Update(gameTime);
        }
        private void makeThatSphere()
        {
            Transform transform = new Transform();

            transform.LocalPosition += new Vector3((float)random.NextDouble() * 5, (float)random.NextDouble() * 5, (float)random.NextDouble() * 5); //avoid overlapping each sphere

            Rigidbody rigidbody = new Rigidbody();

            rigidbody.Mass = 1;

            Vector3 direction = new Vector3(
                (float)random.NextDouble(), (float)random.NextDouble(),
                (float)random.NextDouble());

            direction.Normalize();
            rigidbody.Velocity = direction * ((float)random.NextDouble() * 5 + 5);
            rigidbody.Mass     = 1f + (float)random.NextDouble();

            SphereCollider sphereCollider = new SphereCollider();

            sphereCollider.Radius = 1 * transform.LocalScale.Y;

            SpeedColorEffectController effectControl = new SpeedColorEffectController();

            GameObject3d g = GameObject3d.Initialize();

            g.transform = transform;
            g.mesh      = sphere;
            g.material  = new SpeedAndCollideEffect();

            g.addBehavior(rigidbody);
            g.addBehavior(sphereCollider);
            g.addBehavior(effectControl);

            if (GameObject.gameStarted)
            {
                g.Start();
            }
        }
示例#10
0
 public Enemy(GameObject3d player) => playerObject = player;
        /// <summary>
        /// Allows the game to run logic such as updating the world,
        /// checking for collisions, gathering input, and playing audio.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        protected override void Update(GameTime gameTime)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                Exit();
            }

            InputManager.Update();
            Time.Update(gameTime);
            Collider.Update(gameTime);

            GameObject3d.UpdateObjects();

            //CAM MOVEMENT

            float speed = 10;
            float rot   = 3;

            if (InputManager.IsKeyDown(Keys.W))
            {
                camera.Transform.LocalPosition += speed * camera.Transform.Forward * Time.ElapsedGameTime;
            }
            if (InputManager.IsKeyDown(Keys.S))
            {
                camera.Transform.LocalPosition += speed * camera.Transform.Backward * Time.ElapsedGameTime;
            }

            if (InputManager.IsKeyDown(Keys.A))
            {
                camera.Transform.Rotate(Vector3.Up, rot * Time.ElapsedGameTime);
            }
            if (InputManager.IsKeyDown(Keys.D))
            {
                camera.Transform.Rotate(Vector3.Down, rot * Time.ElapsedGameTime);
            }

            if (InputManager.IsKeyDown(Keys.Space))
            {
                makeThatSphere();
            }
            if (InputManager.IsKeyPressed(Keys.R))
            {
                GameObject3d.activeGameObjects.Where(g => g.mesh?.Equals(sphere) == true).FirstOrDefault()?.Destroy();
            }

            if (InputManager.IsKeyDown(Keys.Up))
            {
                foreach (GameObject3d g in GameObject3d.activeGameObjects)
                {
                    Rigidbody b = g.GetBehavior <Rigidbody>();
                    if (b != null)
                    {
                        b.Velocity *= 1.05f;
                    }
                }
            }
            if (InputManager.IsKeyDown(Keys.Down))
            {
                foreach (GameObject3d g in GameObject3d.activeGameObjects)
                {
                    Rigidbody b = g.GetBehavior <Rigidbody>();
                    if (b != null)
                    {
                        b.Velocity *= 0.95f;
                    }
                }
            }

            if (InputManager.IsKeyPressed(Keys.T))
            {
                offsetSpeed += 0.1f;
            }
            if (InputManager.IsKeyPressed(Keys.Y))
            {
                offsetSpeed -= 0.1f;
            }

            if (InputManager.IsKeyPressed(Keys.G))
            {
                tileAmount += 1f;
            }
            if (InputManager.IsKeyPressed(Keys.H))
            {
                tileAmount -= (tileAmount > 1) ? 1f : 0;
            }

            //UpdateUI();

            base.Update(gameTime);
        }