/// <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( ) { Maps = SimpleUtils.Create2DArray(1, 1, new Map(MAP_SIZE)); //Maps[0][0].Randomize( ); PlayerPosition = new Point(12, 7); for (uint x = 10; x <= 14; x++) { Maps[0][0][x, 9] = Map.WALL; } Cam = new Camera(new Vector2(0, 0), new Vector2(32f, 32f)); SimpleUtils.Init(GraphicsDevice); base.Initialize( ); }
/// <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( ) { Tuple <Map, Point> tuple = WinUtils.LoadMap("Content/asd.lrmap"); Map = tuple.Item1; Player = new Player(tuple.Item2); Player.SetHero(GraphicsDevice, 1 / 260f); Cam = new Camera(new Vector2(0, 0), new Vector2(32f, 32f)); SimpleUtils.Init(GraphicsDevice); // TODO: Renders will be used for more fust drawing of the background... Later Renders = new RenderTarget2D[4]; for (uint i = 0; i < Renders.Length; i++) { Renders[i] = new RenderTarget2D(GraphicsDevice, Graphics.PreferredBackBufferWidth, Graphics.PreferredBackBufferHeight); } base.Initialize(); }
private static void CopyMessageCodeToServer() { string serverPattern = "SimpleServer/SimpleServer/messageCode"; string serverPath = string.Format("{0}{1}", SimpleUtils.GetBasePath(), serverPattern); string clientPattern = "Client/Assets/messageCode"; string clientPath = string.Format("{0}{1}", SimpleUtils.GetBasePath(), clientPattern); if (!Directory.Exists(serverPath)) { Directory.CreateDirectory(serverPath); } string[] clientMessageFiles = Directory.GetFiles(clientPath, "*.cs"); for (int i = 0; i < clientMessageFiles.Length; i++) { string serverFileName = clientMessageFiles[i].Replace(clientPattern, serverPattern); File.Copy(clientMessageFiles[i], serverFileName, true); } }
private void ShowRouteInfo(RouteInfo routeInfo) { if (tb_Start.InvokeRequired) { this.Invoke(new ShowRouteInfoDelegate(ShowRouteInfo), routeInfo); } else { tb_Start.Text = routeInfo.StartStat; tb_StartTime.Text = SimpleUtils.TimeStamp2DateTime(routeInfo.StartTime).ToString(); tb_End.Text = routeInfo.EndStat; tb_EndTime.Text = SimpleUtils.TimeStamp2DateTime(routeInfo.EndTime).ToString(); tb_Distance.Text = routeInfo.Distance.ToString("F2"); int type = service.CarInfo.Type; double unitCost = service.TollDict[type].UnitCost; double cost = routeInfo.Distance * unitCost; tb_UnitCost.Text = unitCost.ToString("F2"); tb_Total.Text = cost.ToString("F2"); } }
private static void UpdateProto() { string basePath = SimpleUtils.GetBasePath(); string externalExe = string.Format("{0}generator/protogen", basePath); string sourcePath = string.Format("{0}Client/Assets/protoSource/", basePath); string clientPath = string.Format("{0}Client/Assets/protoCode/", basePath); string serverPath = string.Format("{0}SimpleServer/SimpleServer/proto", basePath); string[] allFiles = Directory.GetFiles(sourcePath, "*.proto"); string[] fileNames = new string[allFiles.Length]; for (int i = 0; i < allFiles.Length; i++) { fileNames[i] = allFiles[i].Replace(sourcePath, ""); fileNames[i] = fileNames[i].Replace(".proto", ""); string clientArg = string.Format("-i:{0}{2}.proto -o:{1}{2}.cs", sourcePath, clientPath, fileNames[i]); string serverArg = string.Format("-i:{0}{2}.proto -o:{1}/{2}.cs", sourcePath, serverPath, fileNames[i]); UnityEngine.Debug.Log(string.Format("{0} {1}", externalExe, clientArg)); SimpleUtils.ProcessProto(externalExe, clientArg); SimpleUtils.ProcessProto(externalExe, serverArg); } }
/// <summary> /// Allows the game to run logic such as updating the world, /// checking for collisions, gathering input, and playing audio. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Update(GameTime gameTime) { if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState( ).IsKeyDown(Keys.Escape)) { Exit( ); } MouseState MouseState = Mouse.GetState( ); KeyboardState KeyboardState = Keyboard.GetState( ); MousePreviousPosition = MousePosition; MousePosition = MouseState.Position; if (MouseState.RightButton == ButtonState.Pressed) { Cam.Position = Cam.Position + (MousePreviousPosition - MousePosition).Vector2( ) / Cam.Scale; } Vector2 MouseWorldPosition = MousePosition.Vector2( ) / Cam.Scale + Cam.Position; SelectedMap = MouseWorldPosition.FloorToPoint( ) / MAP_SIZE; SelectedPoint = MouseWorldPosition.FloorToPoint( ).Mod(MAP_SIZE); if (MouseWorldPosition.X < 0) { SelectedMap.X -= 1; SelectedPoint.X = MAP_SIZE.X + SelectedPoint.X; } if (MouseWorldPosition.Y < 0) { SelectedMap.Y -= 1; SelectedPoint.Y = MAP_SIZE.Y + SelectedPoint.Y; } if (KeyboardState.IsKeyDown(Keys.D1)) { CurrentValue = Map.WALL; } else if (KeyboardState.IsKeyDown(Keys.D2)) { CurrentValue = Map.LEFT_SHELF; } else if (KeyboardState.IsKeyDown(Keys.D3)) { CurrentValue = Map.RIGHT_SHELF; } else if (KeyboardState.IsKeyDown(Keys.Tab)) { CurrentValue = Map.EMPTY; } if (MouseState.LeftButton == ButtonState.Pressed) { { // TODO: Refactor and optimize this code-block later while (SelectedMap.X < 0) { Map[][] newMaps = SimpleUtils.Create2DArray <Map>((uint)Maps.Length + 1, (uint)Maps[0].Length, null); for (uint i = 0; i < Maps.Length; i++) { for (uint j = 0; j < Maps[0].Length; j++) { newMaps[i + 1][j] = Maps[i][j]; } } for (uint y = 0; y < newMaps[0].Length; y++) { newMaps[0][y] = new Map(MAP_SIZE); } Maps = newMaps; Cam.Position += new Vector2(MAP_SIZE.X, 0f); SelectedMap.X += 1; PlayerPosition.X += MAP_SIZE.X; } while (SelectedMap.Y < 0) { Map[][] newMaps = SimpleUtils.Create2DArray <Map>((uint)Maps.Length, (uint)Maps[0].Length + 1, null); for (uint i = 0; i < Maps.Length; i++) { for (uint j = 0; j < Maps[0].Length; j++) { newMaps[i][j + 1] = Maps[i][j]; } } for (uint x = 0; x < newMaps.Length; x++) { newMaps[x][0] = new Map(MAP_SIZE); } Maps = newMaps; Cam.Position += new Vector2(0f, MAP_SIZE.Y); SelectedMap.Y += 1; PlayerPosition.Y += MAP_SIZE.X; } while (SelectedMap.X >= Maps.Length) { Map[][] newMaps = SimpleUtils.Create2DArray <Map>((uint)Maps.Length + 1, (uint)Maps[0].Length, null); for (uint i = 0; i < Maps.Length; i++) { for (uint j = 0; j < Maps[0].Length; j++) { newMaps[i][j] = Maps[i][j]; } } for (uint y = 0; y < newMaps[0].Length; y++) { newMaps[Maps.Length][y] = new Map(MAP_SIZE); } Maps = newMaps; } while (SelectedMap.Y >= Maps[0].Length) { Map[][] newMaps = SimpleUtils.Create2DArray <Map>((uint)Maps.Length, (uint)Maps[0].Length + 1, null); for (uint i = 0; i < Maps.Length; i++) { for (uint j = 0; j < Maps[0].Length; j++) { newMaps[i][j] = Maps[i][j]; } } for (uint x = 0; x < newMaps.Length; x++) { newMaps[x][Maps[0].Length] = new Map(MAP_SIZE); } Maps = newMaps; } } Point pos = SelectedMap * MAP_SIZE + SelectedPoint; if (!pos.Equals(PlayerPosition) && !pos.Equals(PlayerPosition + new Point(0, 1))) { Maps[SelectedMap.X][SelectedMap.Y][(uint)SelectedPoint.X, (uint)SelectedPoint.Y] = CurrentValue; } } if (KeyboardState.IsKeyDown(Keys.S) && !PreviousKeyboardState.IsKeyDown(Keys.S)) { Map mapToSave = Map.ConvertToBig(Maps); WinUtils.Save(mapToSave, PlayerPosition); } if (KeyboardState.IsKeyDown(Keys.O) && !PreviousKeyboardState.IsKeyDown(Keys.O)) { Tuple <Map, Point> mapToLoad = WinUtils.LoadMap( ); Maps = Map.ConvertFromBig(mapToLoad.Item1, MAP_SIZE); PlayerPosition = mapToLoad.Item2; Cam.Position = PlayerPosition.ToVector2( ) - new Vector2( Graphics.PreferredBackBufferWidth / Cam.Scale.X / 2, Graphics.PreferredBackBufferHeight / Cam.Scale.Y / 2); } PreviousKeyboardState = KeyboardState; base.Update(gameTime); }