Beispiel #1
0
        public PhysicsComponent(Scene aScene, Vector2 aGravity, bool aOptimised = false)
            : base(aScene)
        {
            ConvertUnits.SetDisplayUnitToSimUnitRatio(24f);

            mGravity = aGravity;
            mMultiplier = 1;
            mWorld = new World(mGravity);

            mDebugView = new DebugViewXNA(mWorld);
            mDebugView.DefaultShapeColor = Color.White;
            mDebugView.SleepingShapeColor = Color.LightGray;

            mDebugView.LoadContent(MilkShake.Graphics, MilkShake.ConentManager);

            // [Add Listeners]
            Scene.Listener.Update += new UpdateEvent(Update);
            Scene.Listener.PostDraw[DrawLayer.First] += new DrawEvent(Draw);
            Settings.AllowSleep = false;
            // Optimise
            if(aOptimised)
            {
             	   	Settings.AllowSleep = false;
             	   	Settings.EnableDiagnostics = false;
                Settings.VelocityIterations = 6;
               	     	Settings.PositionIterations = 4;
               	    	Settings.ContinuousPhysics = false;
            }
        }
Beispiel #2
0
        protected override void Initialize()
        {
            IsMouseVisible = true;

            // Initialize the lighting system
            penumbra.Initialize();
            penumbra.AmbientColor = new Color(new Vector3(0.7f));
            //penumbra.Debug = true;

            // Our world for the physics body
            world = new World(Vector2.Zero);

            // Initialize the physics debug view
            PhysicsDebugView = new DebugViewXNA(world);
            PhysicsDebugView.LoadContent(GraphicsDevice, Content);
            PhysicsDebugView.RemoveFlags(DebugViewFlags.Controllers);
            PhysicsDebugView.RemoveFlags(DebugViewFlags.Joint);
            PhysicsDebugView.RemoveFlags(DebugViewFlags.Shape);
            PhysicsDebugView.DefaultShapeColor = new Color(255, 255, 0);

            graphics.PreferredBackBufferWidth  = 1280;
            graphics.PreferredBackBufferHeight = 720;

            graphics.SynchronizeWithVerticalRetrace = true;
            IsFixedTimeStep = false;
            base.Initialize();
        }
        public ControllerViewManager(GraphicsDevice graphicsDevice, ContentManager content)
        {
            controllers = new List<Controller>();
            views = new List<IView>();

            this.content = content;
            this.graphicsDevice = graphicsDevice;
            this.batch = new SpriteBatch(graphicsDevice);
            this.world = new World(new Vector2(0, Constants.GamePlayGravity));
            this.controllerQueue = new ConcurrentQueue<Tuple<Controller, QueueState>>();
            this.viewQueue = new ConcurrentQueue<Tuple<IView, QueueState>>();

            if (Constants.DebugMode && debugView == null)
            {
                debugView = new DebugViewXNA(world);
                debugView.AppendFlags(DebugViewFlags.DebugPanel);
                debugView.DefaultShapeColor = Color.Red;
                debugView.SleepingShapeColor = Color.Green;
                debugView.LoadContent(graphicsDevice, content);
            }

            if (camera == null)
            {
                Viewport v = graphicsDevice.Viewport;
                camera = new Camera2D(graphicsDevice);
                camera.Position = new Vector2(v.Width / 2, v.Height / 2);
            }
            else camera.ResetCamera();
        }
Beispiel #4
0
 public override void Awake()
 {
     activated = true;
     physicsDebugView = new DebugViewXNA(Physics.world);
     //physicsDebugView.DrawSolidShapes = false;
     physicsDebugView.LoadContent(Application.Instance.GraphicsDevice);
     material = new Material() { name = "Debug material", color = Color.white, renderQueue = 100000, shaderName = "Transparent" };
     base.Awake();
 }
        public void LoadContent(GraphicsDevice graphicsDevice, ContentManager content, SpriteFont font) {
            if (!FarseerEnabled)
                return;

            //_view.LoadContent(graphicsDevice, SceneManager.GlobalContent);
            if (DebugView == null) {
                DebugView = new DebugViewXNA(StaticWorld);
                DebugView.AppendFlags(DebugViewFlags.Shape);
                DebugView.AppendFlags(DebugViewFlags.PolygonPoints);
                DebugView.AppendFlags(DebugViewFlags.PerformanceGraph);
                DebugView.AppendFlags(DebugViewFlags.AABB);
                DebugView.DefaultShapeColor = Color.White;
                DebugView.SleepingShapeColor = Color.LightGray;
                DebugView.LoadContent(graphicsDevice, content, font);
            }
        }
        public PhysicsComponent(Vector2 aGravity)
        {
            ConvertUnits.SetDisplayUnitToSimUnitRatio(24f);

            //lucas smells
            mGravity = aGravity;
            Multiplier = 1;
            mWorld = new World(mGravity);

            mDebugView = new DebugViewXNA(mWorld);
            mDebugView.DefaultShapeColor = Color.White;
            mDebugView.SleepingShapeColor = Color.LightGray;

            mDebugView.LoadContent(MilkShake.Graphics, MilkShake.ConentManager);

            //
            Settings.AllowSleep = false;
        }
        public override void LoadContent()
        {
            base.LoadContent();

            //We enable diagnostics to show get values for our performance counters.
            Settings.EnableDiagnostics = true;

            if (World == null)
            {
                World = new World(Vector2.Zero);
            }
            else
            {
                World.Clear();
            }

            if (DebugView == null)
            {
                DebugView = new DebugViewXNA(World);
                DebugView.RemoveFlags(DebugViewFlags.Shape);
                DebugView.RemoveFlags(DebugViewFlags.Joint);
                DebugView.DefaultShapeColor = Color.White;
                DebugView.SleepingShapeColor = Color.LightGray;
                DebugView.LoadContent(ScreenManager.GraphicsDevice, ScreenManager.Content);
            }

            if (Camera == null)
            {
                Camera = new Camera2D(ScreenManager.GraphicsDevice);
            }
            else
            {
                Camera.ResetCamera();
            }

            if (PauseMenu == null)
            {
                PauseMenu = new PauseScreen(this);
            }

            // Loading may take a while... so prevent the game from "catching up" once we finished loading
            ScreenManager.Game.ResetElapsedTime();
        }
