Ejemplo n.º 1
0
        public Physics(Game game, Camera2D camera)
            : base(game)
        {
            World = new World(new Vector2(0f, 10f));
            debugView = new DebugViewXNA(World);
            debugView.AppendFlags(DebugViewFlags.Shape);
            debugView.AppendFlags(DebugViewFlags.ContactNormals);
            debugView.AppendFlags(DebugViewFlags.PolygonPoints);

            this.camera = camera;

            ShowDebug = false;
        }
Ejemplo n.º 2
0
        public Physics(Vector2 gravity, Vector2 min, Vector2 max)
        {
            m_World = new World(gravity, new FarseerPhysics.Collision.AABB(ref min, ref max));
            m_View = new DebugViewXNA(m_World);
            m_View.Flags |= DebugViewFlags.PerformanceGraph;
            m_View.AppendFlags(DebugViewFlags.Shape);
            m_View.AppendFlags(DebugViewFlags.DebugPanel);
            m_View.AppendFlags(DebugViewFlags.Joint);
            m_View.AppendFlags(DebugViewFlags.ContactPoints);
            m_View.AppendFlags(DebugViewFlags.ContactNormals);
            m_View.AppendFlags(DebugViewFlags.Controllers);
            m_View.AppendFlags(DebugViewFlags.CenterOfMass);
            m_View.AppendFlags(DebugViewFlags.AABB);

            m_View.DefaultShapeColor = Color.Green;
            m_View.SleepingShapeColor = Color.LightGray;

            //floor
            BodyFactory.CreateEdge(m_World, new Vector2(min.X, min.Y), new Vector2(max.X, min.Y));

            //right side
            BodyFactory.CreateEdge(m_World, new Vector2(max.X, min.Y), new Vector2(max.X, max.Y));

            //left side
            BodyFactory.CreateEdge(m_World, new Vector2(min.X, min.Y), new Vector2(min.X, max.Y));

            //top
            BodyFactory.CreateEdge(m_World, new Vector2(min.X, max.Y), new Vector2(max.X, max.Y));
        }
Ejemplo n.º 3
0
        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();
        }
Ejemplo n.º 4
0
        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);
            }
        }
Ejemplo n.º 5
0
        public Physics(Vector2 gravity, Vector2 min, Vector2 max)
        {
            m_World = new World(gravity, new FarseerPhysics.Collision.AABB(ref min, ref max));
            m_View = new DebugViewXNA(m_World);
            m_View.Flags |= DebugViewFlags.PerformanceGraph;
            m_View.AppendFlags(DebugViewFlags.Shape);
            m_View.AppendFlags(DebugViewFlags.DebugPanel);
            m_View.AppendFlags(DebugViewFlags.Joint);
            m_View.AppendFlags(DebugViewFlags.ContactPoints);
            m_View.AppendFlags(DebugViewFlags.ContactNormals);
            m_View.AppendFlags(DebugViewFlags.Controllers);
            m_View.AppendFlags(DebugViewFlags.CenterOfMass);
            m_View.AppendFlags(DebugViewFlags.AABB);

            m_View.DefaultShapeColor = Color.Green;
            m_View.SleepingShapeColor = Color.LightGray;

            m_min = min;
            m_max = max;
        }
Ejemplo n.º 6
0
        public GameEnvironment(Controller ctrl)
            : base(ctrl)
        {
            //Frame rate variables initialize
            frameTime = 0;
            fps = 30;
            frameCounter = 0;

            // Create a new SpriteBatch, which can be used to draw textures.
            m_spriteBatch = new SpriteBatch(ctrl.GraphicsDevice);

            CollisionWorld = new Physics.Dynamics.World(Vector2.Zero);

            m_debugView = new Physics.DebugViewXNA(CollisionWorld);
            m_debugView.AppendFlags(Physics.DebugViewFlags.DebugPanel);

            // Create collision notification callbacks.
            CollisionWorld.ContactManager.PreSolve += PreSolve;

            // TODO: Scale to physics world.
            m_debugPhysicsMatrix = Matrix.CreateOrthographicOffCenter(0.0f, m_controller.GraphicsDevice.Viewport.Width * k_physicsScale, m_controller.GraphicsDevice.Viewport.Height * k_physicsScale, 0.0f, -1.0f, 1.0f);
        }
Ejemplo n.º 7
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);
        }
Ejemplo n.º 8
0
 public Debug(Game game, World world, Play play)
 {
     _physicsDebug = new DebugViewXNA(world);
     _physicsDebug.LoadContent(game.GraphicsDevice, game.Content);
     _physicsDebug.AppendFlags(DebugViewFlags.DebugPanel);
 }
Ejemplo n.º 9
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");
        }
Ejemplo n.º 10
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);
       }             
