Exemplo n.º 1
0
 private void EnableOrDisableFlag(DebugViewFlags flag)
 {
     if ((DebugView.Flags & flag) == flag)
     {
         DebugView.RemoveFlags(flag);
     }
     else
     {
         DebugView.AppendFlags(flag);
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Allows the screen to handle user input. Unlike Update, this method
        /// is only called when the screen is active, and not when some other
        /// screen has taken the focus.
        /// </summary>
        public virtual void HandleInput(InputState input)
        {
            //Keyboard Input
            if (!input.LastKeyboardState.IsKeyDown(Key.F1) && input.CurrentKeyboardState.IsKeyDown(Key.F1))
            {
                DebugViewEnabled           = !DebugViewEnabled;
                Settings.EnableDiagnostics = DebugViewEnabled;
                if (DebugViewEnabled == false)
                {
                    TxtDebug.Text = "";
                }
            }

            if (!input.LastKeyboardState.IsKeyDown(Key.Escape) && input.CurrentKeyboardState.IsKeyDown(Key.Escape))
            {
                ScreenManager.GoToMainMenu();
            }

            //Mouse
            Point   p        = Transform.Inverse.Transform(new Point(input.CurrentMouseState.X, input.CurrentMouseState.Y));
            Vector2 position = new Vector2((float)p.X, (float)p.Y);

            if (input.CurrentMouseState.IsLeftButtonDown == false && input.LastMouseState.IsLeftButtonDown)
            {
                MouseUp();
            }
            else if (input.CurrentMouseState.IsLeftButtonDown && input.LastMouseState.IsLeftButtonDown == false)
            {
                MouseDown(position);
            }

            MouseMove(position);

            //DebugView
            if (DebugView != null)
            {
                if (DebugViewEnabled)
                {
                    DebugView.AppendFlags(DebugViewFlags.DebugPanel);
                }
                else
                {
                    DebugView.RemoveFlags(DebugViewFlags.DebugPanel);
                }
            }
        }
Exemplo n.º 3
0
        public override void LoadContent()
        {
            base.LoadContent();

            // Make objects fall at 10 meters per second
            World.Gravity = Vector2.UnitY * 10;

            // Create some walls
            InitializeSpace();

            // Create our crate
            InitializeCrate();

            // Turn on debug view to draw entities
            DebugView.Enabled = true;
            DebugView.AppendFlags(DebugViewFlags.DebugPanel);
        }
Exemplo n.º 4
0
        protected override void Initialize()
        {
            World     = new World(Vector2.UnitY * -10 * PhysicsScale);
            DebugView = new DebugView(World);
            DebugView.DefaultShapeColor  = Color.White;
            DebugView.SleepingShapeColor = Color.LightGray;
            DebugView.LoadContent(GraphicsDevice, Content);
            if (Debug.DISPLAY_COLLIDERS)
            {
                DebugView.AppendFlags(DebugViewFlags.DebugPanel);
            }

            ScreenManager = new ScreenManager(this, new GameScreen[] { new Background(), new MainMenu() });
            Components.Add(ScreenManager);

            PhysicsProjectionMatrix = Matrix.CreateOrthographicOffCenter(0, DisplayWidth, DisplayHeight, 0, 0, -100) *
                                      Matrix.CreateScale(PhysicsScale, -PhysicsScale, 1) *
                                      Matrix.CreateTranslation(PhysicsScale, PhysicsScale, 0);
            StandardTransformMatrix = Matrix.CreateTranslation(DisplayWidth / 2, -DisplayHeight / 2, 0) * Matrix.CreateScale(1, -1f, 1);
            ViewMatrix = Matrix.CreateLookAt(Vector3.Zero, Vector3.Forward, Vector3.Up);

            base.Initialize();
        }
Exemplo n.º 5
0
        protected override void Initialize()
        {
            base.Initialize();
            Graphics = GraphicsDevice;

            //Initialize physics
            tainicom.Aether.Physics2D.Settings.MaxPolygonVertices = 16;
            world     = new World(Vector2.Zero);
            debugView = new DebugView(world);
            debugView.AppendFlags(DebugViewFlags.DebugPanel | DebugViewFlags.PolygonPoints);
            debugView.LoadContent(GraphicsDevice, Content);

            //Create player
            player = new Player(Content, CarType.SPORT, world, adjustedSpeed);
            player.DodgeCompleteCallback = DodgeCompleted;
            player.CoinGetCallback       = CoinGet;

            //Create objects
            environment    = new EnvironmentManager(Content, world);
            trafficManager = new TrafficManager(Content, world);

            //Setup graphics
            Lighting.Initialize();
            effect        = Content.Load <Effect>("effect");
            postProcessor = new PostProcessor(spriteBatch, Content.Load <Effect>("desaturate"));

            //Setup GUI
            scoreUI     = new ScoreUI();
            gameOverUI  = new GameOverUI();
            fpsUI       = new FPSUI();
            countdownUI = new CountdownUI();
            titleUI     = new TitleUI();

            //Setup input
            InputManager.Initialize();
        }
Exemplo n.º 6
0
        public void LoadContent()
        {
            _world = new World();

            // enable multithreading
            _world.ContactManager.VelocityConstraintsMultithreadThreshold = 256;
            _world.ContactManager.PositionConstraintsMultithreadThreshold = 256;
            _world.ContactManager.CollideMultithreadThreshold             = 256;

            var entities = Scene.GetEntities(_ => MatchActiveEntitiesAndComponents(_));

            for (int i = 0; i < entities.Count; i++)
            {
                var     entity        = entities[i];
                var     bodyComponent = entity.GetComponent <BodyComponent>();
                Fixture fixture       = null;

                switch (bodyComponent.EntityShape)
                {
                case EntityShape.Circle:
                    fixture = bodyComponent.CreateCircle(bodyComponent.Radius, bodyComponent.Density, Vector2.Zero);
                    break;

                case EntityShape.Ellipse:
                    fixture = bodyComponent.CreateEllipse(bodyComponent.Size.X * 0.5f, bodyComponent.Size.Y * 0.5f, 8, bodyComponent.Density);
                    break;

                case EntityShape.Rectangle:
                    fixture = bodyComponent.CreateRectangle(bodyComponent.Size.X, bodyComponent.Size.Y, bodyComponent.Density, Vector2.Zero);
                    break;

                case EntityShape.Polygon:
                    var vertices = new Vertices(bodyComponent.Vertices);
                    fixture = bodyComponent.CreatePolygon(vertices, bodyComponent.Density);
                    break;
                }

                _world.Add(bodyComponent);

                bodyComponent.Tag      = entity.UniqueId;
                bodyComponent.Position = entity.Position;
                bodyComponent.Rotation = entity.Rotation;

                if (fixture != null)
                {
                    fixture.Restitution = bodyComponent.Restitution;
                    fixture.Friction    = bodyComponent.Friction;
                }
            }
            ;

            if (Scene.GameCore.DebugActive && entities.Any())
            {
                _debugView = new DebugView(_world);
                _debugView.AppendFlags(DebugViewFlags.Shape);
                _debugView.AppendFlags(DebugViewFlags.Joint);
                _debugView.AppendFlags(DebugViewFlags.PerformanceGraph);
                _debugView.AppendFlags(DebugViewFlags.DebugPanel);
                _debugView.DefaultShapeColor  = Color.Orange;
                _debugView.SleepingShapeColor = Color.DodgerBlue;
                _debugView.TextColor          = Color.Black;
                _debugView.StaticShapeColor   = Color.Red;

                _debugView.LoadContent(Scene.GameCore.GraphicsDevice, Scene.GameCore.Content);
            }
        }