Exemplo n.º 1
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()
        {
            spriteBatch = new SpriteBatch(GraphicsDevice);
            Services.AddService(typeof(SpriteBatch), spriteBatch);

            player = new Player(this);
            var commands = new IConsoleCommand[] { new MovePlayerCommand(player), new RotatePlayerDegreesCommand(player) };
            console = new GameConsole(this, spriteBatch, commands, new GameConsoleOptions
                                                                       {
                                                                           Font = Content.Load<SpriteFont>("GameFont"),
                                                                           FontColor = Color.LawnGreen,
                                                                           Prompt = "~>",
                                                                           PromptColor = Color.Crimson,
                                                                           CursorColor = Color.OrangeRed,
                                                                           BackgroundColor = new Color(Color.Black,150),
                                                                           PastCommandOutputColor = Color.Aqua,
                                                                           BufferColor = Color.Gold
                                                                       });
            console.AddCommand("rotRad", a =>
                                             {
                                                 var angle = float.Parse(a[0]);
                                                 player.Angle = angle;
                                                 return String.Format("Rotated the player to {0} radians", angle);
                                             });
            base.Initialize();
        }
Exemplo n.º 2
0
        protected override void Initialize()
        {
            graphics.PreferMultiSampling = true;
            graphics.PreferredBackBufferWidth = WINDOWED_WIDTH;
            graphics.PreferredBackBufferHeight = WINDOWED_HEIGHT;
            graphics.IsFullScreen = false;
            graphics.ApplyChanges();

            spriteBatch = new SpriteBatch(GraphicsDevice);
            console = new GameConsole(this, spriteBatch, new GameConsoleOptions()
            {
                OpenOnWrite = false,
                Prompt = ">",
                Height = 500,
                ToggleKey = Keys.Escape
            });

            console.AddCommand("load",
                args =>
                {
                    missionFile = "../../../../../missions/" + args[0] + ".json";
                    ClearWorld();
                    InitSim(false);
                    return "Mission loaded.";
                }, "Load a mission file");

            console.AddCommand("experiment",
                args =>
                {
                    if (args[0] == "random")
                        new SmootherExperiment(this, expFile, 100);
                    else if (args[0] == "parking")
                        new ParkingExperiment(this, world, expFile);
                    else
                        return "Experiment not found.";

                    return "Experiment started.";
                }, "Run an experiment");

            console.AddCommand("antialias",
                args =>
                {
                    graphics.PreferMultiSampling = !graphics.PreferMultiSampling;
                    graphics.ApplyChanges();
                    return "Antialias " + (graphics.PreferMultiSampling ? "on" : "off");
                }, "Toggles antialias");

            console.AddCommand("debug",
                 args =>
                 {
                     showDebugInfo = !showDebugInfo;
                     return "Debug " + (showDebugInfo ? "on" : "off");
                 }, "Toggles the debug info");

            console.AddCommand("dashboard",
                 args =>
                 {
                     showDashboard = !showDashboard;
                     return "Dashboard " + (showDashboard ? "on" : "off");
                 }, "Toggles the dashboard");

            console.AddCommand("param",
                args =>
                {
                    if (args.Length < 1) return "";

                    switch (args[0].ToLower())
                    {
                        case "smoother":
                            return Smoother.HandleParamCommand(args);
                        default:
                            return "";
                    }
                }, "Prints or updates parameters");

            console.AddCommand("smooth",
                args =>
                {
                    if (pathSmoothDone)
                    {
                        bg = new Thread(() =>
                            {
                                DateTime now = DateTime.Now;
                                smoothedPath = Smoother.Smooth(astar.Path, grid);
                                int numUnsafe = Smoother.UnsafeIndices != null ? Smoother.UnsafeIndices.Count : 0;
                                console.WriteLine("Smoothing Time: " + Math.Round((DateTime.Now - now).TotalMilliseconds) + " ms (" + Smoother.NumIterations + " iterations, " + Smoother.Change + "m, " + numUnsafe + " unsafe points)");
                                controller = new StanleyFSMController(smoothedPath, goalPose);
                            });
                        bg.IsBackground = true;
                        bg.Priority = ThreadPriority.Lowest;
                        bg.Start();
                    }

                    return "";
                }, "Smooths the path using the current parameters");

            console.AddCommand("smoothing",
                args =>
                {
                    smoothing = !smoothing;
                    return "Smoothing " + (smoothing ? "on" : "off");
                }, "Toggles smoothing"
            );

            dashboard = new Dashboard(this);
            world = new World(Vector2.Zero);
            car = new Car(world, new Pose());
            camera = new Camera(MathHelper.PiOver4, GraphicsDevice.Viewport.AspectRatio, 0.1f, 1000f);
            camera.Position = new Vector3(75f, 75f, 180f);

            base.Initialize();
        }