Ejemplo n.º 11
0
        protected override void Update(GameTime gameTime)
        {
            if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape))
            {
                Exit();
            }

            // Show the physics shape or hide it
            if (Keyboard.GetState().IsKeyDown(Keys.F2) && oldKeys.IsKeyUp(Keys.F2))
            {
                showshapes = !showshapes;

                if (showshapes == true)
                {
                    PhysicsDebugView.AppendFlags(DebugViewFlags.Shape);
                }
                else
                {
                    PhysicsDebugView.RemoveFlags(DebugViewFlags.Shape);
                }
            }

            // Animate light position
            _light.Position =
                new Vector2(400f, 240f) + // Offset origin
                new Vector2(              // Position around origin
                    (float)Math.Cos(gameTime.TotalGameTime.TotalSeconds),
                    (float)Math.Sin(gameTime.TotalGameTime.TotalSeconds)) * 240f;

            // The rotation and the position of all Hulls will be updated
            // according to the physics body rotation and position
            foreach (Hull h in tBodyHull)
            {
                h.Rotation = tBody.Rotation;
                h.Position = ConvertUnits.ToDisplayUnits(tBody.Position);
            }

            // Get the mouse position
            Vector2 position = new Vector2(Mouse.GetState().X, Mouse.GetState().Y);

            // If left mouse button clicked then create a fixture for physics manipulation
            if (Mouse.GetState().LeftButton == ButtonState.Pressed && _fixedMouseJoint == null)
            {
                Fixture savedFixture = world.TestPoint(ConvertUnits.ToSimUnits(position));
                if (savedFixture != null)
                {
                    Body body = savedFixture.Body;
                    _fixedMouseJoint          = new FixedMouseJoint(body, ConvertUnits.ToSimUnits(position));
                    _fixedMouseJoint.MaxForce = 1000.0f * body.Mass;
                    world.AddJoint(_fixedMouseJoint);
                    body.Awake = true;
                }
            }
            // If left mouse button releases then remove the fixture from the world
            if (Mouse.GetState().LeftButton == ButtonState.Released && _fixedMouseJoint != null)
            {
                world.RemoveJoint(_fixedMouseJoint);
                _fixedMouseJoint = null;
            }
            if (_fixedMouseJoint != null)
            {
                _fixedMouseJoint.WorldAnchorB = ConvertUnits.ToSimUnits(position);
            }

            // We update the world
            world.Step((float)gameTime.ElapsedGameTime.TotalMilliseconds * 0.001f);

            // Update the keypress
            oldKeys = Keyboard.GetState();
            base.Update(gameTime);
        }
Ejemplo n.º 12
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
        }
Ejemplo n.º 13
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);

            //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));
        }
Ejemplo n.º 14
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
        }
Ejemplo n.º 15
0
        //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);
        }
Ejemplo n.º 16
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);
        }
Ejemplo n.º 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
        }
Ejemplo n.º 18
0
        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);
        }
Ejemplo n.º 19
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);
        }
Ejemplo n.º 20
0
        /// <summary>
        /// Load graphics content for the game.
        /// </summary>
        public override void Activate(bool instancePreserved)
        {
            if (!instancePreserved)
            {
                if (content == null)
                    content = new ContentManager(ScreenManager.Game.Services, "Content");

                #region Instantiating Fields:

                gameFont = ScreenManager.Font;

                world = new GameWorld(9.8f * Vector2.UnitY, 0.4f, new Camera2D(ScreenManager.GraphicsDevice));

                player = new Player(this, world, camera);
                player.Initialize();
                player.Position = new Vector2(0, 50);

                scenario = new Scenario(this, world, camera);
                scenario.Initialize();

                camera.Zoom = 7f;
                camera.trakingSpeedMult = new Vector2(0.5f, 0.25f);
                camera.trakingOffset = new Vector2(0f, -2f);
                camera.TrackingBody = player.getBody(0);
                camera.Update(new GameTime());
                camera.Jump2Target();

                debugView = new DebugViewXNA(world);
                debugView.AppendFlags(DebugViewFlags.DebugPanel | DebugViewFlags.PerformanceGraph);
                debugView.AppendFlags(DebugViewFlags.ContactNormals | DebugViewFlags.ContactPoints);
                debugView.DefaultShapeColor = Color.Black;
                debugView.SleepingShapeColor = Color.LightGray;

                collectibles = new List<Collectible>();
                myEffect = new ParticleEffect();
                myRenderer = new SpriteBatchRenderer
                {
                    GraphicsDeviceService = (IGraphicsDeviceService)ScreenManager.Game.Services.GetService(typeof(IGraphicsDeviceService))
                };
                sbRenderer = new SpriteBatchRenderer
                {
                    GraphicsDeviceService = (IGraphicsDeviceService)ScreenManager.Game.Services.GetService(typeof(IGraphicsDeviceService))
                };
                #endregion

                loadContent(content);

                ScreenManager.Game.ResetElapsedTime();
            }
        }
Ejemplo n.º 21
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();
        }
Ejemplo n.º 22
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;
        }
Ejemplo n.º 23
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>
        protected override void Initialize()
        {
            //Initialize Physics Objects
            world = new World(new Vector2(0, 20));
            debugViewXNA = new DebugViewXNA(world);
            debugViewXNA.AppendFlags(DebugViewFlags.Shape);
            debugViewXNA.AppendFlags(DebugViewFlags.AABB);
            debugViewXNA.AppendFlags(DebugViewFlags.CenterOfMass);
            debugViewXNA.AppendFlags(DebugViewFlags.DebugPanel);

            //Initialize Singleton Objects
            spriteBatch = new SpriteBatch(GraphicsDevice);
            Services.AddService(typeof(SpriteBatch), spriteBatch);
            font = Content.Load<SpriteFont>("myFont");
            staticEntities = new List<Entity>();

            //Set camera variables
            cam = new Camera2D(GraphicsDevice);
            cam.Zoom = 0.7f;
            Services.AddService(typeof(Camera2D), cam);
            //  cam.Zoom = 0.3f;

            //Initialize Entities
            player1 = new Player(this, ashe, cam, krypton);
            player2 = new DummyPlayer(this, ashe2, cam);

            //Initialize Characters, they must be created after the players but before player.Initialize()
            ashe = new Ashe(player1);
            ashe2 = new Ashe(player2);

            player2.Initialize(ashe2);
            player2.setTeam(Creature.Team.Red);

            player1.Initialize(ashe);
            player1.setTeam(Creature.Team.Blue);

            krypton.Initialize();
            //Initialize Test Objects

            base.Initialize();
        }