Beispiel #1
0
        /// <summary>
        /// Construct a new World object.
        /// </summary>
        /// <param name="graphicsDevice">The graphics device used for this game.</param>
        /// <param name="networkSession">The network session for this game.</param>
        public World(GraphicsDevice graphicsDevice, ContentManager contentManager, 
            NetworkSession networkSession)
        {
            // safety-check the parameters, as they must be valid
            if (graphicsDevice == null)
            {
                throw new ArgumentNullException("graphicsDevice");
            }
            if (contentManager == null)
            {
                throw new ArgumentNullException("contentManager");
            }
            if (networkSession == null)
            {
                throw new ArgumentNullException("networkSession");
            }

            // apply the parameter values
            this.networkSession = networkSession;

            // set up the staggered status packet system
            // -- your first update happens based on where you are in the collection
            for (int i = 0; i < networkSession.AllGamers.Count; i++)
            {
                if (networkSession.AllGamers[i].IsLocal)
                {
                    updatesSinceStatusPacket = i;
                    break;
                }
            }

            // create the spritebatch
            spriteBatch = new SpriteBatch(graphicsDevice);

            // create and initialize the particle-effect manager
            particleEffectManager = new ParticleEffectManager(contentManager);
            particleEffectManager.RegisterParticleEffect(
                ParticleEffectType.LaserExplosion,
                "Particles/laserExplosion.xml", 40);
            particleEffectManager.RegisterParticleEffect(
                ParticleEffectType.MineExplosion, 
                "Particles/mineExplosion.xml", 8);
            particleEffectManager.RegisterParticleEffect(
                ParticleEffectType.RocketExplosion, 
                "Particles/rocketExplosion.xml", 24);
            particleEffectManager.RegisterParticleEffect(
                ParticleEffectType.RocketTrail, 
                "Particles/rocketTrail.xml", 16);
            particleEffectManager.RegisterParticleEffect(
                ParticleEffectType.ShipExplosion, 
                "Particles/shipExplosion.xml", 4);
            particleEffectManager.RegisterParticleEffect(
                ParticleEffectType.ShipSpawn, 
                "Particles/shipSpawn.xml", 4);
            Ship.ParticleEffectManager = particleEffectManager;
            RocketProjectile.ParticleEffectManager = particleEffectManager;
            MineProjectile.ParticleEffectManager = particleEffectManager;
            LaserProjectile.ParticleEffectManager = particleEffectManager;

            // load the font
            playerFont = contentManager.Load<SpriteFont>("Fonts/NetRumbleFont");

            // load the gameplay-object textures
            Ship.LoadContent(contentManager);
            Asteroid.LoadContent(contentManager);
            LaserProjectile.LoadContent(contentManager);
            MineProjectile.LoadContent(contentManager);
            RocketProjectile.LoadContent(contentManager);
            DoubleLaserPowerUp.LoadContent(contentManager);
            TripleLaserPowerUp.LoadContent(contentManager);
            RocketPowerUp.LoadContent(contentManager);
            
            // load the non-gameplay-object textures
            chatAbleTexture = contentManager.Load<Texture2D>("Textures/chatAble");
            chatMuteTexture = contentManager.Load<Texture2D>("Textures/chatMute");
            chatTalkingTexture = contentManager.Load<Texture2D>("Textures/chatTalking");
            readyTexture = contentManager.Load<Texture2D>("Textures/ready");
            cornerBarrierTexture = 
                contentManager.Load<Texture2D>("Textures/barrierEnd");
            verticalBarrierTexture = 
                contentManager.Load<Texture2D>("Textures/barrierPurple");
            horizontalBarrierTexture = 
                contentManager.Load<Texture2D>("Textures/barrierRed");

            // clear the collision manager
            CollisionManager.Collection.Clear();

            // add the collision version of the edge barriers
            CollisionManager.Barriers.Clear();
            CollisionManager.Barriers.Add(new Rectangle(dimensions.X, dimensions.Y, 
                dimensions.Width, barrierSize));  // top edge
            CollisionManager.Barriers.Add(new Rectangle(
                dimensions.X, dimensions.Y + dimensions.Height, 
                dimensions.Width, barrierSize));  // bottom edge
            CollisionManager.Barriers.Add(new Rectangle(dimensions.X, dimensions.Y, 
                barrierSize, dimensions.Height)); // left edge
            CollisionManager.Barriers.Add(new Rectangle(
                dimensions.X + dimensions.Width, dimensions.Y, 
                barrierSize, dimensions.Height)); // right edge

            // add the rendering version of the edge barriers
            cornerBarriers.Clear();
            cornerBarriers.Add(new Rectangle(dimensions.X, dimensions.Y, 
                barrierSize, barrierSize)); // top-left corner
            cornerBarriers.Add(new Rectangle(
                dimensions.X + dimensions.Width, dimensions.Y, 
                barrierSize, barrierSize)); // top-right corner
            cornerBarriers.Add(new Rectangle(
                dimensions.X, dimensions.Y + dimensions.Height, 
                barrierSize, barrierSize)); // bottom-left corner
            cornerBarriers.Add(new Rectangle(
                dimensions.X + dimensions.Width, dimensions.Y + dimensions.Height, 
                barrierSize, barrierSize)); // bottom-right corner
            verticalBarriers.Clear();
            for (int i = 1; i < barrierCounts.Y; i++)
            {
                verticalBarriers.Add(new Rectangle(
                    dimensions.X, dimensions.Y + barrierSize * i, 
                    barrierSize, barrierSize)); // top edge
                verticalBarriers.Add(new Rectangle(
                    dimensions.X + dimensions.Width, dimensions.Y + barrierSize * i,
                    barrierSize, barrierSize)); // bottom edge
            }
            horizontalBarriers.Clear();
            for (int i = 1; i < barrierCounts.X; i++)
            {
                horizontalBarriers.Add(new Rectangle(
                    dimensions.X + barrierSize * i, dimensions.Y,
                    barrierSize, barrierSize)); // left edge
                horizontalBarriers.Add(new Rectangle(
                    dimensions.X + barrierSize * i, dimensions.Y + dimensions.Width,
                    barrierSize, barrierSize)); // right edge
            }
        }