/// <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(); }
public GameConsoleComponent(GameConsole console, Game game, SpriteBatch spriteBatch) : base(game) { this.console = console; EventInput.Initialize(game.Window); this.spriteBatch = spriteBatch; AddPresetCommands(); inputProcesser = new InputProcessor(new CommandProcesser()); inputProcesser.Open += (s, e) => renderer.Open(); inputProcesser.Close += (s, e) => renderer.Close(); renderer = new Renderer(game, spriteBatch, inputProcesser); var inbuiltCommands = new IConsoleCommand[] {new ClearScreenCommand(inputProcesser),new ExitCommand(game),new HelpCommand()}; GameConsoleOptions.Commands.AddRange(inbuiltCommands); }
protected override void LoadContent() { this.SpriteBatch = new SpriteBatch(this.Graphics.GraphicsDevice); this.GameConsole = new GameConsole(this, this.SpriteBatch); // Create the game console. this.GameConsole.Options.PastCommandColor = Color.Green; this.GameConsole.Options.PastCommandOutputColor = Color.Red; // Create the stream writer for Win32 console redirection. this.Writer = new XNAConsoleStreamWriter(this.GameConsole); // Redirect Win32 console output to the game console. Console.SetOut(this.Writer); base.LoadContent(); this.InitalizeScreens(); this.InitalizeConsoleCommands(); }
/// <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); grid = new Grid(this, 20) {DrawGridLines = true}; cursor = new MouseCursor(this, spriteBatch, Content.Load<Texture2D>("cursor")); cursor.LeftClick += (o, e) => HandleLeftButton(e.Position); cursor.LeftDrag += (o, e) => HandleLeftButton(e.Position); cursor.RightClick += (o, e) => HandleRightButton(e.Position); cursor.RightDrag += (o, e) => HandleRightButton(e.Position); aStar = new AStar(this, grid, new ManhattanDistance()); aStar.PathFound += (o, e) => { console.WriteLine(String.Format("Heuristic: {0}; Path length: {1}; Total Explored length: {2}", aStar.Heuristic.Name, e.TotalPathLength, e.TotalExplored)); foreach (var cell in e.Path) { cell.Type = GridCellType.Path; } }; Components.Add(cursor); gameObjects.Add(grid); gameObjects.Add(aStar); var singleStroke = new SingleKeyStroke(this); singleStroke.KeyDown += (o, e) => { if (console.Opened) { return; } if (e.Key == Keys.Space) { grid.DrawGridLines = !grid.DrawGridLines; } if (e.Key == Keys.Enter) { grid.Reset(); aStar.Start(); } }; Components.Add(singleStroke); console = new GameConsole(this, spriteBatch, new IConsoleCommand[] { new DisplayGridlinesCommand(grid), new ResetGridCommand(grid), new CellSizeCommand(grid), new SetHeuristicCommand(aStar), new FullScreenCommand(graphics) }, new GameConsoleOptions{Prompt=">", FontColor = Color.GreenYellow}); base.Initialize(); }
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(); }
public XNAConsoleStreamWriter(GameConsole output) { _output = output; _messageQueue = new Queue<string>(); }