private void CreateBoard(int width, int height) { _allTileBackgrounds = new TileBackground[width, height]; var offset = tileBackgroundPrefab.BoundsSize; var startPos = transform.position; for (int y = 0; y < height; y++) { for (int x = 0; x < width; x++) { Vector2 pos = new Vector2(startPos.x + (offset.x * x), startPos.y + (offset.y * y)); TileBackground instantiated = PoolManager.Instance.GetPooledObjectByTag <TileBackground>(tileBackgroundPrefab.tag); Tile tile = GetTileFromPool(_currentLevel.Grid[x, y], instantiated.transform); tile.SetArrayIndex(x, y); instantiated.transform.position = pos; instantiated.transform.localScale = tileBackgroundPrefab.transform.localScale; instantiated.transform.SetParent(transform); instantiated.SetResetTileBackgroundEvent(OnResetTileBackgroundEvent); instantiated.SetTile(tile); _allTileBackgrounds[x, y] = instantiated; } } UpdateBoardPosition(); }
private void SwipeTiles(Vector2Int current, Vector2Int target) { TileBackground currentTileBackground = GetTileBackgroundAtIndex(current); TileBackground targetTileBackground = GetTileBackgroundAtIndex(target); if (currentTileBackground == null || targetTileBackground == null) { return; } _currentTile = currentTileBackground.GetTile(); _targetTile = targetTileBackground.GetTile(); if (_targetTile.IsCompleted) { return; } OnSwipeStartEvent.Invoke(); currentTileBackground.SetTile(_targetTile); targetTileBackground.SetTile(_currentTile); _currentTile.SetArrayIndex(target.x, target.y); _targetTile.SetArrayIndex(current.x, current.y); _currentTile.SetParent(targetTileBackground.transform); _targetTile.SetParent(currentTileBackground.transform); _currentTile.DoMove(tweenTime); _targetTile.DoMove(tweenTime); StartCoroutine(WaitForSwipe(tweenTime * 1.05f)); }
//-[Methods]------------------------------------------------------------------------------------------------------------------------------------------ /// <summary>saves the UserTrace to a directory</summary> /// <param name="ProjectDir"></param> public void SaveTrace(string ProjectDir) { if (rootuser is null) { throw new InvalidOperationException("Root user is not defined!"); } if (!Directory.Exists(ProjectDir)) { Directory.CreateDirectory(ProjectDir); } if (!Directory.Exists(ProjectDir + "/images")) { Directory.CreateDirectory(ProjectDir + "/images"); } Dictionary <string, string> ProjectDOD = new Dictionary <string, string> { { "name", ServerName }, { "date", string.Join("-", ServerCreationDate.Year, ServerCreationDate.Month, ServerCreationDate.Day) }, { "root", RootUser.Name } }; DOD.Save(ProjectDOD, ProjectDir + "/" + "Project.UTrace"); if (File.Exists(ProjectDir + "/" + "Logo.png")) { File.Delete(ProjectDir + "/" + "Logo.png"); } ServerLogo.Save(ProjectDir + "/" + "Logo.png", System.Drawing.Imaging.ImageFormat.Png); if (File.Exists(ProjectDir + "/" + "TileBG.png")) { File.Delete(ProjectDir + "/" + "TileBG.png"); } TileBackground.Save(ProjectDir + "/" + "TileBG.png", System.Drawing.Imaging.ImageFormat.Png); //now to save the users: Dictionary <string, string> UsersDOD = new Dictionary <string, string>(); foreach (User user in AllUsers) { //Add the user to the DOD UsersDOD.Add(user.Name, user.GenerateUserString()); //Save their image if (File.Exists(ProjectDir + "/images/" + user.Name + ".png")) { File.Delete(ProjectDir + "/images/" + user.Name + ".png"); } user.PFP.Save(ProjectDir + "/images/" + user.Name + ".png", System.Drawing.Imaging.ImageFormat.Png); } //Save the DOD DOD.Save(UsersDOD, ProjectDir + "/" + "Users.DOD"); }
private static void SpawnBackgroundAndBorder(SpriteBatch spriteBatch, IRoom room, string spawnType, int i) { IBackground backgroundType; Point position; if (i == 1) { position = new Point(RoomConstants.BackgroundX, RoomConstants.BackgroundY); } else if (i == 2) { position = new Point(RoomConstants.RoomBorderX, RoomConstants.RoomBorderY); } else { position = Point.Zero; } switch (spawnType) { case RoomConstants.TileBackground: backgroundType = new TileBackground(spriteBatch, position); room.AllObjects.Spawn(backgroundType); break; case RoomConstants.RoomBorder: backgroundType = new RoomBorder(spriteBatch, position); room.AllObjects.Spawn(backgroundType); break; case RoomConstants.BlackBackground: backgroundType = new BlackBackground(spriteBatch, position); room.AllObjects.Spawn(backgroundType); break; case RoomConstants.OldBackground: backgroundType = new OldBackground(spriteBatch, position); room.AllObjects.Spawn(backgroundType); break; case RoomConstants.MemeBackground: backgroundType = new MemeBackground(spriteBatch, position); room.AllObjects.Spawn(backgroundType); break; default: break; } }
// Update is called once per frame void Update() { for (int i = 0; i < Backgrounds.Count; i++) { _currentBackground = Backgrounds[i]; _currentScrollSpeed = new Vector3(_currentBackground.ScrollSpeed * Time.deltaTime, 0, 0); for (int j = 0; j < _currentBackground.Tiles.Count; j++) { _currentTile = _currentBackground.Tiles[j]; _currentTile.position -= (_currentScrollSpeed * GameManager.Instance.GlobalSpeed); if (!_currentTile.renderer.isVisible && _currentTile.position.x < Camera.main.transform.position.x) { _currentTile.position += new Vector3(_currentTile.renderer.bounds.size.x * _currentBackground.Tiles.Count, 0, 0); } } } }
// Update is called once per frame void Update() { for(int i = 0; i < Backgrounds.Count; i++) { _currentBackground = Backgrounds[i]; _currentScrollSpeed = new Vector3(_currentBackground.ScrollSpeed * Time.deltaTime, 0 ,0); for(int j = 0; j < _currentBackground.Tiles.Count; j++) { _currentTile = _currentBackground.Tiles[j]; _currentTile.position -= (_currentScrollSpeed * GameManager.Instance.GlobalSpeed); if(!_currentTile.renderer.isVisible && _currentTile.position.x < Camera.main.transform.position.x) { _currentTile.position += new Vector3(_currentTile.renderer.bounds.size.x * _currentBackground.Tiles.Count, 0, 0); } } } }
private void Deselect() { isSelected = false; rend.color = Color.white; previousSelected = null; }
private void Select() { isSelected = true; rend.color = selectedColor; previousSelected = gameObject.GetComponent <TileBackground>(); }
// Initializes the Grid public void init(Level level) { // level contains the level data base.init(level); // Passes the level to the game controller to begin the game List <Dictionary <string, object> > levelBoard = level.getBoard(); // Contains information for each game tile if (levelBoard != null) // If there is game data, generate tiles corresponding to the data; Otherwise tiles are randomly generated { for (int i = 0; i < levelBoard.Count; i++) // For every tile in level data { Dictionary <string, object> tileData = levelBoard[i]; // Pull out tile data int c = (int)tileData["x"]; // Pull columns out of tile data int r = (int)tileData["y"]; // Pull rows out string val = (string)tileData["val"]; // pull val out if (String.IsNullOrEmpty(val)) // if the tile has no data, do nothing { } else if (val == "%" || val == "Ice") // if tile is ice, { iceTiles[r][c] = Ice.createGameObject(iceGrid, r, c); // create ice tile on grid at tile coordinates } else if (val == "#" || val == "TransparentWall") // if tile is transparent wall, { tiles[r][c] = TransparentWall.createGameObject(this.gameObject, r, c); // insert transparent wall on grid. } else if (val == "=" || val == "Wall") // if tile is wall, { tiles[r][c] = Wall.createGameObject(this.gameObject, r, c); // insert wall on grid. } else if (val == "*" || val == "Anchor") // if tile is anchor { tiles[r][c] = Anchor.createGameObject(this.gameObject, r, c); // insert anchor on grid. } else if (val == "&" || val == "RootedTile") // if tile is rooted, { tiles[r][c] = RootedTile.createGameObject(this.gameObject, r, c); // insert rooted tile on grid } else if (val[0] >= 'a' && val[0] <= 'z') // if the tile is an alphabet letter, { int bonus = 0; // will contain bonus multiplier if (tileData.ContainsKey("bonus")) // if level data contains a bonus, { bonus = (int)tileData["bonus"]; // store bonus data } tiles[r][c] = WordTile.createGameObject(this.gameObject, r, c, val, bonus); // insert bonus at row and column location on grid if (tileData.ContainsKey("crown")) // if level data contains crown special objects { ((WordTile)tiles[r][c]).setCrown(true); // insert crown in game grid } } } } for (int r = 0; r < row; r++) { for (int c = 0; c < col; c++) { // for every grid tile, if (tiles[r][c] == null) // if the tile has no data, { tiles[r][c] = WordTile.createGameObject(this.gameObject, r, c); // generate a game tile piece with random properties } } } for (int r = 0; r < row; r++) { for (int c = 0; c < col; c++) { // for every grid tile, Tile tile = getTile(r, c); // pull the tile data if (tile.isMovable() || level.isTutorial) // if tile can be moved or the level is a tutorial, { TileBackground tb = (Instantiate(Resources.Load("TileBackground")) as GameObject).GetComponent <TileBackground>(); // create a tile background object; non-movable tiles do not get backgrounds tb.transform.SetParent(gridBackground.transform); // attach the background object to the tile tb.init(r, c); // begin rendering the background object } } } updateMoveUI(); // update the number of moves left in the level updateBoardSize(); // change the board size? Function is not implemented updateText(); // update all words that are connected updateScore(); // update the user score gameController.user.logger(new Dictionary <string, object> { { "d1", "levelStart" }, { "d2", level.level } }); // create a log for debugging purposes }