void CheckCollision(Collider other) { if (!IsOperationable) { return; } ObstacleItem obstacle = other.gameObject.GetComponent <ObstacleItem>(); if (obstacle != null) { if (energySkillCdController.Active) { energySkillCdController.Active = false; } else { GameControl.Instance.GameOver(); } return; } BombItem bombItem = other.gameObject.GetComponent <BombItem>(); if (bombItem != null) { bombItem.Trigger(); return; } bool eat = false; EnergyItem energyItem = other.gameObject.GetComponent <EnergyItem> (); if (energyItem != null) { energyValueController.AddValue(energyItem.Value); eat = true; } MassItem massItem = other.gameObject.GetComponent <MassItem>(); if (massItem != null) { Config config = Config.Instance; if (_massItem.Value >= massItem.Value * config.absorbLimit) { // eat it _massItem.Value += massItem.Value * config.absorbRate; eat = true; } } if (eat) { GameControl.Instance.RemoveItem(other.gameObject); } }
private static ObstacleItem Byte2Struct(byte[] arr) { int structSize = Marshal.SizeOf(typeof(ObstacleItem)); IntPtr ptemp = Marshal.AllocHGlobal(structSize); Marshal.Copy(arr, 0, ptemp, structSize); ObstacleItem rs = (ObstacleItem)Marshal.PtrToStructure(ptemp, typeof(ObstacleItem)); Marshal.FreeHGlobal(ptemp); return(rs); }
private void Load(string fileName) { if (!File.Exists(fileName)) { Logger.Error("path file do not exit. {0}", fileName); return; } FileStream fileStream = new FileStream(fileName, FileMode.Open, FileAccess.Read); int nSeek = 0; //先从文件头读取地图的长和宽 byte[] byteLen = new byte[Marshal.SizeOf(typeof(int))]; fileStream.Seek(nSeek, SeekOrigin.Begin); fileStream.Read(byteLen, 0, byteLen.Length); Height = System.BitConverter.ToInt32(byteLen, 0); nSeek += byteLen.Length; byte[] byteWid = new byte[Marshal.SizeOf(typeof(int))]; fileStream.Seek(nSeek, SeekOrigin.Begin); fileStream.Read(byteWid, 0, byteWid.Length); Width = System.BitConverter.ToInt32(byteWid, 0); nSeek += byteWid.Length; int nReadLen = Marshal.SizeOf(typeof(ObstacleItem)); byte[] read = new byte[nReadLen]; mSearchGrid = new StaticGrid(Width * 2 + 1, Height * 2 + 1); byte[][] mat = new byte[Width * 2 + 1][]; for (int i = 0; i < Width * 2 + 1; i++) { mat[i] = new byte[Height * 2 + 1]; } for (int i = 0; i < (Height * 2 + 1) * (Width * 2 + 1); ++i) { fileStream.Seek(nSeek, SeekOrigin.Begin); fileStream.Read(read, 0, nReadLen); nSeek += nReadLen; ObstacleItem info = Byte2Struct(read); mat[(int)(info.Fx * 2)][(int)(info.Fy * 2)] = (byte)info.Value; } mSearchGrid.Reset(mat); mParam = new JumpPointParam(mSearchGrid, new GridPos(0, 0), new GridPos(0, 0), true, true, false, HeuristicMode.MANHATTAN); }
protected List <PlaceHolder> GetPlaceHolderList(int num, ObstacleClass oClass) { int maxPercent = 0; int[] indexList = new int[num]; int listBaseIndex = 0; int maxIndex = 0; int maxValue = 0; ObstacleItem[] sources; if (oClass == ObstacleClass.Static) { sources = new ObstacleItem[obstacleSources.Length]; obstacleSources.CopyTo(sources, 0); } else { sources = new ObstacleItem[dinamicSources.Length]; dinamicSources.CopyTo(sources, 0); } for (int obsIndex = 0; obsIndex < sources.Length; obsIndex++) { ObstacleItem item = sources[obsIndex]; if (item.percentage > maxValue) { maxValue = item.percentage; maxIndex = obsIndex; } maxPercent += item.percentage; } //firstpass for (int obsIndex = 0; obsIndex < sources.Length; obsIndex++) { ObstacleItem item = sources[obsIndex]; item.Weight = item.percentage / (float)maxPercent; int firstPassTotal = Mathf.FloorToInt(item.Weight * num); int i = 0; for (i = 0; i < firstPassTotal; i++) { indexList[listBaseIndex + i] = obsIndex; item.TotalInScene++; } listBaseIndex += i; } //secondpass if (listBaseIndex < num) { int difference = num - listBaseIndex; for (int i = 0; i < difference; i++) { indexList[listBaseIndex + i] = maxIndex; sources[maxIndex].TotalInScene++; } } //scrumble List <int> supportList = new List <int>(indexList); List <PlaceHolder> returnList = new List <PlaceHolder>(); for (int i = 0; i < indexList.Length; i++) { int randomIdx = Random.Range(0, supportList.Count); int sourceIndex = supportList[randomIdx]; supportList.RemoveAt(randomIdx); PlaceHolder pl = new PlaceHolder(); ObstacleItem item = sources[sourceIndex]; pl.item = item; returnList.Add(pl); } return(returnList); }
void PlaceObstacles(int level) { int objCounter = 1; if (gameManagers.GetComponent <GameplayManager>().LearningPhaseDone || level == 0) { if (level == 0) { level = 1; } foreach (PlaceHolder placeholder in obstaclesPositionsList[level - 1]) { ObstacleItem item = placeholder.item; if (item.obstacle.name.Contains("turret")) { item.obsClass = ObstacleClass.GroupDynamic; } else if (item.obstacle.name.Contains("pole") || item.obstacle.name.Contains("ball")) { item.obsClass = ObstacleClass.GroupStatic; } GameObject obstacleObject = null; Obstacle obsComp = null; if (item.obsClass == ObstacleClass.Static) { obstacleObject = (GameObject)GameObject.Instantiate(item.obstacle); obsComp = obstacleObject.AddComponent <Obstacle>(); obsComp.name = item.obstacle.name; obsComp.currentToken = placeholder.token; obsComp.isAnimated = false; obsComp.hasChild = false; obstacleObject.name = "staticObject" + objCounter; //BoxCollider coll = obstacleObject.AddComponent<BoxCollider>(); //coll.isTrigger = true; } else if (item.obsClass == ObstacleClass.Dynamic) { obstacleObject = (GameObject)GameObject.Instantiate(item.obstacle); obsComp = obstacleObject.AddComponent <Obstacle>(); obsComp.name = item.obstacle.name; obsComp.currentToken = placeholder.token; obsComp.isAnimated = true; obsComp.hasChild = false; obsComp.stopTrasversal = item.minTrasversal; //obsComp.isActive = true; obstacleObject.name = "dynamicObject" + objCounter; if (level > 0) { obsComp.SetSpeed(levelConfigs[level - 1].obstacleSpeeds[item.obstacle.name]); } } else if (item.obsClass == ObstacleClass.GroupStatic) { float childWidth = 1.5f; if (item.obstacle.name.Contains("ball")) { childWidth = 2.0f; } obstacleObject = new GameObject("stObstacleGroup" + objCounter); float trasvGap = placeholder.item.maxTrasversal - placeholder.item.minTrasversal; float tokenGap = trasvGap * 0.5f * placeholder.token.width; int childNum = Mathf.CeilToInt(tokenGap / childWidth); for (int i = 0; i < childNum; i++) { GameObject child = (GameObject)GameObject.Instantiate(item.obstacle); child.name = "stgroup" + objCounter.ToString() + "_" + i.ToString(); child.transform.parent = obstacleObject.transform; Vector3 childPos = new Vector3(0.0f, 0.0f, childWidth * i); child.transform.position = childPos; } obsComp = obstacleObject.AddComponent <Obstacle>(); obsComp.name = item.obstacle.name; obsComp.currentToken = placeholder.token; obsComp.isAnimated = false; obsComp.hasChild = true; obsComp.isActive = true; obsComp.stopTrasversal = item.minTrasversal; } else if (item.obsClass == ObstacleClass.GroupDynamic) { float childWidth = 1.5f; obstacleObject = new GameObject("dyObstacleGroup" + objCounter); float trasvGap = placeholder.item.maxTrasversal - placeholder.item.minTrasversal; float tokenGap = trasvGap * 0.5f * placeholder.token.width; int childNum = Mathf.CeilToInt(tokenGap / childWidth); for (int i = 0; i < childNum; i++) { GameObject child = (GameObject)GameObject.Instantiate(item.obstacle); child.name = "dygroup" + objCounter.ToString() + "_" + i.ToString(); child.transform.parent = obstacleObject.transform; Vector3 childPos = new Vector3(0.0f, 0.0f, childWidth * i); child.transform.position = childPos; } obsComp = obstacleObject.AddComponent <Obstacle>(); obsComp.name = item.obstacle.name; obsComp.currentToken = placeholder.token; obsComp.isAnimated = true; obsComp.hasChild = true; //obsComp.isActive = true; obsComp.stopTrasversal = item.minTrasversal; if (level > 0) { obsComp.SetSpeed(levelConfigs[level - 1].obstacleSpeeds[item.obstacle.name]); } } if (level == 0) { obsComp.soundEnabled = true; obsComp.soundVolume = 100; } else { obsComp.soundEnabled = (volumesByLevel[level - 1] > 0); obsComp.soundVolume = volumesByLevel[level - 1]; } if (level > 0) { obsComp.SetAlpha(levelConfigs[level - 1].obstacleAlphas[item.obstacle.name]); } obstaclesList.Add(obsComp); obstacleObject.transform.parent = obstacleParent; obstacleObject.transform.position = placeholder.position; Vector3 tokenDirection = placeholder.token.gameObject.transform.TransformDirection(Vector3.forward); bool toBeRotated = (90.0f - Vector3.Angle(Vector3.forward, tokenDirection)) > 10.0f; if (toBeRotated) { obstacleObject.transform.RotateAround(Vector3.up, -Mathf.PI * 0.5f); } objCounter++; AddObstacleByToken(placeholder.token, obsComp); } } progressSignals.SendSignal(this, new ProgressSignal(ProgressSignalType.OnObstaclePlaced)); }
private static void initInfo() { TileItemType type; items = new TileItem[999]; //NONE type = TileItemType.NONE; items[(int)type] = new NoItem(); items[(int)type].Fonction = TileItemFonction.NONE; //OBSTACLE type = TileItemType.OBSTACLE; items[(int)type] = new ObstacleItem(); items[(int)type].Fonction = TileItemFonction.OBSTACLE; //RESSOURCE type = TileItemType.RESOURCE_COMMON_BODY; items[(int)type] = new ResourceBodyItem(200); items[(int)type].Fonction = TileItemFonction.RESOURCE; //RESSOURCE type = TileItemType.RESOURCE_COMMON_SOUL; items[(int)type] = new ResourceSoulItem(200); items[(int)type].Fonction = TileItemFonction.RESOURCE; //RESSOURCE type = TileItemType.RESOURCE_RARE_BODY; items[(int)type] = new ResourceBodyRareItem(50); items[(int)type].Fonction = TileItemFonction.RARE_RESOURCE; //RESSOURCE type = TileItemType.RESOURCE_RARE_SOUL; items[(int)type] = new ResourceSoulRareItem(50); items[(int)type].Fonction = TileItemFonction.RARE_RESOURCE; //BUILD type = TileItemType.BUILD_AREA_BODY; items[(int)type] = new BuildAreaBodyItem(); items[(int)type].Fonction = TileItemFonction.BUILD_AREA; items[(int)type].MaintenanceCellCostRate = 1; items[(int)type].CostCells = 30; items[(int)type].SynergyMode = TileItemSynergyMode.ADJACENT; //HARVEST type = TileItemType.HARVESTOR_BODY; items[(int)type] = new HarvestorBodyItem(); items[(int)type].Fonction = TileItemFonction.HARVEST; items[(int)type].CostCells = 50; //GENERATOR type = TileItemType.GENERATOR_BODY; items[(int)type] = new GeneratorBodyItem(); items[(int)type].Fonction = TileItemFonction.GENERATE; items[(int)type].CostCells = 65; items[(int)type].CostNutrients = 30; items[(int)type].SynergyMode = TileItemSynergyMode.DIAGONAL; //RADIANCE type = TileItemType.RADIANCE_AREA_BODY; items[(int)type] = new RadianceAreaBodyItem(); items[(int)type].Fonction = TileItemFonction.RADIANCE_AREA; items[(int)type].MaintenanceCellCostRate = 2; items[(int)type].CostCells = 60; items[(int)type].CostNutrients = 25; //BUILD type = TileItemType.BUILD_AREA_SOUL; items[(int)type] = new BuildAreaSoulItem(); items[(int)type].Fonction = TileItemFonction.BUILD_AREA; items[(int)type].MaintenanceThoughtCostRate = 5; items[(int)type].CostThoughts = 30; items[(int)type].CostIdeas = 15; //GENERATOR type = TileItemType.GENERATOR_SOUL; items[(int)type] = new GeneratorSoulItem(); items[(int)type].Fonction = TileItemFonction.GENERATE; items[(int)type].CostThoughts = 150; items[(int)type].SynergyMode = TileItemSynergyMode.HORIZONTAL; //HARVEST type = TileItemType.HARVESTOR_SOUL; items[(int)type] = new HarvestorSoulItem(); items[(int)type].Fonction = TileItemFonction.HARVEST; items[(int)type].CostThoughts = 30; items[(int)type].CostIdeas = 10; //RADIANCE type = TileItemType.RADIANCE_AREA_SOUL; items[(int)type] = new RadianceAreaSoulItem(); items[(int)type].Fonction = TileItemFonction.RADIANCE_AREA; items[(int)type].MaintenanceThoughtCostRate = 3; items[(int)type].MaintenanceIdeaCostRate = 1; items[(int)type].CostThoughts = 25; items[(int)type].CostIdeas = 5; items[(int)type].SynergyMode = TileItemSynergyMode.VERTICAL; //VIRUS type = TileItemType.VIRUS; items[(int)type] = new VirusItem(); items[(int)type].Fonction = TileItemFonction.HOSTILE; //NIGHTMARE type = TileItemType.NIGHTMARE; items[(int)type] = new NightmareItem(); items[(int)type].Fonction = TileItemFonction.HOSTILE; //ORGAN type = TileItemType.ORGAN; items[(int)type] = new OrganItem(); items[(int)type].Fonction = TileItemFonction.POI; //CORRUPTED ORGAN type = TileItemType.CORRUPTED_ORGAN; items[(int)type] = new CorruptedOrganItem(); items[(int)type].Fonction = TileItemFonction.POI; //FEELING type = TileItemType.FEELING; items[(int)type] = new FeelingItem(); items[(int)type].Fonction = TileItemFonction.POI; //CORRUPTED FEELING type = TileItemType.CORRUPTED_FEELING; items[(int)type] = new CorruptedFeelingItem(); items[(int)type].Fonction = TileItemFonction.POI; }