Beispiel #8
0
        public PhysicsSystem(GameScreen screen)
        {
            this.screen = screen;

            GnomicGame game = screen.ParentGame;

            // Todo: pass in a PhysicsSystemSetting with gravity, worldMin and worldMax
            world = new World(
                new Vector2(0.0f, 20.0f),
                new FarseerPhysics.Collision.AABB(Vector2.One * -500.0f, Vector2.One * 500.0f));

            debugView = new DebugViewXNA(world);
            debugView.AppendFlags(DebugViewFlags.Shape);
            debugView.DefaultShapeColor = Color.White;
            debugView.SleepingShapeColor = Color.LightGray;
            debugView.LoadContent(game.GraphicsDevice, game.Content, "GameFont");

            projection = Matrix.CreateOrthographicOffCenter(
                0f,
                ConvertUnits.ToSimUnits(game.ScreenWidth),
                ConvertUnits.ToSimUnits(game.ScreenHeight),
                0f, 0f, 1f);
        }
Beispiel #9
0
        public Physics(Engine engine)
            : base(engine)
        {
            // this should probably never change
              PixelsPerMeter = Global.Configuration.GetFloatConfig("Physics", "PixelsPerMeter");

              World = new World(new Vector2(0.0f, 9.8f));

              DebugView = new DebugViewXNA(World);
              DebugView.LoadContent(Global.Game.GraphicsDevice, Engine.Content);
              uint flags = 0;
              flags += (uint)DebugViewFlags.AABB;
              flags += (uint)DebugViewFlags.CenterOfMass;
              flags += (uint)DebugViewFlags.ContactNormals;
              flags += (uint)DebugViewFlags.ContactPoints;
              flags += (uint)DebugViewFlags.DebugPanel;
              flags += (uint)DebugViewFlags.Joint;
              flags += (uint)DebugViewFlags.Pair;
              flags += (uint)DebugViewFlags.PolygonPoints;
              flags += (uint)DebugViewFlags.Shape;
              DebugView.Flags = (DebugViewFlags)flags;

              DrawOrder = int.MaxValue;
        }
        /// <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();
        }
Beispiel #11
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            _resources.Load(_gameObjectFactory.getAll());

            // TODO: use this.Content to load your game content here

            _screenCenter = new Vector2(_graphics.GraphicsDevice.Viewport.Width / 2f,
                                                _graphics.GraphicsDevice.Viewport.Height / 2f);
            _debugView = new DebugViewXNA(_world);
            _debugView.AppendFlags(DebugViewFlags.DebugPanel);
            _debugView.DefaultShapeColor = Color.Black;
            _debugView.SleepingShapeColor = Color.LightGray;
            _debugView.LoadContent(GraphicsDevice, Content);
        }
Beispiel #12
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            _debugView = new DebugViewXNA(_world);
            _debugView.LoadContent(GraphicsDevice, Content);
            _debugView.RemoveFlags(DebugViewFlags.Controllers);
               _debugView.RemoveFlags(DebugViewFlags.Joint);

            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);
            _fpscounter = new FPScounter(this);
            Mouse.SetPosition(400, 400);
            _cursor = new Cursor(this);

            _introsong = Content.Load<Song>(".\\Audio\\INTRO");

            //--------------------------------------
            //Game STarts here!!!
            //--------------------------------------

            if (Globals.SkipIntro)
            {
               StartPlayingLevel();
            }
            else
            {
                StartTheGame();
            }
        }
Beispiel #13
0
        public virtual void LoadContent(GraphicsDeviceManager dMan, ContentManager cm)
        {
            this.graphics = dMan;
            this.Content = cm;

            // load the map
            mMapLoader.loadMap(Content);

            _font = Content.Load<SpriteFont>("font");
            #if DEBUG
            debugView = new DebugViewXNA(mWorld);
            debugView.AppendFlags(DebugViewFlags.DebugPanel);
            debugView.DefaultShapeColor = Color.White;
            debugView.SleepingShapeColor = Color.LightGray;
            debugView.RemoveFlags(DebugViewFlags.Controllers);
            //debugView.RemoveFlags(DebugViewFlags.Joint);

            debugView.LoadContent(graphics.GraphicsDevice, Content);
            #endif
        }
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            //Create New World with gravity of 10 units, downward.
            MyWorld = new World(Vector2.UnitY * 10);
            bird = Content.Load<Texture2D>("AngryRedBird");
            floor = Content.Load<Texture2D>("blank");

            //camera

            DebugView = new DebugViewXNA(MyWorld);
            DebugView.AppendFlags(DebugViewFlags.Shape);
            DebugView.RemoveFlags(DebugViewFlags.Joint);
            DebugView.DefaultShapeColor = Color.White;
            DebugView.SleepingShapeColor = Color.LightGray;
            DebugView.LoadContent(GraphicsDevice, Content);
            Camera = new Camera2D(GraphicsDevice);

            //Create Floor
            FloorBody = BodyFactory.CreateBody(MyWorld);
            Fixture floorFixture = FixtureFactory.AttachRectangle(ConvertUnits.ToSimUnits(480), ConvertUnits.ToSimUnits(10), 10, Vector2.Zero, FloorBody);
            floorFixture.Restitution = 0.5f;        //Bounceability
            floorFixture.Friction = 0.5f;           //Friction
            FloorBody = floorFixture.Body;          //Get Body from Fixture
            FloorBody.IsStatic = true;              //Floor must be stationary object

            //Create Box, (Note:Different way from above code, just to show it otherwise there is no difference)
            HeroBird = BodyFactory.CreateBody(MyWorld);
            FixtureFactory.AttachRectangle(ConvertUnits.ToSimUnits(50), ConvertUnits.ToSimUnits(50), 10, Vector2.Zero, HeroBird);
            foreach (Fixture fixture in HeroBird.FixtureList)
            {
                fixture.Restitution = 0.5f;
                fixture.Friction = 0.5f;
            }
            HeroBird.BodyType = BodyType.Dynamic;

            //Place floor object to bottom of the screen.
            FloorBody.Position = ConvertUnits.ToSimUnits(new Vector2(240, 700));

            //Place Box on screen, somewhere
            HeroBird.Position = ConvertUnits.ToSimUnits(new Vector2(240, 25));
        }
