void PlaceObstacles(int _probability, Dictionary <int, int> cells) { var freeCells = new List <int>(); foreach (KeyValuePair <int, int> c in cells) { if (c.Value == 0) { freeCells.Add(c.Key); } } freeCells.Sort(); for (int i = 0; i < freeCells.Count; i++) { int x = freeCells[i]; if (Random.Range(0, 100) <= _probability) { ObstacleData _obstacle = ObstacleDatas[Random.Range(0, ObstacleDatas.Count)]; int y = GetTopGroundIndex(x); Vector2 pos = Grid.CellToWorld(new Vector3Int(x, y, 0)); float constraintLeft = pos.x; float constraintRight = pos.x + Grid.cellSize.x; float rndScale = Random.Range(_obstacle.ScaleLimits.x, _obstacle.ScaleLimits.y); float _newXsize = _obstacle.Prefab.GetComponent <Renderer>().bounds.size.x *rndScale; float _yShift; if (_obstacle.Prefab.name == "Bush") { _yShift = _obstacle.Prefab.GetComponent <Renderer>().bounds.size.y *rndScale * 0.385f; } else { _yShift = _obstacle.Prefab.GetComponent <Renderer>().bounds.size.y *rndScale * 0.5f; } pos += new Vector2(0, (Grid.cellSize.y * 0.95f) + _yShift); int leftConstraint = 0; if (Tilemap.GetTile(new Vector3Int(x - 1, y + 1, 0)) != null | Tilemap.GetTile(new Vector3Int(x - 1, y, 0)) == null) { leftConstraint = 1; } pos.x += Random.Range(0, 1f) * Grid.cellSize.x + leftConstraint * (_newXsize * 0.5f); if (_previousObstacle != null) { float minimalDistance = _previousObstacle.transform.position.x + (_previousObstacle.GetComponent <Renderer>().bounds.size.x * 0.5f) + (_newXsize * 0.5f) + ObstacleDelta; if (pos.x < minimalDistance) { pos.x = minimalDistance; } } pos = new Vector2(Mathf.Clamp(pos.x, constraintLeft, constraintRight), pos.y); Vector3Int _adjCell = Grid.WorldToCell(new Vector3(pos.x + (_newXsize / 2f), pos.y)); if (Tilemap.GetTile(new Vector3Int(_adjCell.x, _adjCell.y - 1, _adjCell.z)) != null && Tilemap.GetTile(_adjCell) == null) { _previousObstacle = _obstacle.Pool.Get().gameObject; _previousObstacle.transform.SetParent(Obstacles); _previousObstacle.transform.position = pos; _previousObstacle.transform.localScale = new Vector3(rndScale, rndScale, rndScale); if (Random.Range(0, 2) == 0) { _previousObstacle.transform.Rotate(new Vector3(0, 180, 0)); } cells[x] = 3; } } } }
public static T GetRandom <T>(this IList <T> list) { return(list[Random.Range(0, list.Count)]); }
private void SetStage(bool isStart) { if (isStart) { for (int i = 0; i < 16; i++) { _colors[i] = SquareColor.White; Scaffold.SetButtonBlack(i); } } else { var sq = 0; for (int i = 0; i < 16; i++) { switch (_colors[i]) { case SquareColor.Black: break; case SquareColor.Red: case SquareColor.Green: case SquareColor.Blue: case SquareColor.Yellow: case SquareColor.Magenta: Scaffold.SetButtonBlack(i); sq++; break; case SquareColor.White: _colors[i] = SquareColor.Black; break; } } if (sq <= 3) { ModulePassed(); return; } } // Check all color combinations and find all valid pattern placements var order = new[] { SquareColor.Red, SquareColor.Green, SquareColor.Blue, SquareColor.Yellow, SquareColor.Magenta }; var validCombinations = Enumerable.Range(0, 5).SelectMany(first => Enumerable.Range(0, 5).Select(second => { if (first == second) { return(null); } var pattern = _table[second][first]; var w = pattern.GetLength(0); var h = pattern.GetLength(1); var placements = new List <List <int> >(); for (int i = 0; i < 16; i++) { if (i % 4 + w > 4 || i / 4 + h > 4) { continue; } var placement = new List <int>(); for (int y = 0; y < h; y++) { for (int x = 0; x < w; x++) { if (pattern[x, y]) { var ix = i % 4 + x + 4 * (i / 4 + y); if (_colors[ix] == SquareColor.Black) { goto nope; } placement.Add(ix); } } } placements.Add(placement); nope:; } return(placements.Count == 0 ? null : new { First = order[first], Second = order[second], Placements = placements }); })).Where(inf => inf != null).ToArray(); if (validCombinations.Length == 0) { ModulePassed(); return; } // Fill the still-lit squares with “codes” (numbers 0–5 that we will later map to actual colors) // in such a way that there’s a two-way tie for fewest number of occurrences int[] colorCodes = new int[16]; tryAgain: var counts = new int[5]; for (int i = 0; i < 16; i++) { if (_colors[i] != SquareColor.Black) { var col = Rnd.Range(0, 5); colorCodes[i] = col; counts[col]++; } else { colorCodes[i] = -1; } } var minCount = counts.Where(c => c > 0).Min(); var minCountCodes = Enumerable.Range(0, 5).Where(code => counts[code] == minCount).OrderBy(c => Array.IndexOf(colorCodes, c)).ToArray(); if (minCountCodes.Length != 2) { goto tryAgain; } // Pick a color combination at random var combination = validCombinations[Rnd.Range(0, validCombinations.Length)]; // Create the map from color code to actual color in such a way that the chosen colors are in the correct place var allColors = new List <SquareColor> { SquareColor.Blue, SquareColor.Green, SquareColor.Magenta, SquareColor.Red, SquareColor.Yellow }; allColors.Remove(combination.First); allColors.Remove(combination.Second); if (minCountCodes[0] > minCountCodes[1]) { allColors.Insert(minCountCodes[1], combination.Second); allColors.Insert(minCountCodes[0], combination.First); } else { allColors.Insert(minCountCodes[0], combination.First); allColors.Insert(minCountCodes[1], combination.Second); } // Assign the colors for (int i = 0; i < 16; i++) { if (_colors[i] != SquareColor.Black) { _colors[i] = allColors[colorCodes[i]]; } } if (isStart) { _firstStageColor1 = combination.First; _firstStageColor2 = combination.Second; } Log("{0} stage color pair is {1}/{2}", isStart ? "First" : "Next", combination.First, combination.Second); _permissiblePatterns = combination.Placements; _squaresPressedThisStage.Clear(); Scaffold.StartSquareColorsCoroutine(_colors, delay: true); }
protected override void ButtonPressed(int index) { if (_expectedPresses == null) { return; } if (!_allowedPresses.Contains(index)) { Log(@"Button #{0} ({1}) was incorrect at this time.", index, _colors[index]); Strike(); SetInitialState(); } else { PlaySound(index); _expectedPresses.Remove(index); _colors[index] = SquareColor.White; Scaffold.SetButtonColor(index, SquareColor.White); if (_expectedPresses.Count == 0) { var whiteCount = _colors.Count(c => c == SquareColor.White); if (whiteCount == 16) { _expectedPresses = null; _allowedPresses = null; ModulePassed(); } else { _allowedPresses.Clear(); var nonWhite = Enumerable.Range(0, 16).Where(i => _colors[i] != SquareColor.White).ToArray(); foreach (var i in nonWhite) { Scaffold.SetButtonBlack(i); _colors[i] = (SquareColor)Rnd.Range(1, 6); } // Move to next stage. var nextStage = _table[whiteCount - 1][_lastStage is SquareColor ? (int)(SquareColor)_lastStage - 1 : _lastStage.Equals(true) ? 5 : 6]; Log("{0} lit: next stage is {1}.", whiteCount, nextStage.Equals(true) ? "Row" : nextStage.Equals(false) ? "Column" : ((SquareColor)nextStage).ToString()); if (nextStage.Equals(true)) { // Row var firstRow = Enumerable.Range(0, 4).First(row => Enumerable.Range(0, 4).Any(col => _colors[4 * row + col] != SquareColor.White)); for (int col = 0; col < 4; col++) { if (_colors[4 * firstRow + col] != SquareColor.White) { _allowedPresses.Add(4 * firstRow + col); _expectedPresses.Add(4 * firstRow + col); } } } else if (nextStage.Equals(false)) { // Column var firstCol = Enumerable.Range(0, 4).First(col => Enumerable.Range(0, 4).Any(row => _colors[4 * row + col] != SquareColor.White)); for (int row = 0; row < 4; row++) { if (_colors[4 * row + firstCol] != SquareColor.White) { _allowedPresses.Add(4 * row + firstCol); _expectedPresses.Add(4 * row + firstCol); } } } else { // A specific color // Make sure at least one square has that color var color = (SquareColor)nextStage; _colors[nonWhite[Rnd.Range(0, nonWhite.Length)]] = color; for (int i = 0; i < 16; i++) { if (_colors[i] == color) { _allowedPresses.Add(i); _expectedPresses.Add(i); } } } _lastStage = nextStage; Scaffold.StartSquareColorsCoroutine(_colors, SquaresToRecolor.NonwhiteOnly, delay: true); } } } }
private static int GetRandomPosition(int currentValue, int maxExclusive) { return(Random.Range(Math.Max(currentValue - 1, 0), Math.Min(currentValue + 2, maxExclusive))); }
// pet properties public override void Init(int _entityClass) { base.Init(_entityClass); this.emodel.SetVisible(true, true); if (SingletonMonoBehaviour <ConnectionManager> .Instance.IsServer) { base.getNavigator().setCanDrown(true); base.getNavigator().setInWater(false); } // Sets the hand value, so we can give our entities ranged weapons. inventory.SetSlots(new[] { new ItemStack(inventory.GetBareHandItemValue(), 1) }); string[] auxList = null; var entityClass = EntityClass.list[_entityClass]; if (entityClass.Properties.Values.ContainsKey("FlockSize")) { if (int.TryParse(entityClass.Properties.Values["FlockSize"], out maxToSpawn) == false) { maxToSpawn = 10; } if (maxToSpawn > 0) { maxToSpawn = Random.Range(0, maxToSpawn); } } if (entityClass.Properties.Values.ContainsKey("MaxHeight")) { if (int.TryParse(entityClass.Properties.Values["MaxHeight"], out maxHeight) == false) { maxHeight = 80; } } if (entityClass.Properties.Values.ContainsKey("IsAgressive")) { if (bool.TryParse(entityClass.Properties.Values["IsAgressive"], out targetPlayers) == false) { targetPlayers = false; } } if (entityClass.Properties.Values.ContainsKey("FollowPlayer")) { if (bool.TryParse(entityClass.Properties.Values["FollowPlayer"], out followPlayers) == false) { followPlayers = false; } } if (entityClass.Properties.Values.ContainsKey("RetaliateAttack")) { if (bool.TryParse(entityClass.Properties.Values["RetaliateAttack"], out retaliateAttack) == false) { retaliateAttack = false; } } if (entityClass.Properties.Values.ContainsKey("LandingBlocks")) { auxList = entityClass.Properties.Values["LandingBlocks"].Split(','); targetBlocks = new HashSet <string>(auxList); } if (entityClass.Properties.Values.ContainsKey("DeflectorBlocks")) { auxList = entityClass.Properties.Values["DeflectorBlocks"].Split(','); deflectorBlocks = new HashSet <string>(auxList); } if (entityClass.Properties.Values.ContainsKey("NaturalEnemies")) { auxList = entityClass.Properties.Values["NaturalEnemies"].Split(','); naturalEnemies = new HashSet <string>(auxList); } if (entityClass.Properties.Values.ContainsKey("TameItem")) { tameItem = entityClass.Properties.Values["TameItem"]; } if (entityClass.Properties.Values.ContainsKey("MeshScale")) { var meshScaleStr = entityClass.Properties.Values["MeshScale"]; var parts = meshScaleStr.Split(','); float minScale = 1; float maxScale = 1; if (parts.Length == 1) { maxScale = minScale = float.Parse(parts[0]); } else if (parts.Length == 2) { minScale = float.Parse(parts[0]); maxScale = float.Parse(parts[1]); } meshScale = Random.Range(minScale, maxScale); gameObject.transform.localScale = new Vector3(meshScale, meshScale, meshScale); } auxList = null; }
private ShapeType GetRandomShape() { var shapesCount = Enum.GetValues(typeof(ShapeType)).Length; return((ShapeType)Random.Range(0, shapesCount)); }
float RandomTorque() { return(Random.Range(-maxTorque, maxTorque)); }
Vector3 RandomSpawnPos() { return(new Vector3(Random.Range(-xRange, xRange), ySpawnPos)); }
public static T GetRandomItem <T>(this IEnumerable <T> list) { return(list.ElementAt(Random.Range(0, list.Count()))); }
Vector3 RandomForce() { return(Vector3.up * Random.Range(minSpeed, maxSpeed)); }
public int[,] RandomWalkTopSmoothed(int[,] map, int minSectionWidth, int nodeY) { //Determine the start position //int lastHeight = Random.Range(0, map.GetUpperBound(1)); int lastHeight = Random.Range(0, map.GetLength(1)); int shift = lastHeight - nodeY; if (shift < 0) { shift = 0; } int bottomBound; if (_minCellY < -shift) { bottomBound = 0; } else { bottomBound = _minCellY + shift; } //Used to determine which direction to go int nextMove = 0; //Used to keep track of the current sections width int sectionWidth = 0; Array.Clear(map, 0, map.Length); //for ( int i = 0; i <= map.GetUpperBound(0); i++ ) { // for ( int j = 0; j <= map.GetUpperBound(1); j++ ) { // map[i, j] = 0; // } //} for (int x = 0; x <= map.GetUpperBound(0); x++) { //Determine the next move nextMove = Random.Range(0, 2); //Only change the height if we have used the current height more than the minimum required section width //if ( nextMove == 0 && lastHeight > 0 && sectionWidth > minSectionWidth ) { if (nextMove == 0 && lastHeight > bottomBound && sectionWidth > minSectionWidth) { lastHeight--; sectionWidth = 0; } else if (nextMove == 1 && lastHeight < map.GetUpperBound(1) && sectionWidth > minSectionWidth) { lastHeight++; sectionWidth = 0; } //Increment the section width sectionWidth++; //Work our way from the height down to 0 for (int y = lastHeight; y >= 0; y--) { map[x, y] = 1; } } return(map); }
void PlaceDecor(int _x0, int _x1) { //Кусты и камни на заднем фоне Vector2 scaleLim = new Vector2(0.5f, 2.7f); int propsNum = 0; int iterations = (_x1 - _x0) / 10; for (int i = 0; i < iterations; i++) { propsNum += Random.Range(0, MaxPropsOnTenCells + 1); } List <int> cells = new List <int>(); for (int i = 0; i < propsNum; i++) { int nextCell = Random.Range(_x0, _x1); while (cells.Contains(nextCell)) { nextCell = Random.Range(_x0, _x1); } cells.Add(nextCell); Vector3 pos = Tilemap.CellToWorld(new Vector3Int(nextCell, GetUpperBound(Tilemap, nextCell), 0)); var dData = BGPropsDatas[Random.Range(0, BGPropsDatas.Count)]; float rndScale = Random.Range(scaleLim.x, scaleLim.y); float _yShift = dData.Prefab.GetComponent <Renderer>().bounds.size.y *rndScale * 0.5f; pos.y += Grid.cellSize.y * 0.85f + _yShift; int c = 0; while (!FullyInGround(dData.Prefab.transform, rndScale, pos)) { pos -= new Vector3(0, Grid.cellSize.y * 0.5f, 0); c++; if (c == 3) { return; } } var decor = dData.Pool.Get(); if (decor.transform.parent == null) { decor.transform.SetParent(BGDecor); } decor.transform.localScale = new Vector3(rndScale, rndScale); decor.transform.position = pos; if (Random.Range(0, 2) == 1) { decor.GetComponent <SpriteRenderer>().flipX = true; } else { decor.GetComponent <SpriteRenderer>().flipX = false; } } //черепа и кости propsNum = 0; for (int i = 0; i < iterations; i++) { propsNum += Random.Range(0, MaxSmallPropsOnTenCells + 1); } scaleLim = new Vector2(0.4f, 1.3f); cells.Clear(); for (int i = 0; i < propsNum; i++) { int nextCell = Random.Range(_x0, _x1); while (cells.Contains(nextCell)) { nextCell = Random.Range(_x0, _x1); } cells.Add(nextCell); Vector3 pos = Tilemap.CellToWorld(new Vector3Int(nextCell, GetUpperBound(Tilemap, nextCell) - Random.Range(0, 2), 0)); pos += Grid.cellSize * 0.5f; var dData = FGPropsDatas[Random.Range(0, FGPropsDatas.Count)]; float rndScale = Random.Range(scaleLim.x, scaleLim.y); var decor = dData.Pool.Get(); if (decor.transform.parent == null) { decor.transform.SetParent(Decor); } decor.transform.localScale = new Vector3(rndScale, rndScale); decor.transform.position = pos; //decor.transform.RotateAroundLocal(new Vector3(0, 0, 1), Random.Range(0, 95f)); decor.transform.Rotate(new Vector3(0, 0, Random.Range(0, 180))); if (Random.Range(0, 2) == 1) { decor.GetComponent <SpriteRenderer>().flipX = true; } else { decor.GetComponent <SpriteRenderer>().flipX = false; } } bool IsInGround(Vector3 pos) { if (Tilemap.GetTile(Tilemap.WorldToCell(pos)) == null) { return(false); } else { return(true); } } bool FullyInGround(Transform s, float scale, Vector3 pos) { Renderer rend = s.GetComponent <Renderer>(); if (!IsInGround(pos - (rend.bounds.extents * scale))) { return(false); } else if (!IsInGround(pos + new Vector3(rend.bounds.extents.x * scale, -rend.bounds.extents.y * scale, 0))) { return(false); } return(true); } }
void PlaceIslands(Dictionary <int, int> cells) { float maxDeltaUp = 2.3f; float maxDeltaDown = 1.5f; float minDistance = 1.3f; float maxDistance = 4f; float minHeight = Tilemap.cellSize.y + 0.5f; float lastX = 0f; int recCounter = 0; var scaleBounds = new Vector2(0.3f, 1); float cutOffX = 0f; var indexes = new List <int>(); foreach (KeyValuePair <int, int> c in cells) { indexes.Add(c.Key); } indexes.Sort(); cutOffX = Tilemap.CellToWorld(new Vector3Int(indexes[indexes.Count - 1], 0, 0)).x; var nodes = new List <int>(); for (int i = 0; i < indexes.Count; i++) { if (Tilemap.GetTile(new Vector3Int(indexes[i] + 1, GetUpperBound(Tilemap, indexes[i]), 0)) == null) { nodes.Add(indexes[i]); } } for (int i = 0; i < nodes.Count; i++) { Vector2 node = Tilemap.CellToWorld(new Vector3Int(nodes[i], GetUpperBound(Tilemap, nodes[i]), 0)); node.x += Tilemap.cellSize.x; node.y += Tilemap.cellSize.y; if (node.x < lastX) { continue; } recCounter = 0; TryPlace(node); } void TryPlace(Vector2 node) { if (Random.Range(0, 5) == 4) { return; } float scaleX = Random.Range(scaleBounds.x, scaleBounds.y); float newSizeX = Island.GetComponent <Renderer>().bounds.size.x *scaleX; float baseShift = node.x + 0.5f * newSizeX; float islandY; float islandX; if (recCounter == 1) { islandX = Random.Range(baseShift + 0.8f, baseShift + maxDistance); islandY = Random.Range(node.y + 1, node.y + maxDeltaUp); } else { islandX = Random.Range(baseShift + minDistance, baseShift + maxDistance); islandY = Random.Range(node.y - maxDeltaDown, node.y + maxDeltaUp); } if (islandX > cutOffX) { return; } int islandCellX = Tilemap.WorldToCell(new Vector3(islandX, 0, 0)).x; if (cells.ContainsKey(islandCellX)) { if (cells[islandCellX] == 2) { return; } } float rightEdgeX = islandX + (newSizeX * 0.5f); float leftEdgeX = islandX - (newSizeX * 0.5f); if ((GetHeight(leftEdgeX, islandY) >= minHeight) & (GetHeight(rightEdgeX, islandY) >= minHeight)) { if (IsPassable(rightEdgeX, islandY, scaleX)) { var island = islandsPool.Get().gameObject; if (island.transform.parent == null) { island.transform.SetParent(Islands); } island.transform.position = new Vector2(islandX, islandY); island.transform.localScale = new Vector3(scaleX, 1, 1); lastX = rightEdgeX; recCounter++; if (recCounter == 4) { Instantiate(Apple, new Vector2(islandX, islandY + 1f), Quaternion.identity, Apples); return; } else if (recCounter == 3) { if (Random.Range(0, 2) != 0) { Instantiate(Apple, new Vector2(islandX, islandY + 1f), Quaternion.identity, Apples); } } var newNode = new Vector2(islandX + (newSizeX * 0.5f), islandY); TryPlace(newNode); } } } bool IsPassable(float x, float y, float scale) { int cellX = Tilemap.WorldToCell(new Vector3(x, 0, 0)).x + 1; int cellY = GetUpperBound(Tilemap, cellX); Vector2 leftUpperCorner = Tilemap.CellToWorld(new Vector3Int(cellX, cellY, 0)); leftUpperCorner += new Vector2(-(Tilemap.cellSize.x / 2), Tilemap.cellSize.y); float magnitude = (new Vector2(x, y) - leftUpperCorner).magnitude; if (magnitude > 2f) { return(true); } else { return(false); } } float GetHeight(float x, float y) { int cellX = Tilemap.WorldToCell(new Vector3(x, 0, 0)).x; Vector3 pos = Tilemap.CellToWorld(new Vector3Int(cellX, GetUpperBound(Tilemap, cellX), 0)); return(y - (pos.y + Tilemap.cellSize.y)); } }
void Start() { _moduleId = _moduleIdCounter++; indicatorCount = IndicatorMeshes.Length; Colors = new int[indicatorCount]; Numbers = new int[indicatorCount]; Flashes = new bool[indicatorCount][]; Pointers = new int[indicatorCount]; Operators = new int[2]; SolNumbers = new int[indicatorCount]; for (int i = 0; i < indicatorCount; i++) { Buttons[i].OnInteract += HandlePress(i); } reset: var origParenPos = PAREN_POS = Rnd.Range(0, 2); Operators[0] = Rnd.Range(0, 4); Operators[1] = Rnd.Range(0, 4); for (int i = 0; i < indicatorCount; i++) { Colors[i] = Rnd.Range(0, 7); Numbers[i] = Rnd.Range(1, 36); Flashes[i] = MorseToBoolArray(MORSE_SYMBOLS[Numbers[i]]); } // This changes the value of PAREN_POS if one of the colors is green int solutionNum; for (int i = 0; i < indicatorCount; i++) { SolNumbers[i] = DoColorOperation(Colors[i], Numbers[i]); } Solution = ""; double sign, sol; try { sol = PAREN_POS == 0 ? Op(Operators[1], Op(Operators[0], SolNumbers[0], SolNumbers[1]), SolNumbers[2]) : Op(Operators[0], SolNumbers[0], Op(Operators[1], SolNumbers[1], SolNumbers[2])); } catch (DivideByZeroException) { goto reset; } if (double.IsInfinity(sol) || double.IsNaN(sol)) { goto reset; } sign = Math.Sign(sol); solutionNum = (int)Math.Abs(sol); if (sign == -1 && solutionNum != 0) { Solution = "-....- "; } foreach (char c in (solutionNum % 1000).ToString()) { Solution += MORSE_SYMBOLS[SYMBOLS.IndexOf(c)] + " "; } Solution = Solution.Trim(); if (origParenPos == 0) { Labels[0].text = "("; Labels[3].gameObject.SetActive(false); Labels[1].text = "" + OPERATION_SYMBOLS[Operators[0]]; Labels[2].text = ")" + OPERATION_SYMBOLS[Operators[1]]; } else { Labels[0].gameObject.SetActive(false); Labels[3].text = ")"; Labels[1].text = OPERATION_SYMBOLS[Operators[0]] + "("; Labels[2].text = "" + OPERATION_SYMBOLS[Operators[1]]; } for (int i = 0; i < indicatorCount; i++) { Debug.LogFormat("[Color Morse #{0}] LED {1} is a {2} {3} ({4})", _moduleId, i + 1, ColorNames[Colors[i]], Numbers[i], SYMBOLS[Numbers[i]]); } Debug.LogFormat("[Color Morse #{0}] Parentheses location: {1}", _moduleId, origParenPos == 0 ? "LEFT" : "RIGHT"); Debug.LogFormat("[Color Morse #{0}] Operators: {1} and {2}", _moduleId, OPERATION_SYMBOLS[Operators[0]], OPERATION_SYMBOLS[Operators[1]]); for (int i = 0; i < indicatorCount; i++) { Debug.LogFormat("[Color Morse #{0}] Number {1} after color operation is {2}", _moduleId, i + 1, SolNumbers[i]); } if (origParenPos != PAREN_POS) { Debug.LogFormat("[Color Morse #{0}] Parentheses locations are imaginarily swapped because of green.", _moduleId); } Debug.LogFormat("[Color Morse #{0}] Solution: {1}{2} ({3})", _moduleId, sign == -1 ? "-" : "", solutionNum, Solution); BombModule.OnActivate += Activate; }
Card MakeCard() { int bent = 0; for (int i = 0; i < 4; i++) { if (Random.value < 0.20) { bent++; } } Card c = new Card(Random.Range(0, CD.size), Random.Range(0, 4), Random.Range(1, 10), (char)Random.Range('A', 'I' + 1), Random.value < 0.21, bent); // SHOuLD RARE CARDS BE RARE? Bent corners and holo string[] mulNames = new string[] { "Common", "Uncommon", "Rare", "Very Rare" }; PrintDebug("Monsplode: " + CD.names[c.monsplode].Replace('\n', ' ') + " | Rarity: " + mulNames[c.rarity] + "\nPrint Version: " + c.printChar + c.printDigit + " | Holographic: " + c.isHolographic + " | Bent Corners: " + c.bentCorners); c.value = CalculateCardValue(c); return(c); }
public void Shoot() { if (InfinityAmmo) { Ammo = 1; } if (Ammo > 0) { if (Time.time > nextFireTime + FireRate) { nextFireTime = Time.time; torqueTemp = TorqueSpeedAxis; Ammo -= 1; Vector3 missileposition = this.transform.position; Quaternion missilerotate = this.transform.rotation; if (MissileOuter.Length > 0) { missilerotate = MissileOuter [currentOuter].transform.rotation; missileposition = MissileOuter [currentOuter].transform.position; } if (MissileOuter.Length > 0) { currentOuter += 1; if (currentOuter >= MissileOuter.Length) { currentOuter = 0; } } if (Muzzle) { GameObject muzzle = (GameObject)GameObject.Instantiate(Muzzle, missileposition, missilerotate); muzzle.transform.parent = this.transform; GameObject.Destroy(muzzle, MuzzleLifeTime); if (MissileOuter.Length > 0) { muzzle.transform.parent = MissileOuter [currentOuter].transform; } } for (int i = 0; i < NumBullet; i++) { if (Missile) { Vector3 spread = new Vector3(Random.Range(-Spread, Spread), Random.Range(-Spread, Spread), Random.Range(-Spread, Spread)) / 100; Vector3 direction = this.transform.forward + spread; if (target) { direction = (target.transform.position - this.transform.position).normalized + spread; } GameObject bullet = (GameObject)Instantiate(Missile, missileposition, missilerotate); DamageBase damangeBase = bullet.GetComponent <DamageBase> (); if (damangeBase) { damangeBase.Owner = Owner; damangeBase.TargetTag = TargetTag; } WeaponBase weaponBase = bullet.GetComponent <WeaponBase> (); if (weaponBase) { weaponBase.Owner = Owner; weaponBase.Target = target; weaponBase.TargetTag = TargetTag; } bullet.transform.forward = direction; if (RigidbodyProjectile) { if (bullet.GetComponent <Rigidbody>()) { if (Owner != null && Owner.GetComponent <Rigidbody>()) { bullet.GetComponent <Rigidbody>().velocity = Owner.GetComponent <Rigidbody>().velocity; } bullet.GetComponent <Rigidbody>().AddForce(direction * ForceShoot); } } } } if (Shell) { Transform shelloutpos = this.transform; if (ShellOuter.Length > 0) { shelloutpos = ShellOuter [currentOuter]; } GameObject shell = (GameObject)Instantiate(Shell, shelloutpos.position, Random.rotation); GameObject.Destroy(shell.gameObject, ShellLifeTime); if (shell.GetComponent <Rigidbody>()) { shell.GetComponent <Rigidbody>().AddForce(shelloutpos.forward * ShellOutForce); } } if (SoundGun.Length > 0) { if (audioSource) { audioSource.PlayOneShot(SoundGun [Random.Range(0, SoundGun.Length)]); } } nextFireTime += FireRate; } } }
public static Shape getRandomShape() { Array values = Enum.GetValues(typeof(Shape)); return (Shape) values.GetValue((int) Random.Range(0, values.Length)); }
// Update is called once per frame void Update() { _previousPos = transform.position; // Vector3 direction = // new Vector3(GetComponent<Rigidbody>().velocity.x, 0, GetComponent<Rigidbody>().velocity.z); // transform.rotation = Quaternion.Slerp(transform.rotation,(transform.position + GetComponent<Rigidbody>().velocity), 1); interval += Time.deltaTime; //girlTurn = Random.Range(-180f, 180f); //girlRotation = new Vector3(0f, girlTurn, 0f); if (interval > 3f) { ranNum = Random.Range(0, 6); // GetComponent<Rigidbody>().AddRelativeTorque(girlRotation *2, ForceMode.Force); interval = 0; // GetComponent<Rigidbody>().AddForce(transform.forward * 10, ForceMode.Impulse); } switch (ranNum) { case 1: //transform.position = Vector3.MoveTowards(transform.position, locations[0], .5f); // GetComponent<Rigidbody>().AddForce(locations[0]-transform.position,ForceMode.Acceleration); transform.position = Vector3.MoveTowards(transform.position, locations[0], .1f); // transform.eulerAngles = Vector3.RotateTowards(transform.position, locations[0], .1f, .1f); //transform.LookAt(locations[0]); Vector3 dir = Vector3.RotateTowards(transform.position, locations[0], .5f, 01f); //transform.rotation = Quaternion.LookRotation(dir); //transform.Rotate(new Vector3(0, -90, 0)); transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(dir) * Quaternion.Euler(0, -90, 0), .03f); break; case 2: //transform.position = Vector3.MoveTowards(transform.position, locations[1], .5f); //GetComponent<Rigidbody>().AddForce(locations[1]-transform.position,ForceMode.Acceleration); transform.position = Vector3.MoveTowards(transform.position, locations[1], .05f); // transform.rotation = Quaternion.LookRotation(transform.position,locations[1]); // transform.eulerAngles = Vector3.RotateTowards(transform.position, locations[1], .1f, .1f); Vector3 dir1 = Vector3.RotateTowards(transform.position, locations[1], .5f, 01f); //transform.rotation = Quaternion.LookRotation(dir1); //transform.LookAt(locations[1]); transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(dir1) * Quaternion.Euler(0, -90, 0), .03f); //transform.Rotate(new Vector3(0, -90, 0)); break; case 3: //transform.position = Vector3.MoveTowards(transform.position, locations[2], .5f); //GetComponent<Rigidbody>().AddForce(locations[2]-transform.position,ForceMode.Acceleration); transform.position = Vector3.MoveTowards(transform.position, locations[2], .1f); // transform.rotation = Quaternion.LookRotation(transform.position,locations[2]); //transform.eulerAngles = Vector3.RotateTowards(transform.position, locations[2], .1f, .1f); //transform.LookAt(locations[2]); //Vector3 dir2 = Vector3.RotateTowards(transform.position, locations[2], .5f, 1f); Vector3 dir2 = locations[2] - transform.position; //transform.rotation = Quaternion.LookRotation(dir2); transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(dir2) * Quaternion.Euler(0, -90, 0), .03f); //transform.Rotate(new Vector3(0, -90, 0)); break; case 4: //transform.position = Vector3.MoveTowards(transform.position, locations[3], .5f); //GetComponent<Rigidbody>().AddForce(locations[3]-transform.position,ForceMode.Acceleration); transform.position = Vector3.MoveTowards(transform.position, locations[3], .05f); // transform.rotation = Quaternion.LookRotation(transform.position,locations[3]); //transform.eulerAngles = Vector3.RotateTowards(transform.position, locations[3], .1f, .1f); //Vector3 dir3 = Vector3.RotateTowards(transform.position, locations[3], .5f, 1f); Vector3 dir3 = locations[3] - transform.position; //transform.rotation = Quaternion.LookRotation(dir3); //transform.LookAt(locations[3]); transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(dir3) * Quaternion.Euler(0, -90, 0), .03f); //transform.Rotate(new Vector3(0, -90, 0)); break; case 5: // transform.position = Vector3.MoveTowards(transform.position, locations[4], .5f); //GetComponent<Rigidbody>().AddForce(locations[4]-transform.position,ForceMode.Acceleration); transform.position = Vector3.MoveTowards(transform.position, locations[4], .05f); // transform.rotation = Quaternion.LookRotation(transform.position,locations[4]); //transform.eulerAngles = Vector3.RotateTowards(transform.position, locations[4], .1f, .1f); //Vector3 dir4 = Vector3.RotateTowards(transform.position, locations[4], .5f, 01f); Vector4 dir4 = locations[4] - transform.position; //transform.rotation = Quaternion.LookRotation(dir4); //transform.LookAt(locations[4]); //transform.Rotate(new Vector3(0, -90, 0)); transform.rotation = Quaternion.Slerp(transform.rotation, Quaternion.LookRotation(dir4) * Quaternion.Euler(0, -90, 0), .03f); break; } foreach (var targetLoc in locations) { if (targetLoc.z == transform.position.z && targetLoc.x == transform.position.x) { interval = 3; } } //_lastPos = _previousPos; GirlMovementAnim(); // Debug.Log((transform.position-_previousPos).normalized); }
private void GenerateName() { text.text = NameList.Names[Random.Range(0, NameList.Names.Length)]; DebugLog("Name displayed is {0}", text.text); }
protected override void OnUpdate() { // add random component if (query.CalculateEntityCount() != 0) { var native = query.ToEntityArray(Allocator.Temp); for (int i = 0; i < native.Length; i++) { var entity = native[i]; EntityManager.AddComponentData(entity, new RandomDirection { Direction = new float3(Random.Range(-1, 1f), Random.Range(-1, 1f), Random.Range(-1, 1f)) }); } native.Dispose(); } float time = Time.DeltaTime; Entities.ForEach((Entity entity, ref Translation translation, in RandomDirection randomDirection) => { //translation.Value += time * randomDirection.Direction * 2; }).Schedule(); }
public static int GetRandomPercent() { init(); return(Random.Range(0, MaxPercent)); }
public SecureInt(int value) { _offset = Random.Range(-1000, 1000); _value = value + _offset; }
public static int GetInRange(int min, int max) { init(); return(Random.Range(min, max)); }
public override void StartExecution(Action <Command> OnCommandFinished) { base.StartExecution(OnCommandFinished); if (PhotonNetwork.IsConnected && PhotonNetwork.InRoom) { FinishExecution(); } else { Command connectToMaster = new ConnectToMasterCommand(); Command connectToLobby = new ConnectToLobbyCommand(Keys.DefaultRoom.NICKNAME); Command connectToRoom = new ConnectToRoomCommand(Keys.DefaultRoom.ROOM_NAME + Random.Range(0f, 100f)); invoker.AddCommand(connectToMaster); invoker.AddCommand(connectToLobby); invoker.AddCommand(connectToRoom); invoker.Start(); UnityEngine.Debug.LogWarning("Uruchamianie gry na awaryjnym pokoju"); } }
protected override void AttackTarget(Character target) { SetMainTarget(target); bool isCasting = Owner.GetData().IsCasting; bool forcedVelocity = Owner.GetData().forcedVelocity; // already doing something if (isCasting || forcedVelocity) { return; } if (Owner.GetData().Target == null || Owner.GetData().Target.Equals(target.GetData().GetBody())) { Owner.GetData().Target = target.GetData().GetBody(); } Vector3 ownerPos = Owner.GetData().GetBody().transform.position; Vector3 targetPos = target.GetData().GetBody().transform.position; float distSqr = Utils.DistanceSqr(ownerPos, targetPos); if (currentAction == null && jump != null && GetTimer("jump", jumpInterval)) { Vector3 pos; if (GetTimer("jump_at_player", nextJumpAtPlayerInterval)) { pos = targetPos; SetTimer("jump_at_player"); nextJumpAtPlayerInterval = Random.Range(jumpAtPlayerMinInterval, jumpAtPlayerMaxInterval); } else { Owner.GetData().Target = null; pos = Utils.GenerateRandomPositionAround(targetPos, 15f, 2f); } Debug.DrawLine(ownerPos, pos, Color.magenta, 2f); float range = Vector3.Distance(ownerPos, pos); jump.range = (int)range; if (StartAction(CastSkill(pos, jump, distSqr, true, false, 0f, 0f), 0.5f)) { SetTimer("jump"); return; } } if (shot != null && GetTimer("shoot", spreadshootInterval)) { if (StartAction(CastSkill(null, shot, distSqr, true, false, 0f, 0f), 0.5f)) { SetTimer("shoot"); return; } } Vector3 nextTarget = Utils.GenerateRandomPositionAround(ownerPos, 5f); StartAction(MoveAction(nextTarget, false, 3), 1f); }
public static T RandomEnumValue <T>() { T[] values = (T[])Enum.GetValues(typeof(T)); return(values[Random.Range(0, values.Length - 1)]); }
public override void AnalyzeSkills() { spawnSkill = (ActiveSkill)GetSkillWithTrait(SkillTraits.SpawnMinion); nextSpawnInterval = Random.Range(spawnMinInterval, spawnMaxInterval); }
private new void OnEnable() { base.OnEnable(); parts.transform.Rotate(Random.Range(minRotPos, maxRotPos), 0, Random.Range(minRotPos, maxRotPos), 0); }
Vector3 GetRandomDirection() { var theta = Random.Range(0, Mathf.PI * 2.0f); return(new Vector3(Mathf.Cos(theta), Mathf.Sin(theta), 0)); }