public FarseerPhysicsGame()
        {
            Window.Title = "Farseer Samples Framework";
            _graphics = new GraphicsDeviceManager(this);
            _graphics.PreferMultiSampling = true;
            #if WINDOWS || XBOX
            _graphics.PreferredBackBufferWidth = 1280;
            _graphics.PreferredBackBufferHeight = 720;
            ConvertUnits.SetDisplayUnitToSimUnitRatio(24f);
            IsFixedTimeStep = true;
            #elif WINDOWS_PHONE
            _graphics.PreferredBackBufferWidth = 800;
            _graphics.PreferredBackBufferHeight = 480;
            ConvertUnits.SetDisplayUnitToSimUnitRatio(16f);
            IsFixedTimeStep = false;
            #endif
            #if WINDOWS
            _graphics.IsFullScreen = false;
            #elif XBOX || WINDOWS_PHONE
            _graphics.IsFullScreen = true;
            #endif

            Content.RootDirectory = "Content";

            //new-up components and add to Game.Components
            ScreenManager = new ScreenManager(this);
            Components.Add(ScreenManager);

            FrameRateCounter frameRateCounter = new FrameRateCounter(ScreenManager);
            frameRateCounter.DrawOrder = 101;
            Components.Add(frameRateCounter);
        }
        /// <summary>
        ///   Constructs a new input state.
        /// </summary>
        public InputHelper(ScreenManager manager)
        {
            _currentKeyboardState = new KeyboardState();
            _currentGamePadState = new GamePadState();
            _currentMouseState = new MouseState();
            _currentVirtualState = new GamePadState();

            _lastKeyboardState = new KeyboardState();
            _lastGamePadState = new GamePadState();
            _lastMouseState = new MouseState();
            _lastVirtualState = new GamePadState();

            _manager = manager;

            _cursorIsVisible = false;
            _cursorMoved = false;
            #if WINDOWS_PHONE
            _cursorIsValid = false;
            #else
            _cursorIsValid = true;
            #endif
            _cursor = Vector2.Zero;

            _handleVirtualStick = false;
        }
 public FrameRateCounter(ScreenManager screenManager)
     : base(screenManager.Game)
 {
     _screenManager = screenManager;
     _format = new NumberFormatInfo();
     _format.NumberDecimalSeparator = ".";
     #if XBOX
     _position = new Vector2(55, 35);
     #else
     _position = new Vector2(30, 25);
     #endif
 }
Example #4
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);
        }