Beispiel #15
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
        }
        /// <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();
        }
Beispiel #17
0
        public void LoadContent(GraphicsDeviceManager graphics, ContentManager Content)
        {
            this.graphics = graphics;
            this.Content = Content;

            // Initialize camera controls
            _view = Matrix.Identity *
                        Matrix.CreateScale(_cameraZoom);
            _cameraPosition = Vector2.Zero;
            _screenCenter = new Vector2(graphics.GraphicsDevice.Viewport.Width / 2f,
                                                graphics.GraphicsDevice.Viewport.Height / 2f);
            _font = Content.Load<SpriteFont>("font");

            // load players
            mPlayer1.loadShip(Content, graphics);

            // load the map
            mMapLoader.loadMap(Content);

            #if DEBUG
            debugView = new DebugViewXNA(mWorld);
            debugView.AppendFlags(DebugViewFlags.DebugPanel);
            debugView.DefaultShapeColor = Color.White;
            debugView.SleepingShapeColor = Color.LightGray;
            debugView.RemoveFlags(DebugViewFlags.Controllers);
            debugView.RemoveFlags(DebugViewFlags.Joint);

            debugView.LoadContent(graphics.GraphicsDevice, Content);
            #endif
        }
Beispiel #18
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        public void LoadContent()
        {
            _font = Content.Load<SpriteFont>("Courier New");

            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(_graphicsDevice);
            theBackground = new Background();
            theBackground.LoadContent(this.Content);
            _renderManager.LoadContent(Content, _gameObjectManager.GetAll());
            _bloodManager = new BloodManager(Content);

            _state = GameState.Menu;
            _hud = new HeadsUpDisplay(Content);
            _statScreen = new StatScreen(_graphicsDevice, Content);
            _statScreen.Angelwin = Content.Load<Texture2D>("angelwin");
            _statScreen.Devilwin = Content.Load<Texture2D>("devilwin");
            _statScreen.Nowin = Content.Load<Texture2D>("nobodywin");
            _statScreen.Credits = Content.Load<Texture2D>("credits");

            CreateBaby();

            _controls = new Controls(this);
            _controls.Angel = _angel;
            _controls.Baby = _baby;
            _controls.Devil = _devil;

            _floatingScoreManager = new FloatingScoreManager(_font);
            _floatingScoreManager.Add(_devil);
            _floatingScoreManager.Add(_angel);
            _menu = new GameMenu(Content, this, _devil, _angel);
            _gameObjectManager.SpawnItems();

            _reaper = new Reaper(_gameObjectManager.GetReaper(), _effectManager, _baby);

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

            //_ragdoll.LoadContent(Content);

            _debugView = new DebugViewXNA(_world);
            _debugView.AppendFlags(DebugViewFlags.DebugPanel);
            _debugView.DefaultShapeColor = Color.Black;
            _debugView.SleepingShapeColor = Color.LightGray;
            _debugView.LoadContent(_graphicsDevice, Content);
        }
 public Debug(Game game, World world, Play play)
 {
     _physicsDebug = new DebugViewXNA(world);
     _physicsDebug.LoadContent(game.GraphicsDevice, game.Content);
     _physicsDebug.AppendFlags(DebugViewFlags.DebugPanel);
 }
Beispiel #20
0
       public void Initialize(RenderContext context)
       {
           //Create new savedata file if it doesn't exist yet
           if (!File.Exists(SaveDataFile))
           {
               SaveData data = new SaveData();
               data.HighestDistance = 0;

               XmlWriter.SaveScore(data, SaveDataFile);
           }
           SaveScore(); // actually loads the score

           isActive = true;

           m_ViewPort = context.GraphicsDevice.Viewport;

           //Load a font
           TextRenderer.SetFont(context.Content.Load<SpriteFont>("Font/Standard"));

           //Create player an set him at center of screen
           m_StartPos = new Vector2(context.ViewPortSize.X * 0.25f, context.ViewPortSize.Y * 0.25f);
           m_Player = new Player(context, m_StartPos);
           m_Player.Initialize(context);
           m_Player.Translate(m_StartPos);

           context.Player = m_Player;

           //Generate a random level
           m_LevelManager = new LevelManager();
           m_LevelManager.Initialize(context);

           //AddParalaxing backgrounds
           m_BgManager = new BackgroundManager(context);
           m_BgManager.AddBackgound(new Background("background", new Vector2(0, 0), 1.0f, false, context));
           m_BgManager.AddBackgound(new Background("1", new Vector2(60, 20), 1.0f, false, context));
           m_BgManager.AddBackgound(new Background("2", new Vector2(100, 70), 1, false, context));
           m_BgManager.AddBackgound(new Background("3", new Vector2(200, 40), 1, false, context));
           m_BgManager.AddBackgound(new Background("4", new Vector2(300, 50), 1, false, context));
           m_BgManager.AddBackgound(new Background("5", new Vector2(400, 200), 1, false, context));

           #if(DEBUG)
           m_MonoDebug = new DebugViewXNA(context.World);
           m_MonoDebug.AppendFlags(DebugViewFlags.DebugPanel);
           m_MonoDebug.DefaultShapeColor = Color.Red;
           m_MonoDebug.SleepingShapeColor = Color.LightGray;
           m_MonoDebug.LoadContent(context.GraphicsDevice, context.Content);
           #endif

           SoundManager.Play("Background", true);

           HitScreen = new GameSprite("Textures/GUI/hit", context);
           PickScreen = new GameSprite("Textures/GUI/pickupHit", context);
       }             
