Пример #1
0
 protected override void LoadContent()
 {
     spriteBatch = new SpriteBatch(GraphicsDevice);
     if (Services.GetService(spriteBatch.GetType()) == null)
     {
         Services.AddService(typeof(SpriteBatch), spriteBatch);
     }
     contentContainer.LoadContent();
     if(screenManager.isInitialize == false)
         screenManager.Initialize();
     base.LoadContent();
 }
Пример #2
0
        public RaySample()
        {
            ppm = new PostProcessingManager(Hgl.Game);
            rays = new CrepuscularRays(Hgl.Game, Vector2.One * .5f, "Textures/flare", 1, .97f, .97f, .5f, .25f);
            ppm.AddEffect(rays);

            _renderer = Add(new DrawComponent(Draw));

            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(Render.Device);
            Hgl.Game.Services.AddService(spriteBatch.GetType(), spriteBatch);

            rays.lightSource = rayStartingPos;

            scene = new RenderTarget2D(Render.Device, Render.Device.Viewport.Width, Render.Device.Viewport.Height, false, SurfaceFormat.Color, DepthFormat.None);

            AddBackground("Textures/Backgrounds/BGForeGround_1_1", 2f);
            AddBackground("Textures/Backgrounds/BGForeGround_1_2", 3f);
            AddBackground("Textures/Backgrounds/BGForeGround_1_3", 4f);
        }
