Ejemplo n.º 1
0
        /// <summary>
        /// Constructs a new particle emitter object.
        /// </summary>
        public ParticleEmitter(ParticleSystem particleSystem,
                               float particlesPerSecond, Vector3 initialPosition)
        {
            this.particleSystem = particleSystem;

            timeBetweenParticles = 1.0f/particlesPerSecond;

            previousPosition = initialPosition;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Constructs a new projectile.
        /// </summary>
        public Projectile(Vector3 from, Vector3 startVelocity,
                          ParticleSystem explosionParticles,
                          ParticleSystem explosionSmokeParticles,
                          ParticleSystem projectileTrailParticles)
        {
            this._explosionParticles = explosionParticles;
            this._explosionSmokeParticles = explosionSmokeParticles;

            // Start at the origin, firing in a random (but roughly upward) direction.
            _position = from;

            _velocity.X = startVelocity.X; //(float)(random.NextDouble() - 0.5) * sidewaysVelocityRange;
            _velocity.Y = startVelocity.Y; //(float)(random.NextDouble() + 0.5) * verticalVelocityRange;
            _velocity.Z = startVelocity.Z; //(float)(random.NextDouble() - 0.5) * sidewaysVelocityRange;

            // Use the particle emitter helper to output our trail particles.
            _trailEmitter = new ParticleEmitter(projectileTrailParticles,
                                               TrailParticlesPerSecond, _position);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        public override void LoadContent()
        {
            graphics = (GraphicsDeviceManager) ScreenManager.Game.Services.GetService(typeof (IGraphicsDeviceManager));
            //graphics.ToggleFullScreen();

            // Construct our particle system components.
            explosionParticles = new ExplosionParticleSystem(ScreenManager.Game, ScreenManager.Game.Content);
            explosionSmokeParticles = new ExplosionSmokeParticleSystem(ScreenManager.Game, ScreenManager.Game.Content);
            projectileTrailParticles = new ProjectileTrailParticleSystem(ScreenManager.Game, ScreenManager.Game.Content);
            smokePlumeParticles = new SmokePlumeParticleSystem(ScreenManager.Game, ScreenManager.Game.Content);
            fireParticles = new FireParticleSystem(ScreenManager.Game, ScreenManager.Game.Content);

            // Set the draw order so the explosions and fire
            // will appear over the top of the smoke.
            smokePlumeParticles.DrawOrder = 100;
            explosionSmokeParticles.DrawOrder = 200;
            projectileTrailParticles.DrawOrder = 300;
            explosionParticles.DrawOrder = 400;
            fireParticles.DrawOrder = 500;

            // Load terrain
            terrain = ScreenManager.Game.Content.Load<Model>("terrain/terrain3");
            // The terrain processor attached a HeightMapInfo to the terrain model's
            // Tag. We'll save that to a member variable now, and use it to
            // calculate the terrain's heights later.
            heightMapInfo = terrain.Tag as HeightMapInfo;
            if (heightMapInfo == null)
            {
                const string message = "The terrain model did not have a HeightMapInfo " +
                                       "object attached. Are you sure you are using the " +
                                       "TerrainProcessor?";
                throw new InvalidOperationException(message);
            }

            // Load entities
            playerOne = new Player(this, "models/rio/rio_1", playerOneName, 1, true) {Position = new Vector3(400, 0, -400)};
            ai = new Player(this, "models/rio/rio_2", playerTwoName, 2, true) {Position = new Vector3(200, 0, 200)};
            ai.RandomMovementMinimalInterval = 0.01f;
            ai.RandomMovementMaximalnInterval = 0.03f;
            ai.RandomMovementRotationProbability = 0.3f;
            ai.MovesRandomly = true;

            surface = new Entity(this, "models/surface/surface", false, true);
            surface.Alpha = 0.6f;
            surface.MoveInTime = true;
            //surface.MaxMovementSpeed = 1.8f;
            surface.MovementSpeed = 0.0002f;
            surface.Friction = 0.00001f;
            surface.RotationX = MathHelper.ToRadians(180f);
            surface.Position = new Vector3(0, 500, 0);
            surface.IsBoundToHeightMap = false;
            Entites.Add(surface);

            Entites.Add(PlayerOne);
            Entites.Add(ai);

            CollideableEntites.Add(PlayerOne);
            CollideableEntites.Add(ai);

            AddMultipleInstancesOfEntity("models/egg/egg", 2, true, false, true);
            //AddMultipleInstancesOfEntity("models/grass/grassBig1", 30, false, true);
            //AddMultipleInstancesOfEntity("models/grass/grassBig2", 30, false, true);
            //AddMultipleInstancesOfEntity("models/grass/grassBig3", 30, false, true);
            //AddMultipleInstancesOfEntity("models/grass/grassBig4", 30, false, true);
            //AddMultipleInstancesOfEntity("models/grass/grassSmall1", 50, false, true);
            //AddMultipleInstancesOfEntity("models/grass/grassSmall2", 50, false, true);
            //AddMultipleInstancesOfEntity("models/grass/grassSmall3", 50, false, true);
            //AddMultipleInstancesOfEntity("models/grass/grassSmall4", 50, false, true);
            AddMultipleInstancesOfEntity("models/grassBunch/grassBunchSmall1", 80, false, true);
            AddMultipleInstancesOfEntity("models/grassBunch/grassBunchSmall2", 80, false, true);
            AddMultipleInstancesOfEntity("models/grassBunch/grassBunchSmall3", 80, false, true);
            AddMultipleInstancesOfEntity("models/grassBunch/grassBunchBig1", 60, false, true);
            AddMultipleInstancesOfEntity("models/grassBunch/grassBunchBig2", 60, false, true);
            AddMultipleInstancesOfEntity("models/grassBunch/grassBunchBig3", 60, false, true);
            AddMultipleInstancesOfEntity("models/seaGrass/seaGrassBigBlue", 60, true, true);
            AddMultipleInstancesOfEntity("models/seaGrass/seaGrassBigGreen", 60, true, true);
            //AddMultipleInstancesOfEntity("models/seaGrass/seaGrassBigPink", 60, true, true);
            AddMultipleInstancesOfEntity("models/seaGrass/seaGrassBigRed", 60, true, true);
            AddMultipleInstancesOfEntity("models/seaGrass/seaGrassBigViolet", 60, true, true);
            //AddMultipleInstancesOfEntity("models/seaGrass/seaGrassBigYellow", 60, true, true);
            AddMultipleInstancesOfEntity("models/seaGrassCylinder/seaGrassCylinderDorangev1", 30, true, true, false, 15);
            AddMultipleInstancesOfEntity("models/seaGrassCylinder/seaGrassCylinderDorangev2", 30, true, true, false, 15);
            AddMultipleInstancesOfEntity("models/seaGrassCylinder/seaGrassCylinderDorangev3", 30, true, true, false, 15);
            AddMultipleInstancesOfEntity("models/seaGrassCylinder/seaGrassCylinderOrangev1", 30, true, true, false, 15);
            AddMultipleInstancesOfEntity("models/seaGrassCylinder/seaGrassCylinderOrangev2", 30, true, true, false, 15);
            AddMultipleInstancesOfEntity("models/seaGrassCylinder/seaGrassCylinderOrangev3", 30, true, true, false, 15);
            AddMultipleInstancesOfEntity("models/seaGrassCylinder/seaGrassCylinderRedv1", 30, true, true, false, 15);
            AddMultipleInstancesOfEntity("models/seaGrassCylinder/seaGrassCylinderRedv2", 30, true, true, false, 15);
            AddMultipleInstancesOfEntity("models/seaGrassCylinder/seaGrassCylinderRedv3", 30, true, true, false, 15);
            AddMultipleInstancesOfEntity("models/seaGrassCylinder/seaGrassCylinder2Pink", 30, false, true, true, 15);
            AddMultipleInstancesOfEntity("models/seaGrassCylinder/seaGrassCylinder2Red", 30, false, true, true, 15);
            AddMultipleInstancesOfEntity("models/seaGrassCylinder/seaGrassCylinder2Violet", 30, false, true, true, 15);
            AddMultipleInstancesOfEntity("models/seaGrass/seaGrassMiddleBlue", 65, true, true);
            AddMultipleInstancesOfEntity("models/seaGrass/seaGrassMiddleGreen", 65, true, true);
            AddMultipleInstancesOfEntity("models/seaGrass/seaGrassMiddleRed", 65, true, true);
            AddMultipleInstancesOfEntity("models/seaGrass/seaGrassMiddleViolet", 65, true, true);
            AddMultipleInstancesOfEntity("models/seaGrass/seaGrassMiddleYellow", 65, true, true);
            AddMultipleInstancesOfEntity("models/seaGrass/seaGrassSmallBlue", 40, true, true);
            AddMultipleInstancesOfEntity("models/seaGrass/seaGrassSmallGreen", 40, true, true);
            AddMultipleInstancesOfEntity("models/seaGrass/seaGrassSmallRed", 40, true, true);
            AddMultipleInstancesOfEntity("models/seaGrass/seaGrassSmallViolet", 40, true, true);
            AddMultipleInstancesOfEntity("models/seaGrass/seaGrassSmallYellow", 40, true, true);
            AddMultipleInstancesOfEntity("models/star/seaStarSlim", 85, true, true, false, 15, true);
            AddMultipleInstancesOfEntity("models/shell/shellOpen", 25, true, true);
            AddMultipleInstancesOfEntity("models/shell/shellHalfClose", 25, true, true);
            AddMultipleInstancesOfEntity("models/shell/shellClose", 25, true, true);
            AddMultipleInstancesOfEntity("models/mussel/musselOpen", 25, true, true);
            AddMultipleInstancesOfEntity("models/mussel/musselClose", 25, true, true);
            AddMultipleInstancesOfEntity("models/urchin/urchinBlack", 25, true, true);
            AddMultipleInstancesOfEntity("models/urchin/urchinRed", 25, true, true);
            AddMultipleInstancesOfEntity("models/urchin/urchinWithHairLongBlack", 25, true, true, true, 12, true);
            AddMultipleInstancesOfEntity("models/urchin/urchinWithHairLongRed", 25, true, true, true, 12, true);
            AddMultipleInstancesOfEntity("models/urchin/urchinWithHairShortBlack", 25, true, true, true, 12, true);
            AddMultipleInstancesOfEntity("models/urchin/urchinWithHairShortRed", 25, true, true, true, 12, true);
            AddMultipleInstancesOfEntity("models/stone/stone1_tex1", 1, true, false, true, 70);
            AddMultipleInstancesOfEntity("models/stone/stone1_tex2", 1, true, false, true, 70);
            AddMultipleInstancesOfEntity("models/stone/stone1_tex3", 1, true, false, true, 70);
            AddMultipleInstancesOfEntity("models/stone/stone1_tex1", 1, true, false, true, 70);
            AddMultipleInstancesOfEntity("models/stone/stone1_tex2", 1, true, false, true, 70);
            AddMultipleInstancesOfEntity("models/stone/stone1_tex3", 1, true, false, true, 70);
            AddMultipleInstancesOfEntity("models/stone/stone2_tex1", 1, true, false, true, 70);
            AddMultipleInstancesOfEntity("models/stone/stone2_tex2", 1, true, false, true, 70);
            AddMultipleInstancesOfEntity("models/stone/stone2_tex3", 1, true, false, true, 70);
            AddMultipleInstancesOfEntity("models/stone/stone3_tex1", 1, true, false, true, 70);
            AddMultipleInstancesOfEntity("models/stone/stone3_tex2", 1, true, false, true, 70);
            AddMultipleInstancesOfEntity("models/stone/stone3_tex3", 1, true, false, true, 70);
            AddMultipleInstancesOfEntity("models/stone/stone4_tex1", 1, true, false, true, 70);
            AddMultipleInstancesOfEntity("models/stone/stone4_tex2", 1, true, false, true, 70);
            AddMultipleInstancesOfEntity("models/stone/stone4_tex3", 1, true, false, true, 70);
            AddMultipleInstancesOfEntity("models/stone/stone5_tex1", 1, true, false, true, 70);
            AddMultipleInstancesOfEntity("models/stone/stone5_tex2", 1, true, false, true, 70);
            AddMultipleInstancesOfEntity("models/stone/stone5_tex3", 1, true, false, true, 70);
            AddMultipleInstancesOfEntity("models/stone/stone6_tex1", 1, true, false, true, 70);
            AddMultipleInstancesOfEntity("models/stone/stone6_tex2", 1, true, false, true, 70);
            AddMultipleInstancesOfEntity("models/stone/stone6_tex3", 1, true, false, true, 70);
            AddMultipleInstancesOfEntity("models/stone/stone7_tex1", 1, true, false, true, 70);
            AddMultipleInstancesOfEntity("models/stone/stone7_tex2", 1, true, false, true, 70);
            AddMultipleInstancesOfEntity("models/stone/stone7_tex3", 1, true, false, true, 70);
            AddMultipleInstancesOfEntity("models/stone/stone8_tex1", 1, true, false, true, 70);
            AddMultipleInstancesOfEntity("models/stone/stone8_tex2", 1, true, false, true, 70);
            AddMultipleInstancesOfEntity("models/stone/stone8_tex3", 1, true, false, true, 70);
            AddMultipleInstancesOfEntity("models/stone/stone9_tex1", 1, true, false, true, 70);
            AddMultipleInstancesOfEntity("models/stone/stone9_tex2", 1, true, false, true, 70);
            AddMultipleInstancesOfEntity("models/stone/stone9_tex3", 1, true, false, true, 70);
            AddMultipleInstancesOfEntity("models/stone/stone10_tex1", 1, true, false, true, 70);
            AddMultipleInstancesOfEntity("models/stone/stone10_tex2", 1, true, false, true, 70);
            AddMultipleInstancesOfEntity("models/stone/stone10_tex3", 1, true, false, true, 70);
            AddMultipleInstancesOfEntity("models/stone/stone11_tex1", 1, true, false, true, 70);
            AddMultipleInstancesOfEntity("models/stone/stone11_tex2", 1, true, false, true, 70);
            AddMultipleInstancesOfEntity("models/stone/stone11_tex3", 1, true, false, true, 70);
            AddMultipleInstancesOfEntity("models/stone/stone12_tex1", 1, true, false, true, 70);
            AddMultipleInstancesOfEntity("models/stone/stone12_tex2", 1, true, false, true, 70);
            AddMultipleInstancesOfEntity("models/stone/stone12_tex3", 1, true, false, true, 70);
            AddMultipleInstancesOfEntity("models/stone/stone13_tex1", 1, true, false, true, 70);
            AddMultipleInstancesOfEntity("models/stone/stone13_tex2", 1, true, false, true, 70);
            AddMultipleInstancesOfEntity("models/stone/stone13_tex3", 1, true, false, true, 70);
            AddMultipleInstancesOfEntity("models/stone/stone14_tex1", 1, true, false, true, 70);
            AddMultipleInstancesOfEntity("models/stone/stone14_tex2", 1, true, false, true, 70);
            AddMultipleInstancesOfEntity("models/stone/stone14_tex3", 1, true, false, true, 70);
            AddMultipleInstancesOfEntity("models/stone/stoneGroup1_tex1", 1, true, false, true, 100);
            AddMultipleInstancesOfEntity("models/stone/stoneGroup1_tex2", 1, true, false, true, 100);
            AddMultipleInstancesOfEntity("models/stone/stoneGroup1_tex3", 1, true, false, true, 100);
            AddMultipleInstancesOfEntity("models/stone/stoneGroup2_tex1", 1, true, false, true, 100);
            AddMultipleInstancesOfEntity("models/stone/stoneGroup2_tex2", 1, true, false, true, 100);
            AddMultipleInstancesOfEntity("models/stone/stoneGroup2_tex3", 1, true, false, true, 100);
            AddMultipleInstancesOfEntity("models/stone/stoneGroup3_tex1", 1, true, false, true, 100);
            AddMultipleInstancesOfEntity("models/stone/stoneGroup3_tex2", 1, true, false, true, 100);
            AddMultipleInstancesOfEntity("models/stone/stoneGroup3_tex3", 1, true, false, true, 100);
            AddMultipleInstancesOfEntity("models/stone/stoneGroup4_tex1", 1, true, false, true, 100);
            AddMultipleInstancesOfEntity("models/stone/stoneGroup4_tex2", 1, true, false, true, 100);
            AddMultipleInstancesOfEntity("models/stone/stoneGroup4_tex3", 1, true, false, true, 100);
            /**/

            // Components registration
            bloom = new BloomComponent(ScreenManager.Game);
            ScreenManager.Game.Components.Add(bloom);

            // Register the particle system components.
            ScreenManager.Game.Components.Add(explosionParticles);
            ScreenManager.Game.Components.Add(explosionSmokeParticles);
            ScreenManager.Game.Components.Add(projectileTrailParticles);
            ScreenManager.Game.Components.Add(smokePlumeParticles);
            ScreenManager.Game.Components.Add(fireParticles);

            // Enable background sound
            backgroundSound = ScreenManager.AudioManager.Play3DSound("sound/game_background", true, surface);

            spriteBatch = new SpriteBatch(graphics.GraphicsDevice);
            //ScreenManager.Game.Content.Load<SpriteFont>("fonts/hudFont");
            //ScreenManager.Game.Content.Load<Texture2D>("images/hud");
            background = ScreenManager.Game.Content.Load<Texture2D>("images/game/background");

            foreach (Entity entity in Entites)
                entity.LoadContent();

            ScreenManager.Game.ResetElapsedTime();
        }

        public void setBloomPreset(String presetName)
        {
            BloomSettings preset = BloomSettings.PresetSettings[0];

            foreach (var currentPreset in BloomSettings.PresetSettings)
            {
                if(currentPreset.Name.Equals(presetName))
                {
                    preset = currentPreset;
                    break;
                }
            }

            bloom.Settings = preset;
            setBloomPresetCleaningTimeout();
        }

        /// <summary>
        /// UnloadContent will be called once per game and is the place to unload
        /// all content.
        /// </summary>
        public override void UnloadContent()
        {
            if (!backgroundSound.IsDisposed)
                backgroundSound.Stop(true);

            for (int i = ScreenManager.Game.Components.Count - 1; i > 1; i--)
                ScreenManager.Game.Components.RemoveAt(i);

            foreach (Entity entity in Entites)
                entity.UnloadContent();
            foreach (Rocket entity in rockets)
                entity.UnloadContent();
        }

        /// <summary>
        /// Allows the game to run logic.
        /// </summary>
        public override void Update(GameTime gameTime, bool otherScreenHasFocus, bool coveredByOtherScreen)
        {
            /*if(!_fpsCamera)*/ UpdateCamera(gameTime); // colission with player controls
            UpdateProjectiles(gameTime);

            presetCleanDelay -= gameTime.ElapsedGameTime;
            if (!bloom.Settings.Name.Equals(BloomSettings.PresetSettings[0].Name) && presetCleanDelay < TimeSpan.Zero)
            {
                setBloomPreset("Default");
            }

            rocketGCDelay -= gameTime.ElapsedGameTime;
            if (rocketGCDelay < TimeSpan.Zero)
            {
                RocketGC();
                rocketGCDelay += TimeSpan.FromSeconds(RocketGCInterval);;
            }

            foreach (Entity entity in Entites)
                entity.Update(gameTime, heightMapInfo);

            foreach (Rocket entity in rockets)
                entity.Update(gameTime, heightMapInfo);

            base.Update(gameTime, otherScreenHasFocus, false);
        }