//when we add a new block, does it block the current path? public void ShouldRecalcPathBlocked(GameCube placedIn) { //Since we change currentPaths in the foreach loop, we have to cache the paths as they are //so we can verify state Dictionary <GameCube, List <GameCube> > paths = new Dictionary <GameCube, List <GameCube> > (); foreach (KeyValuePair <GameCube, List <GameCube> > kvp in currentPaths) { paths [kvp.Key] = currentPaths [kvp.Key]; } foreach (KeyValuePair <GameCube, List <GameCube> > path in paths) { if (path.Value.Contains(placedIn)) { CalcEnemyPath(path.Key); foreach (KeyValuePair <GameCube, List <Enemy> > enemies in currentEnemiesByPath) { foreach (Enemy e in enemies.Value) { e.SetPath(currentPaths [path.Key]); } } } } }
/// <summary> /// 在盘面空位置上随机添加GameCube /// </summary> private void AddCube() { //先获取到所有空位置 List <Node> tempList = new List <Node> (); for (int i = 0; i < mNodes.Length; i++) { if (!mNodes [i].mGameCube) { tempList.Add(mNodes [i]); } } int pos = Random.Range(0, (tempList.Count - 1)); Debug.Log("positon=" + tempList [pos].mPosX + "-" + tempList [pos].mPosY + ",index=" + pos); GameCube cube = Instantiate(mCubePrefab, tempList [pos].transform.position, Quaternion.identity) as GameCube; //乱入数,2或者4 int num = Random.value > 0.4?2:4; if (num == 2) { cube.mValue = 2; cube.GetComponent <SpriteRenderer> ().sprite = cube.mSprites [0]; } else { cube.mValue = 4; cube.GetComponent <SpriteRenderer> ().sprite = cube.mSprites [1]; } cube.mCurrentNode = tempList [pos]; tempList [pos].mGameCube = cube; }
private GameCube MakeCube(SeededRandom dice) { GameCube toReturn = GameObject.Instantiate(cube); toReturn.Initialize(owner, dice); return(toReturn); }
void CalcEnemyPath(GameCube startCube, AStarPath suppliedPath = null) { RemoveEnemyPathUI(startCube); List <GameObject> pathTrails = new List <GameObject> (); List <GameCube> cachedPath = new List <GameCube> (); AStarPath path = (suppliedPath != null) ? suppliedPath : new AStarPath(startCube, enemyDestination); if (path.IsComplete == false) { Debug.LogError("Enemy Path Completely Blocked!"); } cachedPath.Add(startCube); while (path.IsNext()) { cachedPath.Add(path.GetNext()); } for (float i = 0; i < cachedPath.Count; i++) { pathTrails.Add(SpawnEnemyPathUI(cachedPath, (int)i, pathTrails)); } currentPaths [startCube] = cachedPath; currentPathTrails [startCube] = pathTrails; }
public List <GameCube> GetNeighbours(GameCube center) { //Non - dynamic : conceptual grid is based on position, with one cube occupying one meter Vector3Int index = this.FloorVec3(center.Position); return(GetNeighbours(center, index)); }
IEnumerator MoveTowards(GameCube t, Vector3?positionInCube = null) { this.destination = t; if (positionInCube.HasValue) { destinationPosition = positionInCube.Value; } else { destinationPosition = t.RandomPositionInBounds; } Vector3 startPos = transform.position; float dist = Vector3.Distance(startPos, destinationPosition); float movePercentage = 0f; while (movePercentage < 1f) { movePercentage += (moveSpeed * Time.deltaTime) / (dist * t.MoveCost); transform.position = Vector3.Lerp(startPos, destinationPosition, movePercentage); yield return(null); } currentCube = t; MoveToNext(); }
internal void DropNewCubeAt(int x, int y) { GameCube cube = GameObject.Instantiate <GameCube>(currentPiece.cube); // Probably unsafe. cube.Initialize(player, dice); grid[currentPiecePosition.x + x - 1, currentPiecePosition.y + y - 1] = cube; cube.transform.parent = this.transform; cube.transform.localPosition = new Vector3(currentPiecePosition.x - numCells.x / 2f + x - 1 + .5f, 0, currentPiecePosition.y - numCells.y / 2f + y - 1 + .5f); }
public void ActOnCube(GameCube gc) { if (gc.CurrentlyPointingAt == this) { //If placing if (currentID >= 0) { IPlaceable placeable = buildables [currentID].GetComponent <IPlaceable> (); GameCube.PlacementError pe = gc.CanPlace(placeable); if (pe == GameCube.PlacementError.None) { GameObject p = Instantiate(buildables [currentID]); //most of the spawning process is handled by the gamecube gc.Occupying = p; if (p.GetComponent <AudioSource>() != null) { p.GetComponent <AudioSource> ().Play(); } //spend resources ResourceManager.Instance.Spend(p.GetComponent <IPlaceable> ().BuildCost); EnemyPathManager.Instance.ShouldRecalcPathBlocked(gc); } else { //failure cases Debug.Log(pe.ToString()); } } else { GameCube.RemoveError re = gc.CanRemove(); if (re == GameCube.RemoveError.None) { ResourceManager.Instance.AddResources(gc.Occupying.GetComponent <IPlaceable> ().BuildCost); gc.Occupying = null; } else { //failure case Debug.Log(re.ToString()); } } } else { Debug.Log("Another build tool is pointed at this cube first!"); } }
void RemoveEnemyPathUI(GameCube startCube) { if (currentPathTrails.ContainsKey(startCube) && currentPathTrails[startCube] != null) { foreach (GameObject go in currentPathTrails[startCube]) { Destroy(go); } } }
// Gets the mouse position is world space (& check for Cube hits) private void GameStateUpdates() { MarkedCube = null; // reset marked Cube UpdateUI(); // update Player UI information // Shoot ray into middle of screen (marked by sight) Ray ray = Camera.main.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0f)); RaycastHit hit; if (Physics.Raycast(ray, out hit, 100f, layerMask)) { var cube = hit.transform.GetComponent <GameCube>(); // get Cube var cubeNormal = hit.normal.ToString(); // get side where Cube was hit switch (cubeNormal) // determine position for potential new Cube { case "(1.0, 0.0, 0.0)": NewCube = hit.transform.position + new Vector3(1, 0, 0); break; case "(-1.0, 0.0, 0.0)": NewCube = hit.transform.position + new Vector3(-1, 0, 0); break; case "(0.0, 1.0, 0.0)": NewCube = hit.transform.position + new Vector3(0, 1, 0); break; case "(0.0, 0.0, 1.0)": NewCube = hit.transform.position + new Vector3(0, 0, 1); break; case "(0.0, 0.0, -1.0)": NewCube = hit.transform.position + new Vector3(0, 0, -1); break; default: // no action needed break; } NewCubeSector = GameSectors.FindLast(n => n.SectorCoords == cube.ParentSector); ActionAllowed = true; // allow Build/Destroy actions if (cube.PlayerMade == true && BuildMode == false) // update time needed to destroy Cube { MarkedCube = cube; } } else { ActionAllowed = false; // no hit = disable Build/Destroy actions } }
// Method for destroy marked Player Cube private void DestroyCube(GameCube toRemove) { // Remove from list PlayerCube = PlayerMade.FindLast(n => n.sectorCoord == toRemove.ParentSector); var cubeData = PlayerCube.CubeData.Find(n => n.CubeCoords == toRemove.transform.position); PlayerCube.CubeData.Remove(cubeData); SumPlayerCubes -= 1; // decrease Total Destroy(toRemove.gameObject); // destroy Cube Game Object }
//Helper for SetPath int FindPathIndex(GameCube gc, List <GameCube> path) { for (int i = 0; i < path.Count; i++) { if (path [i] == gc) { return(i); } } return(-1); }
//------------------------------- // Method for rebuild Player Cube private void RecreatePlayerCube(GameSector sector, PlayerCubesData cubeData) { // Create Player Cube according to loaded data about this var cubePos = cubeData.CubeCoords; GameObject newCubeGO = Instantiate(PlayerCubePfbs[cubeData.Endurance - 1], new Vector3(cubePos.x, cubePos.y, cubePos.z), Quaternion.identity) as GameObject; GameCube newCube = newCubeGO.GetComponent <GameCube>(); newCubeGO.transform.parent = sector.transform; newCube.ParentSector = sector.SectorCoords; sector.Cubes.Add(newCube); }
public KeyValuePair <string, CS_CreateCube> CreateCube(string id, GameCube cube) { var pair = new KeyValuePair <string, CS_CreateCube>("CreateCube", new CS_CreateCube() { Id = id, NewCube = cube, }); SendLocal(pair.Key, pair.Value.Map <SC_CreateCube>()); Send(pair.Key, pair.Value); return(pair); }
private void RemoveCubeFromGrid(GameCube cube) { for (int x = 0; x < numCells.x; x++) { for (int y = 0; y < numCells.y; y++) { if (grid[x, y] == cube) { grid[x, y] = null; return; } } } Debug.LogWarning("Warning! Attempt to remove Cube that doesn't exist!"); }
// Use this for initialization void Start() { gridWidth = 8; gridHeight = 5; // initial values turnLength = 2f; gameLength = 120f; turnTimer = 0f; gameTimer = gameLength; score = 0; // scoring values samePlusPoints = 10; rainbowPlusPoints = 5; sameDoublePlusPoints = 40; rainbowDoublePlusPoints = 20; mixedDoublePlusPoints = 30; // available colors cubeColors = new Color[] { Color.white, Color.gray, Color.black, Color.blue, Color.green, Color.red, Color.yellow }; colorValues = new int[] { 0, 1, 2, 4, 8, 16, 32 }; // track the active cube. Default to -1 at initialization activeCubeX = -1; activeCubeY = -1; cubes = new GameCube[gridWidth, gridHeight]; numWhiteCubes = new int[gridHeight]; // create the grid, row by row for (int y = 0; y < gridHeight; y++) { // track the number of white cubes numWhiteCubes[y] = gridWidth; // create each cube in the row for (int x = 0; x < gridWidth; x++) { cubes[x, y] = new GameCube(x, y, (GameObject)Instantiate(aCube, new Vector3(x * 2 - 7, y * 2 - 3, 2), Quaternion.identity)); } } // create the next cube - it's a special prefab without a script on it to avoid being clickable nextCube = new GameCube((GameObject)Instantiate(unclickableCube, new Vector3(0, 7.5f, 2), Quaternion.identity)); // start with a cube in the Next Cube area ShowNextCube(); }
public override void OnCreateCube(byte combineLv, Vector3 position) { var gameSlot = user.Slots.Random(); var serverPos = Local2Server(position); var gameCube = new GameCube() { CubeSeq = user.CubeSeq, CubeId = gameSlot.CubeId, CombineLv = combineLv, PositionX = (int)serverPos.x, PositionY = (int)serverPos.y, }; GameServer.sInstance?.CreateCube(user.Id, gameCube); }
void RecontructPath(Dictionary <GameCube, GameCube> path, GameCube current) { validPath = new Stack <GameCube> (); Queue <GameCube> pathQueue = new Queue <GameCube> (); pathQueue.Enqueue(current); while (path.ContainsKey(current)) { current = path [current]; pathQueue.Enqueue(current); } while (pathQueue.Count > 1) { validPath.Push(pathQueue.Dequeue()); } }
public override void OnDestroy() { RaycastHit hitInfo; if (Physics.Raycast(barrel.transform.position, barrel.transform.forward, out hitInfo, Mathf.Infinity)) { if (hitInfo.collider != null) { //we hit a collider GameCube cube = hitInfo.collider.GetComponent <GameCube> (); if (cube != null) { cube.OnPointedAway(); } } } base.OnDestroy(); }
internal void QueueCube(GameCube gameCube, PowerupType type) { switch (type) { case PowerupType.ATTACK: gameCube.coloredSection.material = gameCube.attackMaterial; break; case PowerupType.SHIELDS: gameCube.coloredSection.material = gameCube.shieldMaterial; break; default: Debug.LogError("Bad Cube type passed to the cube conversion manager: " + type + ", destroying Cube instead of enqueueing it."); GameObject.Destroy(gameCube.gameObject); return; } toConvert.Add(new CubeConversionRequest(gameCube, type)); }
private int GetCubesInSquare(int xCorner, int yCorner, PowerupType type) { int toReturn = 0; for (int x = 0; x < 3; x++) { for (int y = 0; y < 3; y++) { GameCube cube = grid[x + xCorner, y + yCorner]; if (cube == null) { throw new InvalidOperationException("Somehow we're trying to check the type of a null cube in GameGrid.getCubesInSquare"); } if (type == cube.type) { toReturn += 1; } } } return(toReturn); }
public void AddCube(Vector3 v, GameCube gc) { Vector3Int index = FloorVec3(v); if (this.grid.ContainsKey(index.x) == false) { this.grid [index.x] = new Dictionary <int, Dictionary <int, GameCube> > (); } if (this.grid [index.x].ContainsKey(index.y) == false) { this.grid [index.x] [index.y] = new Dictionary <int, GameCube> (); } if (this.grid [index.x][index.y].ContainsKey(index.z) == true) { Debug.LogWarning("Warning: Replacing cube in ConceptualGrid"); } this.grid [index.x] [index.y] [index.z] = gc; }
private List <GameCube> GetNeighbours(GameCube center, Vector3Int index) { if (center == null) { Debug.LogWarning("Warning: Attempting to find neighbours of a non-existent GameCube"); return(null); } List <GameCube> n = new List <GameCube> (); foreach (Vector3Int vec in NeighbourDefinition) { GameCube gc = this.GetCubeAt(new Vector3(index.x + vec.x, index.y + vec.y, index.z + vec.z)); if (gc != null) { n.Add(gc); } } return(n); }
//------------------------------ // Method for Game Cube Creation // (Dynamic batching swithed on for reducing number of batches) private void CreateGameCube(GameSector sector, Vector2 position) { int yCoord = NoiseEffect(position.x, position.y); // create 'terrain' effect GCIndex = 0; // set Cube color according to y-position if (yCoord > 2) { GCIndex = 1; } if (yCoord > 5) { GCIndex = 2; } GameObject newCubeGO = Instantiate(CubePrefabs[GCIndex], new Vector3(position.x, yCoord, position.y), Quaternion.identity) as GameObject; GameCube newCube = newCubeGO.GetComponent <GameCube>(); newCubeGO.transform.parent = sector.transform; newCube.ParentSector = sector.SectorCoords; sector.Cubes.Add(newCube); }
public bool RotateCW(bool[,] surroundings) { int newX = 0; int newY = 2; GameCube[,] newPiecemap = new GameCube[3, 3]; /* * newPiecemap[0,0] = piecemap[0,2]; * newPiecemap[0,1] = piecemap[1,2]; * newPiecemap[0,2] = piecemap[2,2]; * newPiecemap[1,0] = piecemap[0,1]; * newPiecemap[1,1] = piecemap[1,1]; * newPiecemap[1,2] = piecemap[2,1]; * newPiecemap[2,0] = piecemap[0,0]; * newPiecemap[2,1] = piecemap[1,0]; * newPiecemap[2,2] = piecemap[2,0]; */ for (int x = 0; x < 3; x++) { for (int y = 0; y < 3; y++) { newPiecemap[x, y] = piecemap[newX, newY]; newX++; if (newPiecemap[x, y] != null && surroundings[x, y] == true) { return(false); } } newY--; newX = 0; } piecemap = newPiecemap; return(true); //placeCubesCorrectly(); }
public void Spawn(string userId, GameCube gameCube, GameSlot gameSlot) { anim.Stop(); ownerId = userId; this.gameCube = gameCube; this.gameSlot = gameSlot; state = State.Idle; cubeData = XmlKey.CubeData.Find <CubeDataXml.Data>(x => x.CubeId == gameSlot.CubeId); var color = new Color(cubeData.Color[0], cubeData.Color[1], cubeData.Color[2], 1f); render.material.color = color; render.transform.localRotation = Quaternion.identity; range.material.color = new Color(color.r, color.g, color.b, 0.1f); range.transform.localScale = new Vector3(gameCube.CombineLv * 2f, gameCube.CombineLv * 2f, range.transform.localScale.z); combineLv_text.text = gameCube.CombineLv.ToString(); base.Spawn(); StartShot(); }
public virtual Cube CreateCube(GameCube gameCube) { var position = Server2Local(new Vector3(gameCube.PositionX, gameCube.PositionY, 0f)); var gameSlot = user.Slots.Find(x => x.CubeId == gameCube.CubeId); var cube = PoolFactory.Get <Cube>("Cube", position, Quaternion.identity, transform); cube.OnMove = OnMove; cube.OnCombineMove = OnCombineMove; cube.OnCombine = OnCombine; cube.OnShot = OnShot; cube.Spawn(user.Id, gameCube, gameSlot); cubes.Add(cube); user.Cubes.Add(gameCube); if (gameCube.CombineLv == 1) { user.SP -= ServerDefine.CubeSeq2NeedSP(user.CubeSeq); } user.CubeSeq++; return(cube); }
//------------------------------------- // Method for Player made Cube Creation private void CreatePlayerCube(GameSector sector) { // Create Cube from relevant Prefab GameObject newCubeGO = Instantiate(PlayerCubePfbs[CubeIndex], new Vector3(NewCube.x, NewCube.y, NewCube.z), Quaternion.identity) as GameObject; GameCube newCube = newCubeGO.GetComponent <GameCube>(); newCubeGO.transform.parent = sector.transform; newCube.ParentSector = sector.SectorCoords; sector.Cubes.Add(newCube); // probably not needed SumPlayerCubes += 1; // increase Total // Process Player Made list PlayerCube = PlayerMade.FindLast(n => n.sectorCoord == sector.SectorCoords); if (PlayerCube.CubeData == null) // no Player Cube data for Sector yet { PlayerCube.sectorCoord = sector.SectorCoords; PlayerCube.CubeData = new List <PlayerCubesData>(); PlayerCubesData cubedata = new PlayerCubesData { CubeCoords = NewCube, Endurance = newCube.Endurance }; PlayerCube.CubeData.Add(cubedata); PlayerMade.Add(PlayerCube); } else // only add new Player Cube to list { PlayerCubesData cubedata = new PlayerCubesData { CubeCoords = NewCube, Endurance = newCube.Endurance }; PlayerCube.CubeData.Add(cubedata); } }
/* * THere should always be a path the enemies can take from (each) start cube to * the enemy destination */ public bool WouldYieldNoPaths(GameCube test, float newMoveCost) { // set test cube to Mathf.Infinity float testMoveCost = test.MoveCost; test.MoveCost = newMoveCost; foreach (GameCube start in startCubes) { AStarPath path = new AStarPath(start, enemyDestination); if (path.IsComplete == false) { test.MoveCost = testMoveCost; return(false); } } test.MoveCost = testMoveCost; //there is at least one path for each start cube return(true); }
//-------------------------------------- // Controller Update method private void Update() { // Permanently active 'Keys' if (Input.GetKeyDown("q")) // Build/Destroy mode switch { if (BuildMode == false) // change mode and update UI { GameUI.transform.Find("BuildPanel").gameObject.SetActive(true); ActionText.text = "Destroy [Q]"; BuildMode = true; } else // change mode and update UI { GameUI.transform.Find("BuildPanel").gameObject.SetActive(false); ActionText.text = "Build [Q]"; BuildMode = false; } } if (Input.GetKeyDown("1")) { if (MenuActive == false) // change mode and update UI { GameUI.transform.Find("GameOptions").gameObject.SetActive(true); MenuActive = true; } else // change mode and update UI { GameUI.transform.Find("GameOptions").gameObject.SetActive(false); MenuActive = false; } } // Activated 'Keys' if (Input.GetKeyDown("f1") && MenuActive == true) // Save Game { SaveGame(); } if (Input.GetKeyDown("f2") && MenuActive == true) // Start New Game { SceneManager.LoadScene("GameScene"); } if (Input.GetKeyDown("f3") && MenuActive == true) // Load Saved Game { LoadGame(); } if (Input.GetKeyDown("f4") && MenuActive == true) // Quit Game { Application.Quit(); } if (BuildMode == true) // check for switch Player Cube prefab { if (Input.GetKeyDown("e")) // Player Cube lvl1 { CubeIndex = 0; FrameColor = new Color32(116, 231, 86, 255); } if (Input.GetKeyDown("r")) // Player Cube lvl2 { CubeIndex = 1; FrameColor = new Color32(201, 229, 107, 255); } if (Input.GetKeyDown("f")) // Player Cube lvl3 { CubeIndex = 2; FrameColor = new Color32(231, 235, 77, 255); } if (Input.GetKeyDown("g")) // Player Cube lvl4 { CubeIndex = 3; FrameColor = new Color32(231, 178, 71, 255); } } // Handle mouse actions if (Input.GetMouseButtonDown(0)) // Create Player Cube { if (BuildMode == true) { if (ActionAllowed == true) { CreatePlayerCube(NewCubeSector); } } } // Count mouse down time and destroy Player Cube when endurance reached if (Input.GetMouseButton(0) && BuildMode == false && MarkedCube == true) { DestroyCounter += Time.deltaTime; var time = (int)DestroyCounter; if (time == MarkedCube.Endurance) { DestroyCube(MarkedCube); MarkedCube = null; DestroyCounter = 0; } } else { DestroyCounter = 0; } if (Input.GetMouseButtonUp(0)) { DestroyCounter = 0; } // Check hit of some Cube & update Game GameStateUpdates(); }
// Use this for initialization void Start() { gridWidth = 8; gridHeight = 5; // initial values turnLength = 2f; gameLength = 120f; turnTimer = 0f; gameTimer = gameLength; score = 0; // scoring values samePlusPoints = 10; rainbowPlusPoints = 5; sameDoublePlusPoints = 40; rainbowDoublePlusPoints = 20; mixedDoublePlusPoints = 30; // available colors cubeColors = new Color[] {Color.white, Color.gray, Color.black, Color.blue, Color.green, Color.red, Color.yellow}; colorValues = new int[] {0, 1, 2, 4, 8, 16, 32}; // track the active cube. Default to -1 at initialization activeCubeX = -1; activeCubeY = -1; cubes = new GameCube[gridWidth, gridHeight]; numWhiteCubes = new int[gridHeight]; // create the grid, row by row for (int y = 0; y < gridHeight; y++) { // track the number of white cubes numWhiteCubes[y] = gridWidth; // create each cube in the row for (int x = 0; x < gridWidth; x++) { cubes[x,y] = new GameCube(x, y, (GameObject) Instantiate(aCube, new Vector3(x*2 - 7, y*2 - 3, 2), Quaternion.identity)); } } // create the next cube - it's a special prefab without a script on it to avoid being clickable nextCube = new GameCube((GameObject) Instantiate(unclickableCube, new Vector3(0, 7.5f, 2), Quaternion.identity)); // start with a cube in the Next Cube area ShowNextCube(); }