private void GenerateEnvironment() { //go over all the tiles on the board for (int i = 0; i < (int)worldSize.x; i++) { for (int j = 0; j < (int)worldSize.y; j++) { // Spawn plant Vector3 spawnCoordinates = (Vector3)PlayGrid.getGridCoordinates(new Vector2(i, j)); //determine if a plant should be instantiated if (Random.Range(0f, 1f) < plantDensity) { spawnVegitation(spawnCoordinates); //Instantiate(plant, spawnCoordinates, Quaternion.identity); } else if (Random.Range(0f, 1f) < NPCreatureDensity) { spawnNPCreature(spawnCoordinates, -1); //Instantiate(NPCreature, spawnCoordinates, Quaternion.Euler(0f, 0f, Random.Range(-180f, 180f))); } } } //spawn the player creatures GameObject player1 = Instantiate(playerCreature, (Vector3)PlayGrid.getGridCoordinates(new Vector2(30, 10)), Quaternion.identity); player1.GetComponent <PlayCreature>().Birth(1, new Vector2(30, 10), false); }
public void Fill(GridSpot start, int maxDistance, PlayGrid grid) { Clear(); startSpot = start; elements.Add(new MoveSetElement(startSpot, null, 0)); Explore(elements[0], 0, maxDistance, grid); }
private void GameOnGameOver(object sender, EventArgs eventArgs) { AllGamesOver = (bc.Game.IsGameOver); if (!AllGamesOver) { return; } ShowAchievement("No more moves", "GAME OVER"); #if GOOGLE_ANALYTICS EasyTracker.GetTracker().SendEvent("GameOver" + bc.Game.GameDefinition.UniqueId, "Score", null, TotalScore); EasyTracker.GetTracker().SendEvent("GameOver" + bc.Game.GameDefinition.UniqueId, "Moves", null, bc.Game.Moves); if (TotalScore == bc.Game.GameData.BestScore) { EasyTracker.GetTracker().SendEvent("BestScore" + bc.Game.GameDefinition.UniqueId, "BestScore", null, bc.Game.GameData.BestScore); } #endif ShowShare = true; PlayGrid.IsHitTestVisible = true; PlayGrid.AnimateAsync(new FadeInAnimation()); PlayButton.IsHitTestVisible = true; PlayButton.AnimateAsync(new BounceInUpAnimation()); bc.SaveData(); }
public void Load() { LoadFileName = UILoadInputField.text; PlayGrid LoadedGrig = BinaryDataHandler.Load <PlayGrid>(BinaryDataHandler.UnityFolder.stremingAsset, LoadFileName, BinaryDataHandler.DataFileExtention.map); Debug.Log(LoadedGrig._hight); _PlayGridHolder.PlayGrid = LoadedGrig; for (int x = 0; x < LoadedGrig._hight; x++) { for (int y = 0; y < LoadedGrig._width; y++) { if (LoadedGrig.PlayTiles[x, y].Tag1 != 0) { SetTile(TempletBuilder.EditPlayTiles[LoadedGrig.PlayTiles[x, y].Tag1], new Vector2Int(x, y), LoadedGrig.PlayTiles[x, y].Tag1); } if (LoadedGrig.PlayTiles[x, y].Tag2 != 0) { SetTile(TempletBuilder.EditPlayTiles[LoadedGrig.PlayTiles[x, y].Tag2], new Vector2Int(x, y), LoadedGrig.PlayTiles[x, y].Tag2); } if (LoadedGrig.PlayTiles[x, y].Tag3 != 0) { SetTile(TempletBuilder.EditPlayTiles[LoadedGrig.PlayTiles[x, y].Tag3], new Vector2Int(x, y), LoadedGrig.PlayTiles[x, y].Tag3); } if (LoadedGrig.PlayTiles[x, y].ActorIndex != 0) { SetActor(TempletActors.EditGridActors[LoadedGrig.PlayTiles[x, y].ActorIndex], new Vector2Int(x, y), LoadedGrig.PlayTiles[x, y].ActorIndex); } } } }
private GameObject SeeIfCollisionWithOtherObject(Vector3 RaycastDirection, int unitViewDistance, string tag) { float length = PlayGrid.getUnitWorldSize().x *unitViewDistance *Vector3.Magnitude(RaycastDirection); RaycastHit2D[] hit = Physics2D.RaycastAll(gameObject.transform.position, RaycastDirection.normalized, length); Debug.DrawLine(gameObject.transform.position, gameObject.transform.position + length * RaycastDirection.normalized, Color.blue, gameMaster.getRoundDuration()); for (int i = 0; i < hit.Length; i++) { if (hit[i].collider.gameObject.tag == tag) { // Calculate the distance from the NPCreature to the next float distance = Vector3.Distance(hit[i].transform.position, transform.position); if (distance < 0.00001f) { //Debug.Log("Raycast hits own collider (distance = " + distance + ")"); } else { //Debug.Log("NPCreature sees " + tag); return(hit[i].collider.gameObject); } } } return(null); }
private void Start() { TimeManager.TTStart.AddListener(TTStart); TimeManager.TTUpdate.AddListener(TTUpDate); TimeManager.TTLateUpdate.AddListener(TTLastUpDate); PlayGrid = playGidHolder.GetComponent <PlayGridHolder>().PlayGrid; _newPos = PlayGrid.GetWorldPositionCentreCell(_currentPos); }
public static bool CheckCell(PlayGrid grid, Vector2Int pos, List <Vector2Int> closeList) { if (grid.CheckIsInGrid(pos) && !closeList.Contains(pos)) { return(true); } return(false); }
// Start is called before the first frame update void Start() { DirectorMove.AddListener(TimeManager.DirectorMove); TimeManager.TTSetPause.AddListener(SetPause); Debug.Log(PlayGrid._hight); PlayGrid = playGidHolder.GetComponent <PlayGridHolder>().PlayGrid; _newPos = PlayGrid.GetWorldPositionCentreCell(_currentPos.x, _currentPos.y); AmmoLeft = AmmoReload; }
public void GenerateInfluenceMap(PlayGrid playGrid, List <Unit> EnemyUnits, List <Unit> FriendlyUnits) { for (int i = 0; i < x; i++) { for (int j = 0; j < y; j++) { //mapScores[i, j] = playGrid.DjikstraInfluence(new Vector2Int(i, j)); } } }
/*void Start() * { * _playGrid = playGidHolder.GetComponent<PlayGridHolder>().PlayGrid; * _newPos = _playGrid.GetWorldPositionCentreCell(_currentPos.x, _currentPos.y); * }*/ void Update() { //initie ga grid associer if (_playGrid == null && playGidHolder != null) { _playGrid = playGidHolder.GetComponent <PlayGridHolder>().PlayGrid; _newPos = _playGrid.GetWorldPositionCentreCell(_currentPos.x, _currentPos.y); } if (Input.GetButtonDown("Horizontal")) { if (Input.GetAxis("Horizontal") < 0) { if (_playGrid.CheckIfWalkeble((int)_playGrid.GetXY(transform.position).x, (int)_playGrid.GetXY(transform.position).y + 1)) { _newPos = _playGrid.GetWorldPositionCentreCell(_currentPos.x, _currentPos.y + 1); _currentPos = _currentPos + new Vector2Int(0, 1); } } else if (Input.GetAxis("Horizontal") > 0) { if (_playGrid.CheckIfWalkeble((int)_playGrid.GetXY(transform.position).x, (int)_playGrid.GetXY(transform.position).y - 1)) { _newPos = _playGrid.GetWorldPositionCentreCell(_currentPos.x, _currentPos.y - 1); _currentPos = _currentPos + new Vector2Int(0, -1); } } } else if (Input.GetButtonDown("Vertical")) { if (Input.GetAxis("Vertical") > 0) { if (_playGrid.CheckIfWalkeble((int)_playGrid.GetXY(transform.position).x + 1, (int)_playGrid.GetXY(transform.position).y)) { _newPos = _playGrid.GetWorldPositionCentreCell(_currentPos.x + 1, _currentPos.y); _currentPos = _currentPos + new Vector2Int(1, 0); } } else if (Input.GetAxis("Vertical") < 0) { if (_playGrid.CheckIfWalkeble((int)_playGrid.GetXY(transform.position).x - 1, (int)_playGrid.GetXY(transform.position).y)) { _newPos = _playGrid.GetWorldPositionCentreCell(_currentPos.x - 1, _currentPos.y); _currentPos = _currentPos + new Vector2Int(-1, 0); } } } transform.position = Vector3.Lerp(transform.position, _newPos, 0.5f); }
private void recycleLife(GameObject NPCreature) { // input NPCreature is destined to die. To save on computing time (destroying the gameObject for creating it later again), put it on ice outside the screen dead = true; age = 1; children = 0; satiation = satiationMax; NPCreature.transform.position = PlayGrid.getOutsideOfScreenCoordinates(); NPCreaturesInTheAfterlife.Add(NPCreature); }
private void Awake() { GameObject LoadData = GameObject.Find("MainMenu"); _PlayGridHolder = GetComponent <PlayGridHolder>(); savePlayGrid = LoadData.GetComponent <MainMenuHendler>().PlayGrid; newPlayGrid = _PlayGridHolder.CreatNewPlaygrid(savePlayGrid._hight, savePlayGrid._width, savePlayGrid._cellsize, savePlayGrid.GetGridOrinie()); _gameManager = GetComponent <GameManager>(); Load(); Destroy(LoadData); }
public List <Cell <int> > getEmptyCellInSquare(int _x, int _y) { int minX = Square.getMinX(_x, PuzzleOrder); int maxX = Square.getMaxX(_x, PuzzleOrder); int minY = Square.getMinX(_y, PuzzleOrder); int maxY = Square.getMaxX(_y, PuzzleOrder); return(PlayGrid.FindAll(cell => cell.X >= minX && cell.X <= maxX && cell.Y >= minY && cell.Y <= maxY && cell.Value == Int32.MinValue)); }
private void stepForward(Vector2 directionVector) { TargetUnitPosition = UnitPosition + directionVector; if (!PlayGrid.checkIfOutOfBounds(TargetUnitPosition)) { // Take a step forward (update current NPCreature position) gameObject.GetComponent <Transform>().position = PlayGrid.getGridCoordinates(TargetUnitPosition); } else { // flip direction vector gameObject.transform.Rotate(0, 0, 180); } }
public List <int> getPlacedValueInSquare(int _x, int _y) { int minX = Square.getMinX(_x, PuzzleOrder); int maxX = Square.getMaxX(_x, PuzzleOrder); int minY = Square.getMinX(_y, PuzzleOrder); int maxY = Square.getMaxX(_y, PuzzleOrder); var cellsOfSquare = PlayGrid.FindAll(cell => cell.X >= minX && cell.X <= maxX && cell.Y >= minY && cell.Y <= maxY && cell.Value != Int32.MinValue); return(cellsOfSquare.Select(cell => cell.Value).ToList()); }
public MainWindow() { InitializeComponent(); GameTimer.Interval = TimeSpan.FromMilliseconds(120); LblSpeed.Content = "Geschwindigkeit: 120ms"; GameTimer.Tick += GameTimer_Elapsed; PreviewKeyDown += MainWindow_PreviewKeyDown; playGrid = new PlayGrid(GrdField, 20); playGrid.PlaceSnake(0, 0); GameTimer.Start(); }
private void Reproduce() { int i = Mathf.RoundToInt(Random.Range(1f, PlayGrid.PlayFieldSize.x - 1)); int j = Mathf.RoundToInt(Random.Range(1f, PlayGrid.PlayFieldSize.x - 1)); Vector3 spawnCoordinates = (Vector3)PlayGrid.getGridCoordinates(new Vector2(i, j)); board.spawnNPCreature(spawnCoordinates, 0); if (outputStats) { Debug.Log("NPCreatures reproduced"); } //Debug.Log("NPCreatures created a child at [" + i + "," + j + "]"); children++; }
private void PlayPLAnimate() //play button animation for playlist { DoubleAnimation Anim = new DoubleAnimation(); Anim.Completed += delegate { if (CurrentList.Count > 0) { ChangeAudio(CurrentList[0]); // after the end of the animation, start playback from the first song in the playlist } }; Anim.From = 0; Anim.To = 1; Anim.Duration = new Duration(TimeSpan.FromSeconds(1)); PlayGrid.BeginAnimation(OpacityProperty, Anim); }
public Grid(Grid _g) { this.PuzzleOrder = _g.PuzzleOrder; this.SquareOrder = _g.SquareOrder; playGrid = new List <Cell <int> >(); fixedValue = new List <Cell <int> >(); foreach (Cell <int> cell in _g.FixedValue) { this.fixedValue.Add(new Cell <int>(cell)); } foreach (Cell <int> cell in _g.playGrid) { PlayGrid.Add(new Cell <int>(cell)); } }
private void PlayPLAnimate() //анимация кнопки воспроизвести для плейлиста { DoubleAnimation Anim = new DoubleAnimation(); Anim.Completed += delegate { if (CurrentList.Count > 0) { ChangeAudio(CurrentList[0]); // после окончания анимации начинаем воспроизведение с первой песни плейлиста } }; Anim.From = 0; Anim.To = 1; Anim.Duration = new Duration(TimeSpan.FromSeconds(1)); PlayGrid.BeginAnimation(OpacityProperty, Anim); }
public void Initialize() { print("Grid Manager Initialized"); gm = GetComponent <GameManager>(); grid = gm.grid; em = GetComponent <EventManager>(); mainCanvas = gm.mainCanvas; selectedPosition = new int[gm.nbOfPlayers][]; for (int i = 0; i < gm.nbOfPlayers; i++) { selectedPosition[i] = new int[3]; selectedPosition[i][0] = -1; } }
private async void PlayButton_Click(object sender, RoutedEventArgs routedEventArgs) { await PlayGrid.AnimateAsync(new FadeOutAnimation()); PlayGrid.IsHitTestVisible = false; #if GOOGLE_ANALYTICS EasyTracker.GetTracker().SendEvent("GameStart" + bc.Game.GameDefinition.UniqueId, "Start", null, 0); #endif await bc.Clear(); bc.Game.Setup(); TotalScore = 0; AllGamesOver = false; }
void Awake() { if (TileMapSetter != null) { MainMenuHendler info = GameObject.Find("MainMenu").GetComponent <MainMenuHendler>(); Hight = info.NewHauteur; Width = info.NewLargeur; PlayGrid = new PlayGrid(info.NewHauteur, info.NewLargeur, CellSize, Origin); TileMapSetter.ChangeNameSave(info.NewName); Destroy(info.gameObject); Debug.Log("hauter" + info.NewHauteur + " Largeur " + info.NewLargeur); EditorCam.Xmax = PlayGrid._width * PlayGrid._cellsize; EditorCam.Ymax = PlayGrid._hight * PlayGrid._cellsize; } else { PlayGrid = new PlayGrid(Hight, Width, CellSize, Origin); } }
protected void TTStart() { // verifie les places disponibles if (Direction == direction.haut) { _nextPos = _currentPos + new Vector2Int(0, 1); } else { _nextPos = _currentPos + new Vector2Int(0, -1); } if (PlayGrid.CheckIfWalkeble(_nextPos.x, _nextPos.y)) { _willMove = true; } else { if (Direction == direction.haut) { Direction = direction.bas; _nextPos = _currentPos + new Vector2Int(0, -1); } else { Direction = direction.haut; _nextPos = _currentPos + new Vector2Int(0, 1); } if (PlayGrid.CheckIfWalkeble(-_nextPos.x, _nextPos.y)) { _willMove = true; } } // effectue l'action de bouger if (_willMove) { PlayGrid.GetPlayTile(_currentPos).GridActor = null; PlayGrid.GetPlayTile(_nextPos).GridActor = null; _currentPos = _nextPos; _newPos = PlayGrid.GetWorldPositionCentreCell(_currentPos); } }
bool isValidGridPos() { foreach (Transform child in transform) { Vector2 v = PlayGrid.roundVec2(child.position); // Not inside Border? if (!PlayGrid.insideBorder(v)) { return(false); } // Block in grid cell (and not part of same group)? if (PlayGrid.grid[(int)v.x, (int)v.y] != null && PlayGrid.grid[(int)v.x, (int)v.y].parent != transform) { return(false); } } return(true); }
public void UIToPlayMode() { PannelLoad.SetActive(true); //List<GameObject> oldSaves = new List<GameObject>(); foreach (Transform child in PannelDesSaves.transform) { Destroy(child.gameObject, 0.01f); } string[] saves = BinaryDataHandler.CheckForFiles(BinaryDataHandler.UnityFolder.stremingAsset); foreach (var save in saves) { if (Path.GetExtension(save) == ".map") { GameObject bouton = Instantiate(BoutonSave, PannelDesSaves.transform); bouton.GetComponentInChildren <TMP_Text>().text = Path.GetFileNameWithoutExtension(save); bouton.GetComponent <Button>().onClick.AddListener(delegate { PlayGrid = BinaryDataHandler.Load <PlayGrid>(BinaryDataHandler.UnityFolder.stremingAsset, Path.GetFileNameWithoutExtension(save), BinaryDataHandler.DataFileExtention.map); SceneManager.LoadScene(1); }); } } }
override public string ToString() { string s = ""; int numberOfDigit = (int)Math.Floor(Math.Log10(SquareOrder) + 1); for (int row = 0; row < SquareOrder; row++) { for (int column = 0; column < SquareOrder; column++) { int number = PlayGrid.Find(cell => cell.X == column && cell.Y == row).Value; if (number != Int32.MinValue) { s = s + padCentre(number.ToString(), numberOfDigit); } else { s = s + padCentre("", numberOfDigit); } s = s + "|"; } s = s.Remove(s.Length - 1); s = s + " -> " + getCostRow(row); s = s + System.Environment.NewLine; } for (int column = 0; column < SquareOrder; column++) { s = s + padCentre("v", numberOfDigit) + " "; } s = s + System.Environment.NewLine; for (int column = 0; column < SquareOrder; column++) { s = s + padCentre(getCostColumn(column).ToString(), numberOfDigit) + "|"; } s = s.Remove(s.Length - 1); s = s + " -> " + getCost() + System.Environment.NewLine; return(s); }
void updateGrid() { // Remove old children from grid for (int y = 0; y < PlayGrid.h; ++y) { for (int x = 0; x < PlayGrid.w; ++x) { if (PlayGrid.grid[x, y] != null) { if (PlayGrid.grid[x, y].parent == transform) { PlayGrid.grid[x, y] = null; } } } } // Add new children to grid foreach (Transform child in transform) { Vector2 v = PlayGrid.roundVec2(child.position); PlayGrid.grid[(int)v.x, (int)v.y] = child; } }
public PlayGrid CreatNewPlaygrid(int hight, int width, float cellSize, Vector3 origine) { PlayGrid = new PlayGrid(hight, width, cellSize, origine); return(PlayGrid); }
private IEnumerator MoveCoroutine() { // Randomise the distance walked (if NPCreature is not hungry) int movePoints; bool reproduce = false; if (Hungry() || Horny()) { movePoints = speed; } else { movePoints = Mathf.RoundToInt(Random.Range(0f, speed)); } // Start walking while (movePoints > 0) { UnitPosition = PlayGrid.getUnitCoordinates((Vector2)gameObject.GetComponent <Transform>().transform.position); directionVector = Vector2.zero; // Check if the NPCreature is hungry. If yes, determine in which direction there is a plant with the most nutrition if (Hungry()) { directionVector = FindPlant(); //Debug.Log("Highest nutriotional plant at Vector [" + directionVector.x + "," + directionVector.y + "]"); } else if (Horny()) { directionVector = findMate(); } if (directionVector == Vector2.zero) //If the directionVector has remained zero (i.e., plant or mate not found) { directionVector = chooseRandomWalkingDirection(); } // Take a step forward (checking for collision with other NPCreatures) GameObject NPCreatureObstacle = checkforNPColission(directionVector); if (NPCreatureObstacle == null) { stepForward(directionVector); } else if (Horny() && NPCreatureObstacle.GetComponent <NPCreature>().Horny()) { // collision between two horny NPCreatures. //Debug.Log("Horny NPCreatures collided"); reproduce = true; } yield return(null); // Use Player overlap script to munch away plant if there is any in the vicinity //check for a collider overlap Collider2D[] encounters = new Collider2D[2]; boxcol.OverlapCollider(contactfilter, encounters); foreach (Collider2D encounter in encounters) { if (encounter != null) { if (encounter.gameObject.tag == "Plant" && satiation > 0) { satiation += encounter.gameObject.GetComponent <Plant>().GetEaten(); satiation = Mathf.Clamp(satiation, 0f, satiationMax); } else if (encounter.gameObject.tag == "NPCreature") // if NPCreatures accidentally step into the same space (which was empty), they will reproduce //Debug.Log("NPCreatures overlapping at [" + PlayGrid.getUnitCoordinates(gameObject.transform.position).x + "," + PlayGrid.getUnitCoordinates(gameObject.transform.position).y + "]"); { if (Horny() && encounter.gameObject.GetComponent <NPCreature>().Horny()) { reproduce = true; } } } } if (reproduce) { Reproduce(); } movePoints--; } }