Beispiel #21
0
 private void InitDebug()
 {
     _debugView = new DebugViewXNA(World);
     _debugView.RemoveFlags(DebugViewFlags.Shape);
     _debugView.RemoveFlags(DebugViewFlags.Joint);
     _debugView.DefaultShapeColor = Color.White;
     _debugView.SleepingShapeColor = Color.LightGray;
     _debugView.LoadContent(GraphicsDevice, Game1.contentManager);
 }
        public MainGameScreen(Game game, SpriteBatch spriteBatch, GraphicsDeviceManager graphicsDeviceManager, ScreenManager screenManager)
            : base(game, spriteBatch, graphicsDeviceManager, screenManager)
        {
            ConvertUnits.DisplayUnitsToSimUnitsRatio = 16f;
            TouchPanel.EnabledGestures = GestureType.Tap | GestureType.FreeDrag | GestureType.Flick | GestureType.Pinch | GestureType.DoubleTap;

            world = new World(gravity);
            game.Services.AddService(typeof(World), world);

            var sphere = new Sphere(game, world, new Vector2(200, 0), 1f);

            var landscapePieces = new string[2];
            for (int i = 0; i < landscapePieces.Length; i++)
            {
                landscapePieces[i] = "Images/Terrain/terrainFull" + i;
            }
            var landscape = new Landscape(game, world, GraphicsDeviceManager.GraphicsDevice.Viewport.Height,
                                          landscapePieces,
                                          Category.Cat11, 1);

            var rope = new Rope(world, graphicsDeviceManager.GraphicsDevice, spriteBatch, new Vector2(200), 100, Color.Brown, new Vector2(970, 100));
            var bridge = new Bridge(world, spriteBatch, graphicsDeviceManager.GraphicsDevice, new Vector2(1548, 235),new Vector2(1858, 222), Color.Brown);
            crosshair = new Crosshair(game, spriteBatch, graphicsDeviceManager.GraphicsDevice.Viewport.Width, graphicsDeviceManager.GraphicsDevice.Viewport.Height);
            //var vehicle = new Vehicle(Game, world, new Vector2(500,150));
            var wheel = new BigWheel(game, world, new Vector2(3651, -150));
            entities = new List<IPlayable>
                           {
                               new ScreenBounds(world, landscape.Width, GraphicsDeviceManager.GraphicsDevice.Viewport.Height),
                               landscape,
                               sphere,
                               //new Helicopter(game,new Vector2(400,400)),
                               //new RotatingPlatform(game,"platform1",new Vector2(600,-100),0,1f),
                               //new StaticPlatform(game,"platform1",new Vector2(600,500),0),
                               //new RotatingPlatform(game,"platform1",new Vector2(600,400),0,10f),
                               //new ElevatorPlatform(game,world,"platform2",new Vector2(400, 300),0,100f,new List<Vector2>{new Vector2(-200, 0), new Vector2(200,0), new Vector2(200, -200), new Vector2(-200,-200)}, 50f),
                               new StaticPlatform(game, world, "platform2", new Vector2(970, 100), 0),
                               //vehicle
                               bridge,
                               rope,
                               new Water(game,spriteBatch, world,new Vector2(2617, 305), 395,80 ),
                               crosshair,
                               wheel,
                               //new ExplosionTrigger(game,world)
                           };
            parallax = new Parallax(game,spriteBatch,ParallaxDirection.Left);
            parallax.AddLayer("Images/Parallax/cloud1", 0.5f, 2);
            parallax.AddLayer("Images/Parallax/cloud2", 0.5f, 5);
            game.Components.Add(parallax);

            camera = new Camera2D(game)
                         {
                             Focus = sphere,
                             MoveSpeed = 10f,
                             Clamp = p => new Vector2(
                                              MathHelper.Clamp(p.X, Game.GraphicsDevice.Viewport.Width / 2f, landscape.Width - Game.GraphicsDevice.Viewport.Width / 2f),
                                              MathHelper.Clamp(p.Y, float.NegativeInfinity, Game.GraphicsDevice.Viewport.Height / 2f)),
                             Scale = 1f
                         };
            game.Components.Add(camera);
            debugView = new DebugViewXNA(world) {DefaultShapeColor = Color.White, SleepingShapeColor = Color.LightGray};
            debugView.LoadContent(graphicsDeviceManager.GraphicsDevice,game.Content);
            debugView.AppendFlags(DebugViewFlags.DebugPanel | DebugViewFlags.Joint | DebugViewFlags.Shape | DebugViewFlags.PerformanceGraph | DebugViewFlags.ContactPoints);

            //bridge.Break(bridge.Length/2);
        }