Пример #3
0
        protected override void LoadContent()
        {
            // Initialize camera controls
            #region "etc"
            _view = Matrix.Identity;

            _screenCenter = new Vector2(graphics.GraphicsDevice.Viewport.Width / 2f,
                                                graphics.GraphicsDevice.Viewport.Height / 2f);

            backgroundRectangle = new Rectangle(0, 0, graphics.GraphicsDevice.Viewport.Width, graphics.GraphicsDevice.Viewport.Height);

            //_cameraPosition = new Vector2(0, -200);
            cam = new Camera2d();
            cam._pos = new Vector2(0, -200);
            _view = Matrix.CreateTranslation(new Vector3(cam._pos - _screenCenter, 0f)) *
                        Matrix.CreateTranslation(new Vector3(_screenCenter, 0f));
            batch = new SpriteBatch(graphics.GraphicsDevice);

            menuMusic = Content.Load<Song>("Audio/MenuMusic");  // Put the name of your song in instead of "song_title"
            MediaPlayer.IsRepeating = true;
            MediaPlayer.Volume = 0.6f;
            MediaPlayer.Play(menuMusic);

            menuBlip1 = Content.Load<SoundEffect>("Audio/Blip1");
            menuBlip2 = Content.Load<SoundEffect>("Audio/Blip2");

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

            minecraftia = Content.Load<SpriteFont>("Fonts/Minecraftia");
            bitWonder = Content.Load<SpriteFont>("Fonts/8BitWonder");

            fxaaEffect = Content.Load<Effect>("FXAA");

            // Load sprites
            circleSprite = Content.Load<Texture2D>("circleSprite"); //  96px x 96px => 1.5m x 1.5m
            //groundSprite = Content.Load<Texture2D>("groundSprite"); // 512px x 64px =>   8m x 1m
            blissSprite = Content.Load<Texture2D>("bliss");
            vignette = Content.Load<Texture2D>("textures/vignette");
            particleImage = Content.Load<Texture2D>("textures/metaparticle");

            walk = Content.Load<Texture2D>("textures/walk"); //  96px x 96px => 1.5m x 1.5m
            stand = Content.Load<Texture2D>("textures/stand"); // 512px x 64px =>   8m x 1m
            arm1 = Content.Load<Texture2D>("textures/arm"); // 512px x 64px =>   8m x 1m
            sword = Content.Load<Texture2D>("textures/sword");
            pick = Content.Load<Texture2D>("textures/pick");
            back = Content.Load<Texture2D>("textures/back");

            /* Circle */
            circleSprite = Content.Load<Texture2D>("circleSprite"); //  96px x 96px => 1.5m x 1.5m
            //groundSprite = Content.Load<Texture2D>("groundSprite"); // 512px x 64px =>   8m x 1m
            characterSprite = Content.Load<Texture2D>("textures/character"); // 512px x 64px =>   8m x 1m

            textures[1] = Content.Load<Texture2D>("textures/blocks/stone");
            textures[2] = Content.Load<Texture2D>("textures/blocks/dirt");
            textures[3] = Content.Load<Texture2D>("textures/blocks/iron");
            textures[4] = Content.Load<Texture2D>("textures/blocks/gold");
            textures[10] = Content.Load<Texture2D>("textures/blocks/cloud");
            textures[11] = Content.Load<Texture2D>("textures/blocks/grass");
            textures[12] = Content.Load<Texture2D>("textures/blocks/wood");
            textures[13] = Content.Load<Texture2D>("textures/blocks/brush");

            grass[1] = Content.Load<Texture2D>("textures/grass/grassleft");
            grass[2] = Content.Load<Texture2D>("textures/grass/grasstop");
            grass[3] = Content.Load<Texture2D>("textures/grass/grassright");
            grass[4] = Content.Load<Texture2D>("textures/grass/grasstopleft");
            grass[5] = Content.Load<Texture2D>("textures/grass/grasstopright");
            grass[6] = Content.Load<Texture2D>("textures/grass/grassleftright");
            grass[7] = Content.Load<Texture2D>("textures/grass/grasscovered");

            _fluidSimulation = new FluidSimulation(world, batch, font);
            water = new Water(GraphicsDevice, particleImage);
            #endregion
            #region "initTerrain"
            for (int x = 0; x < xD; x++)
            {
                for (int y = 0; y < yD; y++)
                {
                    terrain[x, y] = new Block();
                    terrain[x, y].setBlockType(Block.NO_BLOCK);
                }
            }
            int Seed = (int)DateTime.Now.Ticks;
            Console.Out.WriteLine(Seed);
            random = new Random(Seed);
            /*for (int xi = 1; xi < xD; xi++)
            {
                for (int yi = 1; yi < yD - 121; yi++)
                {
                    terrain[xi, yi + 121].setBlockType(2);
                }
            }*/
            Tree temp = new Tree(157, 121);
            terrain[159, 120].setBlockType(2);
            for (int xi = 163; xi < xD / 4; xi++)
            {
                terrain[xi, 117].setBlockType(2);
            }
            for (int xi = 162; xi < xD / 4; xi++)
            {
                terrain[xi, 118].setBlockType(2);
            }
            for (int xi = 161; xi < xD / 4; xi++)
            {
                terrain[xi, 119].setBlockType(2);
            }
            for (int xi = 161; xi < xD / 4; xi++)
            {
                terrain[xi, 120].setBlockType(2);
            }
            for (int xi = 150; xi < xD/4; xi++)
            {
                terrain[xi, 121].setBlockType(2);
            }
            for (int xi = 151; xi < xD / 4; xi++)
            {
                terrain[xi, 122].setBlockType(2);
            }
            for (int xi = 152; xi < xD / 4; xi++)
            {
                terrain[xi, 123].setBlockType(2);
            }
            for (int xi = 154; xi < xD / 4; xi++)
            {
                terrain[xi, 124].setBlockType(2);
            }
            for (int xi = 156; xi < xD / 4; xi++)
            {
                terrain[xi, 125].setBlockType(2);
            }
            for (int xi = 159; xi < xD / 4; xi++)
            {
                terrain[xi, 126].setBlockType(2);
            }
            for (int xi = 161; xi < xD / 4; xi++)
            {
                terrain[xi, 127].setBlockType(2);
            }
            for (int xi = 162; xi < xD / 4; xi++)
            {
                terrain[xi, 128].setBlockType(2);
            }
            //rock
            for (int xi = 163; xi < xD / 4; xi++)
            {
                terrain[xi, 119].setBlockType(1);
            }
            for (int xi = 162; xi < xD / 4; xi++)
            {
                terrain[xi, 120].setBlockType(1);
            }
            for (int xi = 162; xi < xD / 4; xi++)
            {
                terrain[xi, 121].setBlockType(1);
            }
            for (int xi = 153; xi < xD / 4; xi++)
            {
                terrain[xi, 122].setBlockType(1);
            }
            for (int xi = 155; xi < xD / 4; xi++)
            {
                terrain[xi, 123].setBlockType(1);
            }
            for (int xi = 157; xi < xD / 4; xi++)
            {
                terrain[xi, 124].setBlockType(1);
            }
            for (int xi = 160; xi < xD / 4; xi++)
            {
                terrain[xi, 125].setBlockType(1);
            }
            for (int xi = 162; xi < xD / 4; xi++)
            {
                terrain[xi, 126].setBlockType(1);
            }
            //dem checks
            for (int xi = 2; xi < xD - 1; xi++)
            {
                for (int yi = 1; yi < yD - 1; yi++)
                {
                    checkVariation(xi, yi);
                }
            }
            for (int xi = 4; xi < xD - 3; xi++)
            {
                for (int yi = 4; yi < yD - 3; yi++)
                {
                    if (terrain[xi, yi].getBlockType() != Block.DIRT_BLOCK)
                    {
                        terrain[xi, yi].setVariation(0);
                    }
                    //checkGrass(xi, yi);
                }
            }
            terrain[157, 121].setVariation(2);
            terrain[151, 120].setBlockType(Block.GRASS_BLOCK);
            terrain[153, 120].setBlockType(Block.GRASS_BLOCK);
            terrain[154, 120].setBlockType(Block.GRASS_BLOCK);
            terrain[155, 120].setBlockType(Block.GRASS_BLOCK);
            terrain[160, 120].setBlockType(Block.GRASS_BLOCK);
            terrain[162, 117].setBlockType(Block.GRASS_BLOCK);
            #endregion
            //generateTerrain();
            #region "physicssetup"
            // create and configure the debug view
            _debugView = new DebugViewXNA(world);
            _debugView.AppendFlags(DebugViewFlags.DebugPanel);
            _debugView.DefaultShapeColor = Color.White;
            _debugView.SleepingShapeColor = Color.LightGray;
            _debugView.LoadContent(GraphicsDevice, Content);

            Vector2 characterPosition = new Vector2(152.9f, 120);

            characterBody = CreateCapsule(world, 14f / scale, 7f / scale, 1f, null);

            characterBody.Position = characterPosition;
            characterBody.Mass = 10000;
            characterBody.SleepingAllowed = false;
            characterBody.IsStatic = false;
            characterBody.Restitution = 0.0f;
            characterBody.Friction = 0.0f;
            characterBody.FixedRotation = true;
            characterBody.OnCollision += CharacterOnCollision;
            characterBody.OnSeparation += CharacterOnSeparation;

            ////// arm stuff
            /*armBody = BodyFactory.CreateRectangle(world, 6f / scale, 29f / scale, 1f, characterPosition+new Vector2(0/scale,-14/scale));
            armBody.Mass = 1;
            armBody.IsStatic = false;
            armBody.IgnoreCollisionWith(characterBody);

            _joint = new RevoluteJoint(armBody, characterBody, armBody.GetLocalPoint(characterBody.Position), new Vector2(4 / scale, -4 / scale));
            world.AddJoint(_joint);

            //_joint.MotorSpeed = 1.0f * Settings.Pi;
            _joint.MaxMotorTorque = 1.0f;
            _joint.MotorEnabled = false;
            _joint.CollideConnected = false;*/

            characterBody.Mass = 1;
            //armBody.Mass = 0;

            /* Circle */
            // Convert screen center from pixels to meters
            Vector2 circlePosition = (_screenCenter / scale) + new Vector2(0, -40.5f);

            // Create the circle fixture
            circleBody = BodyFactory.CreateCircle(world, 96f / (2f * scale), 1f, circlePosition);
            circleBody.BodyType = BodyType.Dynamic;

            // Give it some bounce and friction
            circleBody.Restitution = 0.3f;
            circleBody.Friction = 0.5f;

            /* Ground */
            Vector2 groundPosition = (_screenCenter / scale) + new Vector2(0, -24.25f);

            // Create the ground fixture
            groundBody = BodyFactory.CreateRectangle(world, 512f / scale, 64f / scale, 1f, groundPosition);
            groundBody.IsStatic = true;
            groundBody.Restitution = 0.3f;
            groundBody.Friction = 0.5f;

            // create and configure the debug view
            _debugView = new DebugViewXNA(world);
            _debugView.AppendFlags(DebugViewFlags.DebugPanel);
            _debugView.DefaultShapeColor = Color.White;
            _debugView.SleepingShapeColor = Color.LightGray;
            _debugView.LoadContent(GraphicsDevice, Content);
            #endregion
            #region "blur"
            gaussianBlur = new GaussianBlur(this);
            gaussianBlur.ComputeKernel(BLUR_RADIUS, BLUR_AMOUNT);

            renderTargetWidth = 16;
            renderTargetHeight = 16;

            renderTarget1 = new RenderTarget2D(GraphicsDevice,
                renderTargetWidth, renderTargetHeight, false,
                GraphicsDevice.PresentationParameters.BackBufferFormat,
                DepthFormat.None);

            renderTarget2 = new RenderTarget2D(GraphicsDevice,
                renderTargetWidth, renderTargetHeight, false,
                GraphicsDevice.PresentationParameters.BackBufferFormat,
                DepthFormat.None);

            gaussianBlur.ComputeOffsets(renderTargetWidth, renderTargetHeight);
            #endregion
            #region "rays"
            Services.AddService(batch.GetType(), batch);

            rays.lightSource = rayStartingPos;
            rays.Exposure -= .15f;
            rays.LightSourceSize -= .5f;

            scene = new RenderTarget2D(graphics.GraphicsDevice, graphics.GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height, false, SurfaceFormat.Color, DepthFormat.None);
            sceneReg = new RenderTarget2D(graphics.GraphicsDevice, graphics.GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height, false, SurfaceFormat.Color, DepthFormat.None);
            sceneRegB = new RenderTarget2D(graphics.GraphicsDevice, graphics.GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height, false, SurfaceFormat.Color, DepthFormat.None);
            sceneRegPre = new RenderTarget2D(graphics.GraphicsDevice, graphics.GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height, false, SurfaceFormat.Color, DepthFormat.None);

            #endregion
        }