/// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        public override void LoadContent()
        {
            //read write stream to the server
            readStream = new MemoryStream();
            writeStream = new MemoryStream();

            reader = new BinaryReader(readStream);
            writer = new BinaryWriter(writeStream);
            if (Content == null)
                Content = new ContentManager(ScreenManager.Game.Services, "Content");

            //DebugView Stuff
            Settings.EnableDiagnostics = true;
            DebugView = new DebugViewXNA(world);
            DebugView.LoadContent(ScreenManager.GraphicsDevice, Content);

            terrain.LoadContent(ScreenManager.GraphicsDevice);

            //Create camera using current viewport. Track a body without rotation.
            camera = new Camera2D(ScreenManager.GraphicsDevice);

            gameFont = Content.Load<SpriteFont>("gamefont");

            // Back ground stuff --------------------------------
            List<Texture2D> list = new List<Texture2D>();
            list.Add(ScreenManager.Game.Content.Load<Texture2D>("Sky"));
            list.Add(ScreenManager.Game.Content.Load<Texture2D>("trees"));
            list.Add(ScreenManager.Game.Content.Load<Texture2D>("Grass"));
            skyLayer = new GameBackground(list, camera.Position)
            {
                Height = ScreenManager.GraphicsDevice.Viewport.Height,
                Width = ScreenManager.GraphicsDevice.Viewport.Width,
                SpeedX = 0.3f
            };
            //---------------------------------------------------

            Texture2D terrainTex = Content.Load<Texture2D>("ground");

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

            //Create player
            player = new CompositeCharacter(world, new Vector2(ScreenManager.GraphicsDevice.Viewport.Width / 2.0f, ScreenManager.GraphicsDevice.Viewport.Height / 2.0f),
                Content.Load<Texture2D>("bean_ss1"), new Vector2(35.0f, 50.0f), ScreenManager.CharacterColor);

            //Create HUD
            playerHUD = new HUD(ScreenManager.Game, player, ScreenManager.Game.Content, ScreenManager.SpriteBatch);
            ScreenManager.Game.Components.Add(playerHUD);

            client = new TcpClient();
            client.NoDelay = true;
            IPAddress ipadd = System.Net.IPAddress.Parse("169.254.169.231");
            client.Connect(ipadd, PORT);
            readBuffer = new byte[BUFFER_SIZE];
            client.GetStream().BeginRead(readBuffer, 0, BUFFER_SIZE, StreamReceived, null);

            Thread.Sleep(2000);

            if (id == 0)
            {
                terrain.CreateRandomTerrain(new Vector2(0, 0));
            }
            // Set camera to track player
            camera.TrackingBody = player.body;

            //Create walls
            leftWall = new StaticPhysicsObject(world, new Vector2(ConvertUnits.ToDisplayUnits(-100.0f), 0), Content.Load<Texture2D>("platformTex"),
                new Vector2(100, ConvertUnits.ToDisplayUnits(100.0f)));
            rightWall = new StaticPhysicsObject(world, new Vector2(ConvertUnits.ToDisplayUnits(100.0f), 0), Content.Load<Texture2D>("platformTex"),
                new Vector2(100, ConvertUnits.ToDisplayUnits(100.0f)));

            ground = new StaticPhysicsObject(world, new Vector2(ScreenManager.GraphicsDevice.Viewport.Width / 4.0f, ScreenManager.GraphicsDevice.Viewport.Height / 2.0f + 100), Content.Load<Texture2D>("platformTex"), new Vector2(2000f, 20f));
            // Load projectile and explosion textures
            projectileTexRed = Content.Load<Texture2D>("projectile_fire_red");
            projectileTexBlue = Content.Load<Texture2D>("projectile_fire_blue");
            projectileTexYellow = Content.Load<Texture2D>("projectile_fire_yellow");
            explosionTex = Content.Load<Texture2D>("explosion");

            // ----------------------------------------------------------

            // once the load has finished, we use ResetElapsedTime to tell the game's
            // timing mechanism that we have just finished a very long frame, and that
            // it should not try to catch up.
            ScreenManager.Game.ResetElapsedTime();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        public override void LoadContent()
        {
            if (Content == null)
                Content = new ContentManager(ScreenManager.Game.Services, "Content");

            //DebugView Stuff
            Settings.EnableDiagnostics = true;
            DebugView = new DebugViewXNA(world);
            DebugView.LoadContent(ScreenManager.GraphicsDevice, Content);

            terrain.LoadContent(ScreenManager.GraphicsDevice);

            //Create camera using current viewport. Track a body without rotation.
            camera = new Camera2D(ScreenManager.GraphicsDevice);

            gameFont = Content.Load<SpriteFont>("gamefont");

            // Back ground stuff --------------------------------
            List<Texture2D> list = new List<Texture2D>();
            list.Add(ScreenManager.Game.Content.Load<Texture2D>("Sky"));
            list.Add(ScreenManager.Game.Content.Load<Texture2D>("trees"));
            list.Add(ScreenManager.Game.Content.Load<Texture2D>("Grass"));
            skyLayer = new GameBackground(list, camera.Position)
            {
                Height = ScreenManager.GraphicsDevice.Viewport.Height,
                Width = ScreenManager.GraphicsDevice.Viewport.Width,
                SpeedX = 0.3f
            };
            //---------------------------------------------------

            Texture2D terrainTex = Content.Load<Texture2D>("ground");
            terrain.CreateRandomTerrain(new Vector2(0, 0));

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

            player = new CompositeCharacter(world, new Vector2(0, 0), Content.Load<Texture2D>("bean_ss1"), new Vector2(35.0f, 50.0f), ScreenManager.CharacterColor);

            //Create HUD
            playerHUD = new HUD(ScreenManager.Game, player, ScreenManager.Game.Content, ScreenManager.SpriteBatch);
            ScreenManager.Game.Components.Add(playerHUD);

            // Set camera to track player
            camera.TrackingBody = player.body;

            //Create walls
            leftWall = new StaticPhysicsObject(world, new Vector2(ConvertUnits.ToDisplayUnits(-100.0f), 0), Content.Load<Texture2D>("platformTex"),
                new Vector2(100, ConvertUnits.ToDisplayUnits(100.0f)));
            rightWall = new StaticPhysicsObject(world, new Vector2(ConvertUnits.ToDisplayUnits(100.0f), 0), Content.Load<Texture2D>("platformTex"),
                new Vector2(100, ConvertUnits.ToDisplayUnits(100.0f)));

            // Load projectile and explosion textures
            projectileTexRed = Content.Load<Texture2D>("projectile_fire_red");
            projectileTexBlue = Content.Load<Texture2D>("projectile_fire_blue");
            projectileTexYellow = Content.Load<Texture2D>("projectile_fire_yellow");
            explosionTex = Content.Load<Texture2D>("explosion");
            enemyTex = Content.Load<Texture2D>("enemy_new");

            // ----------------------------------------------------------

            // Sleep for the loading screen
            Thread.Sleep(500);

            // once the load has finished, we use ResetElapsedTime to tell the game's
            // timing mechanism that we have just finished a very long frame, and that
            // it should not try to catch up.
            ScreenManager.Game.ResetElapsedTime();
        }