Beispiel #23
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            _spriteBatch = new SpriteBatch(GraphicsDevice);
            //_rubeScene = new RubeScene(@"..\..\..\..\..\RubeData\cartest.json", Content, GraphicsDevice);
            _rubeScene = new RubeScene(@"..\..\..\..\..\RubeData\radar-vehicle-test.json", Content, GraphicsDevice);
            _camera = new Camera(GraphicsDevice.Viewport);
            _font = Content.Load<SpriteFont>("font");

            _physicsDebug = new DebugViewXNA(_rubeScene.World);
            _physicsDebug.LoadContent(GraphicsDevice, Content);
            _physicsDebug.AppendFlags(DebugViewFlags.Shape);
            _physicsDebug.AppendFlags(DebugViewFlags.Controllers);
            _physicsDebug.AppendFlags(DebugViewFlags.DebugPanel);
            _physicsDebug.AppendFlags(DebugViewFlags.PerformanceGraph);

            _car = new Car();
            _rubeScene.AttachJointControllers(_car, "characterWheel");
            _rubeScene.AttachBodyControllers(_car, "chacterbody");
            _car.Init();
        }
Beispiel #24
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            spriteBatch = new SpriteBatch(GraphicsDevice);

            // for debug view
            DebugView = new DebugViewXNA(physicsSystem.world);
            DebugView.DefaultShapeColor = Color.White;
            DebugView.SleepingShapeColor = Color.LightGray;
            DebugView.AppendFlags(DebugViewFlags.ContactPoints);
            DebugView.AppendFlags(DebugViewFlags.DebugPanel);
            DebugView.RemoveFlags(DebugViewFlags.Joint);
            DebugView.LoadContent(GraphicsDevice, Content);

            // for splitscreen
            SetUpSplitScreen();

            entityManager = new EntityManager();
            representationManager = new RepresentationManager(Content);
            controllerManager = new ControllerManager();

            LevelMap levelMap = Content.Load<LevelMap>("simplelevelmap");
            map = new Map(physicsSystem.world, levelMap, entityManager, representationManager, controllerManager);
            mapRepresentation = new MapRepresentation(map);
            mapRepresentation.LoadContent(Content);
            representationManager.Add(mapRepresentation);

            GameVariables.LevelHeight = map.LevelMap.Height;
            GameVariables.EnemyRespawnDelay = 10f;
            GameVariables.CamCulling = new Vector2(640 * 0.5f, 360 * 0.5f);

            // create the players
            int numPlayers = GameVariables.NumPlayers;
            CreatePlayer((int)PlayerIndex.One);
            if (numPlayers > 1)
            {
                CreatePlayer((int)PlayerIndex.Two);
            }
            if (numPlayers > 2)
            {
                CreatePlayer((int)PlayerIndex.Three);
            }
            if (numPlayers > 3)
            {
                CreatePlayer((int)PlayerIndex.Four);
            }

            map.SetUpTiles();

            // test for a slanted platform
            /*
            Vector2 position = new Vector2(180, 270);
            Vertices vertices = new Vertices();
            vertices.Add(ConvertUnits.ToSimUnits(new Vector2(290, 480)));
            vertices.Add(ConvertUnits.ToSimUnits(new Vector2(578, 384)));
            vertices.Add(ConvertUnits.ToSimUnits(new Vector2(578, 480)));
            Body body = BodyFactory.CreatePolygon(physicsSystem.world, vertices, 1f);
            body.BodyType = BodyType.Static;
            body.Restitution = 0f;
            body.Friction = 0.5f;
            body.CollisionCategories = GameConstants.PlatformCollisionCategory;
             */

            // test for a thin platform
            //Vector2 position = new Vector2(300, 400);
            /*
            Body body = BodyFactory.CreateEdge(physicsSystem.world, ConvertUnits.ToSimUnits(new Vector2(300, 400)), ConvertUnits.ToSimUnits(new Vector2(500, 400)));
            //StaticPhysicsObject physicsObject = new StaticPhysicsObject(this, physicsSystem.world, position, 64, 1);
            //Body body = physicsObject.body;
            body.BodyType = BodyType.Static;
            body.Restitution = 0f;
            body.Friction = 0.5f;
            body.CollisionCategories = GameConstants.PlatformCollisionCategory;
             */
            //oneWayTile = new OneWayGroundTile(physicsSystem.world, position, 64);
            /*
            Vector2 startPosition = new Vector2(268, 400);
            Vector2 endPosition = new Vector2(332, 400);
            Body body = BodyFactory.CreateEdge(physicsSystem.world, ConvertUnits.ToSimUnits(startPosition), ConvertUnits.ToSimUnits(endPosition));
            body.BodyType = BodyType.Static;
            body.Restitution = 0f;
            body.Friction = 0.5f;
             */

            // set player spawn positions from map
            List<Player> players = entityManager.Players;
            foreach (Player player in players)
            {
                player.SpawnPosition = map.PlayerSpawn;
            }

            // spawn the living entities
            entityManager.SpawnLivingEntities();

            tmpTex = Content.Load<Texture2D>("blank");
        }
Beispiel #25
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        public override void Initialize(IServiceProvider services)
        {
            Content = new ContentManager(services);
            Content.RootDirectory = "Content";

            ScreenOffset = Vector2.Zero;

            ScreenManager.Graphics.PreferredBackBufferWidth = Settings.SCREEN_WIDTH;
            ScreenManager.Graphics.PreferredBackBufferHeight = Settings.SCREEN_HEIGHT;

            map1 = new Map();
            player = new Player();

            physicsWorld = new World(new Vector2(0, ConvertUnits.ToSimUnits(600f)));

            //AudioManager.Instance.Initialize(ScreenManager);

            DebugView = new DebugViewXNA(physicsWorld);

            //DebugView.AppendFlags(FarseerPhysics.DebugViewFlags.PolygonPoints);
            //DebugView.AppendFlags(FarseerPhysics.DebugViewFlags.DebugPanel);
            //DebugView.AppendFlags(FarseerPhysics.DebugViewFlags.ContactPoints);
            //DebugView.AppendFlags(FarseerPhysics.DebugViewFlags.AABB);
            DebugView.DefaultShapeColor = Color.Green;
            DebugView.StaticShapeColor = Color.Blue;
            DebugView.KinematicShapeColor = Color.Brown;
            DebugView.SleepingShapeColor = Color.White;
            DebugView.InactiveShapeColor = Color.Yellow;
            DebugView.LoadContent(ScreenManager.Graphics.GraphicsDevice, Content);
        }
