示例#1
0
        public DefaultGame()
        {
            _deviceManager  = new GraphicsDeviceManager(this);
            IsFixedTimeStep = true;
            _deviceManager.GraphicsProfile           = GraphicsProfile.HiDef;
            _deviceManager.IsFullScreen              = false;
            _deviceManager.PreferredBackBufferWidth  = 800;
            _deviceManager.PreferredBackBufferHeight = 600;
            _deviceManager.ApplyChanges();
            GraphicsDevice.RasterizerState = RasterizerState.CullCounterClockwise;
            GraphicsDevice.BlendState      = BlendState.AlphaBlend;
            Content.RootDirectory          = "Content";

            _batch = new SpriteBatch(GraphicsDevice);
            using (Stream stream = File.OpenRead(@"Content\square.png"))
            {
                _square = Texture2D.FromStream(GraphicsDevice, stream);
            }
            _breakSound  = Content.Load <SoundEffect>("Slap");
            _bounceSound = Content.Load <SoundEffect>("Jump");

            _world = new World(1000);

            _runner = new DefaultParallelRunner(Environment.ProcessorCount);
            _system = new SequentialSystem <float>(
                new GameSystem(_world),
                new PlayerSystem(_world, Window),
                new BallToBarSystem(_world, Window),
                new VelocitySystem(_world, _runner),
                new CollisionSystem(_world),
                new BallBoundSystem(_world),
                new PositionSystem(_world, _runner),
                new DrawSystem(_batch, _square, _world));

            _world.Subscribe <BrickBrokenMessage>(On);
            _world.Subscribe <BarBounceMessage>(On);

            Level1.CreatePlayer(_world);
        }