コード例 #1
0
ファイル: Bridge.cs プロジェクト: dreasgrech/FPE3Sandbox
        public Bridge(World world, SpriteBatch spriteBatch, GraphicsDevice device, Vector2 worldAnchorA, Vector2 worldAnchorB, Color ropeColor)
        {
            Length = Vector2.Distance(worldAnchorA, worldAnchorB);

            rope = new Rope(world, device, spriteBatch, worldAnchorA, Length, ropeColor, worldAnchorA, worldAnchorB);

            foreach (var segment in rope.Segments)
            {
                segment.Body.CollisionCategories = Category.Cat9;
                segment.Body.CollidesWith = ~CollisionCategoriesSettings.Terrain;
            }
        }
コード例 #2
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);
        }