Beispiel #26
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            _spriteBatch = new SpriteBatch(GraphicsDevice);

            _world = new World(new Vector2(0,0));

            _debugView = new DebugViewXNA(_world);

               // default is shape, controller, joints
               // we just want shapes to display
               _debugView.RemoveFlags(DebugViewFlags.Controllers);
               _debugView.RemoveFlags(DebugViewFlags.Joint);

               _debugView.LoadContent(GraphicsDevice, Content);

               //_debugView.LoadContent(GraphicsDevice, Content);

             // Create and position our floor
               _floor = BodyFactory.CreateRectangle(
            _world,
            ConvertUnits.ToSimUnits(480),
            ConvertUnits.ToSimUnits(50),
            10f);
            _floor.Position = ConvertUnits.ToSimUnits(300,400);
            _floor.IsStatic = true;
            _floor.Restitution = 0.2f;
            _floor.Friction = 0.2f;

                          box = BodyFactory.CreateRectangle(
               _world,
               ConvertUnits.ToSimUnits(100),
               ConvertUnits.ToSimUnits(100),
               10f,
               new Vector2(ConvertUnits.ToSimUnits(300), ConvertUnits.ToSimUnits(0)));

               box.BodyType = BodyType.Dynamic;
               box.Restitution = 0.2f;
               box.Friction = 0.2f;
        }
        public override void Activate(bool instancePreserved)
        {
            if (!instancePreserved)
            {
                base.Activate(instancePreserved);

                //We enable diagnostics to show get values for our performance counters.
                FarseerPhysics.Settings.EnableDiagnostics = true;

                if (World == null)
                {
                    World = new World(Vector2.Zero);
                }
                else
                {
                    World.Clear();
                }

                if (DebugView == null)
                {
                    if (!Axios.Settings.ScreenSaver)
                    {
                        ContentManager man = new ContentManager(this.ScreenManager.Game.Services, "Content");
                        DebugView = new DebugViewXNA(World);
                        DebugView.RemoveFlags(DebugViewFlags.Shape);
                        DebugView.RemoveFlags(DebugViewFlags.Joint);
                        DebugView.DefaultShapeColor = Color.White;
                        DebugView.SleepingShapeColor = Color.LightGray;
                        DebugView.LoadContent(ScreenManager.GraphicsDevice, man);
                    }
                }

                if (Camera == null)
                {
                    Camera = new Camera2D(ScreenManager.GraphicsDevice);
                }
                else
                {
                    Camera.ResetCamera();
                }

                // Loading may take a while... so prevent the game from "catching up" once we finished loading
                ScreenManager.Game.ResetElapsedTime();
            }
        }
        public EggGameScreen(Game1 game)
            : base(game, game.Camera.Clone())
        {
            ConvertUnits.SetDisplayUnitToSimUnitRatio(64f);

            _eggtastic = game;

            Clips = new Dictionary<string, Clip>();
            Enemies = new List<EnemyEntity>();
            Eggs = new List<EggEntity>();
            QueuedForDisposal = new List<CharacterEntity>();
            QueuedForCreation = new List<CharacterEntity>();

            ScreenSizeDefault = new Vector2(1280, 720);

            GraphicsDevice = game.GraphicsDevice;
            Viewport = GraphicsDevice.Viewport;
            ScreenCenter = new Vector2(ScreenSizeDefault.X / 2f, ScreenSizeDefault.Y / 2f);
            Content = game.Content;

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

            #if !ANDROID
            BackgroundMusic =
                Content.Load<Song>("background-music");
            MediaPlayer.Play(BackgroundMusic);
            MediaPlayer.Volume = 0.5f;
            #endif

            Corners = new Vertices(4);
            Corners.Add(new Vector2(0f));                                           // top-left
            Corners.Add(new Vector2(ScreenSizeDefault.X, 0f));                     // top-right
            Corners.Add(new Vector2(ScreenSizeDefault.X, ScreenSizeDefault.Y));   // bottom-right
            Corners.Add(new Vector2(0f, ScreenSizeDefault.Y));                     // bottom-left

            projection =
                Matrix.CreateOrthographicOffCenter(0f, ConvertUnits.ToSimUnits(ScreenSizeDefault.X),
                                                   ConvertUnits.ToSimUnits(ScreenSizeDefault.Y), 0f, 0f, 1f);

            World = new World(new Vector2(0, 0));
            DebugView = new DebugViewXNA(World);
            DebugView.RemoveFlags(DebugViewFlags.Shape);
            DebugView.DefaultShapeColor = Color.White;
            DebugView.SleepingShapeColor = Color.LightGray;
            DebugView.LoadContent(GraphicsDevice, Content);

            if (Tweak.SHOW_PHYSICS_ON_START)
                EnableOrDisableFlag(DebugViewFlags.Shape);
            Tweak.Init();

            InitialiseClips();

            _enemySpawner = new EnemySpawner(this, Clips["enemy"]);

            // World is 1 screen high, N screens wide
            _border = new Border(World, new Vector2(ScreenSizeDefault.X * PLAY_AREA_WIDTH_IN_SCREENS, ScreenSizeDefault.Y));

            InitialiseLevel();
        }
        //public SpriteClasses.BloodControl.BloodDespawner despawn;
        /// <summary>
        /// Creates a new level, sets up Farseer world object and loads tiles
        /// </summary>
        /// <param name="serviceProvider"></param>
        public Level1ReallyOld(ContentManager serviceProvider, GraphicsDevice graphicDevice)
        {
            FarseerPhysics.Settings.EnableDiagnostics = false;
            FarseerPhysics.Settings.VelocityIterations = 6;
            FarseerPhysics.Settings.PositionIterations = 2;
            FarseerPhysics.Settings.ContinuousPhysics = false;

            content = serviceProvider;
            if (world == null)
            {
                world = new World(new Vector2(0f, 0f));
            }
            else
            {
                world.Clear();
            }

            LoadTiles();
            soundEngine = new SoundEngine(content);

            // create and configure the debug view
            _debugView = new DebugViewXNA(world);
            _debugView.Enabled = true;
            _debugView.AppendFlags(DebugViewFlags.DebugPanel);
            _debugView.DefaultShapeColor = Color.White;
            _debugView.SleepingShapeColor = Color.Lavender;
            _debugView.LoadContent(graphicDevice, content);
            _debugView.AdaptiveLimits = true;
            _debugView.AppendFlags(DebugViewFlags.AABB);
        }
Beispiel #30
0
        public void initializeLevel()
        {
            ConvertUnits.SetDisplayUnitToSimUnitRatio(64);
            if (_currentLevel == null)
                _currentLevel = new Level();
            if (_world == null)
            {
                _world = new World(new Vector2(0f, 12f));
            }
            if (_hero == null)
                _hero = new Player(_world);

            if (_camera == null)
            {
                _camera = new Camera2D(ScreenManager.GraphicsDevice);
                _camera.EnablePositionTracking = true;
                _camera.TrackingBody = _hero._body;
            }
            if (gameTimers == null)
            {
                gameTimers = new TimerManager(ref _world);
            }

            if (_debugView == null)
            {
                _debugView = new DebugViewXNA(_world);
                _debugView.AppendFlags(DebugViewFlags.DebugPanel);
                _debugView.DefaultShapeColor = Color.White;
                _debugView.SleepingShapeColor = Color.LightGray;
                _debugView.LoadContent(ScreenManager.GraphicsDevice, content);
            }
            completedLevel = false;
        }
Beispiel #31
0
        public override void LoadContent()
        {
            base.LoadContent();

            string json = System.IO.File.ReadAllText("Levels\\" + mLevelID + ".txt");

            List<object> output = JsonParser.Parse(json);
            Hashtable level = (Hashtable)output[0];

            //Level Name
            mLevelName = (string)level["name"];

            //Gravity
            mGravity = new Vector2((float)((List<object>)level["Gravity"])[0], (float)((List<object>)level["Gravity"])[1]);

            //Starting Positions
            foreach(List<object> pos in (List<object>)level["starting_positions"])
            {
                mStartingPositions.Add(mStartingPositions.Count, new Vector2((float)pos[0], (float)pos[1]));
            }

            //Create the camera
            mCamera = new Camera2D(ScreenManager.GraphicsDevice);

            //Create the world
            mWorld = new World(mGravity);

            //Save starting poition index
            mStartingPositionIndex = 0;

            //Save starting position
            mStartingPosition = mStartingPositions[mStartingPositionIndex];

            //Get the content manager
            mContentManager = new ContentManager(ScreenManager.Game.Services, "Content");

            //Create the player
            mPlayer = new Player(mWorld, this, mContentManager, Color.White, mStartingPosition);
            mCamera.EnableTracking = true;
            mCamera.EnablePositionTracking = true;
            mCamera.TrackingBody = mPlayer.CamBody;
            mCamera.Jump2Target();

            //Create a test PC
            mTestPC = new PC(mWorld, this, mContentManager, Color.White, mStartingPosition);

            //Create level objects
            foreach(object dobj in (List<object>)level["Objects"])
            {
                Hashtable dict = (Hashtable)dobj;

                if (dict["Type"].Equals("Body"))
                {
                    Body nBody;

                    Hashtable properties = (Hashtable)dict["Properties"];

                    string SpriteClass = (string)properties["SpriteClass"];

                    if (SpriteClass != "" && SpriteClass != null)
                    {
                        nBody = BodyFactory.CreateBody(mWorld, new Vector2((float)((List<object>)properties["Position"])[0], (float)((List<object>)properties["Position"])[1]));
                    }
                    else
                    {
                        nBody = BodyFactory.CreateBody(mWorld, new Vector2((float)((List<object>)properties["Position"])[0], (float)((List<object>)properties["Position"])[1]));
                    }

                    string nTextureName = (string)properties["SpriteTexture"];
                    MaterialType nMaterialType = (MaterialType)Enum.Parse(typeof(MaterialType), (string)properties["MaterialType"]);
                    Color nColor = (Color)Color.White.GetType().GetProperty((string)properties["Color"]).GetValue(null, null);

                    nBody.Position = new Vector2((float)((List<object>)properties["Position"])[0], (float)((List<object>)properties["Position"])[1]);
                    nBody.Rotation = (float)properties["Rotation"];
                    nBody.BodyType = (BodyType)Enum.Parse(typeof(BodyType), (string)properties["BodyType"]);
                    nBody.IsBullet = (bool)properties["IsBullet"];
                    nBody.IsSensor = (bool)properties["IsSensor"];
                    nBody.IsStatic = (bool)properties["IsStatic"];

                    nBody.Mass = (float)properties["Mass"];

                    nBody.Inertia = (float)properties["Inertia"];
                    nBody.Friction = (float)properties["Friction"];
                    nBody.Restitution = (float)properties["Restitution"];
                    nBody.LinearDamping = (float)properties["LinearDamping"];
                    nBody.AngularDamping = (float)properties["AngularDamping"];
                    nBody.FixedRotation = (bool)properties["FixedRotation"];

                    nBody.Awake = (bool)properties["Awake"];
                    nBody.Enabled = (bool)properties["Enabled"];
                    nBody.IgnoreCCD = (bool)properties["IgnoreCCD"];
                    nBody.IgnoreGravity = (bool)properties["IgnoreGravity"];
                    nBody.SleepingAllowed = (bool)properties["SleepingAllowed"];

                    foreach(object fobj in (List<object>)dict["Fixtures"])
                    {
                        Hashtable fixture = (Hashtable)fobj;

                        if(fixture["Shape"].Equals("Rectangle"))
                        {
                            FixtureFactory.AttachRectangle((float)fixture["Width"], (float)fixture["Height"], (float)fixture["Density"], new Vector2((float)((List<object>)fixture["Offset"])[0], (float)((List<object>)fixture["Offset"])[1]), nBody);
                        }
                        else if(fixture["Shape"].Equals("Circle"))
                        {
                            FixtureFactory.AttachCircle((float)fixture["Radius"], (float)fixture["Density"], nBody, new Vector2((float)((List<object>)fixture["Offset"])[0], (float)((List<object>)fixture["Offset"])[1]));
                        }
                        else if(fixture["Shape"].Equals("Ellipse"))
                        {
                            FixtureFactory.AttachEllipse((float)fixture["xRadius"], (float)fixture["yRadius"], (int)fixture["Edges"], (float)fixture["Density"], nBody);
                        }

                    }

                    AddObject(nBody, nMaterialType, nColor, nTextureName);
                }
                else if (dict["Type"].Equals("Fixture"))
                {
                    Hashtable properties = (Hashtable)dict["Properties"];

                    Body nBody = null;

                    if(properties["Shape"].Equals("Rectangle"))
                    {
                        nBody = BodyFactory.CreateRectangle(mWorld, (float)properties["Width"], (float)properties["Height"], (float)properties["Density"]);
                    }
                    else if(properties["Shape"].Equals("Circle"))
                    {
                        nBody = BodyFactory.CreateCircle(mWorld, (float)properties["Radius"], (float)properties["Density"]);
                    }
                    else if(properties["Shape"].Equals("Ellipse"))
                    {
                        nBody = BodyFactory.CreateEllipse(mWorld, (float)properties["xRadius"], (float)properties["yRadius"], (int)properties["Edges"], (float)properties["Density"]);
                    }

                    string SpriteClass = (string)properties["SpriteClass"];
                    string nTextureName = (string)properties["SpriteTexture"];
                    MaterialType nMaterialType = (MaterialType)Enum.Parse(typeof(MaterialType), (string)properties["MaterialType"]);
                    Color nColor = (Color)Color.White.GetType().GetProperty((string)properties["Color"]).GetValue(null, null);

                    nBody.Position = new Vector2((float)((List<object>)properties["Position"])[0], (float)((List<object>)properties["Position"])[1]);
                    nBody.Rotation = (float)properties["Rotation"];
                    nBody.BodyType = (BodyType)Enum.Parse(typeof(BodyType), (string)properties["BodyType"]);
                    nBody.IsBullet = (bool)properties["IsBullet"];
                    nBody.IsSensor = (bool)properties["IsSensor"];
                    nBody.IsStatic = (bool)properties["IsStatic"];

                    nBody.Mass = (float)properties["Mass"];

                    nBody.Inertia = (float)properties["Inertia"];
                    nBody.Friction = (float)properties["Friction"];
                    nBody.Restitution = (float)properties["Restitution"];
                    nBody.LinearDamping = (float)properties["LinearDamping"];
                    nBody.AngularDamping = (float)properties["AngularDamping"];
                    nBody.FixedRotation = (bool)properties["FixedRotation"];

                    nBody.Awake = (bool)properties["Awake"];
                    nBody.Enabled = (bool)properties["Enabled"];
                    nBody.IgnoreCCD = (bool)properties["IgnoreCCD"];
                    nBody.IgnoreGravity = (bool)properties["IgnoreGravity"];
                    nBody.SleepingAllowed = (bool)properties["SleepingAllowed"];

                    AddObject(nBody, nMaterialType, nColor, nTextureName);
                }
                else if ((dict["Type"].Equals("Custom")))
                {
                    Hashtable properties = (Hashtable)dict["Properties"];
                    BaseSprite nSprite;

                    string SpriteClass = (string)properties["SpriteClass"];
                    Vector2 nPos = new Vector2((float)((List<object>)properties["Position"])[0], (float)((List<object>)properties["Position"])[1]);
                    if (SpriteClass == "LevelPortal")
                    {
                        nSprite = new LevelPortal(mWorld, this, mContentManager, Color.White, nPos, LevelPortalCollision, (Hashtable)properties["Config"]);
                    }
                    else
                    {
                        nSprite = null;
                    }

                    AddSpecial(nSprite);
                }
            }

            //Attach the debug view
            DebugView = new DebugViewXNA(mWorld);
            DebugView.RemoveFlags(DebugViewFlags.Shape);
            DebugView.RemoveFlags(DebugViewFlags.Joint);
            DebugView.DefaultShapeColor = Color.White;
            DebugView.SleepingShapeColor = Color.LightGray;
            DebugView.LoadContent(ScreenManager.GraphicsDevice, ScreenManager.Content);

            //Reset time elapsed to account for loading time
            ScreenManager.Game.ResetElapsedTime();
        }