public void createBlob() { blobsW = new GameObject[nbW]; blobsB = new GameObject[nbB]; for (int i = 0; i < nbW + nbB; i++) { GameObject obj = GameObject.CreatePrimitive(PrimitiveType.Sphere); obj.layer = 11; // layer scene3d //BlobScript bo = new BlobScript(obj); BlobScript bo = obj.AddComponent("BlobScript") as BlobScript; Rigidbody rigid = obj.AddComponent <Rigidbody>(); obj.collider.material = (PhysicMaterial)Resources.Load("ball physics Material"); bo.setGo(obj); bo.setManagerScript(this); rigid.useGravity = true; rigid.mass = 0.2f; //obj.AddComponent<BlobScript> (); obj.transform.localScale = new Vector3((float)0.5, (float )0.5, (float)0.5); obj.transform.parent = BlobManager.transform; //obj.AddComponent<SphereCollider> (); obj.transform.localPosition = new Vector3(0, 0, 0); if (i < nbW) { blobsW[i] = obj; } else { blobsB[i - nbW] = obj; } } }
//Bound to range, not needed as handled clearned elsewhere public Vector2 FindSafestInRange(BlobScript myPos, List <BlobScript> otherPosition, int range) { var loc = myPos.GetGridLocation(); MarkDownGridSpiral(myPos, otherPosition); var leftBound = (int)(loc.x - range > 0 ? loc.x - range : 0); var RightBound = (int)(loc.x + range < Grid.Length ? loc.x + range : 0); var topBound = (int)(loc.y - range > 0 ? loc.y - range : 0); var bottomBound = (int)(loc.y + range < Grid.Length ? loc.y + range : 0); int min = 100; Vector2 safest = new Vector2(); for (int i = leftBound; i < RightBound; i++) { for (int j = topBound; j < bottomBound; j++) { if (Grid[i, j] < min) { min = Grid[i, j]; safest.x = i; safest.y = j; } } } return(safest); }
void OnTriggerEnter2D(Collider2D hitInfo) { //Debug.Log(hitInfo.name); PlayerHealth Player = hitInfo.GetComponent <PlayerHealth>(); BlobScript blob = hitInfo.GetComponent <BlobScript>(); if (Player != null) { Player.TakeDamage(damage); Destroy(bullet); } if (hitInfo.tag == "Walls") { Destroy(bullet); } if (hitInfo.tag == "Blob") { blob.TakeDamage(damage); Destroy(bullet); } if (hitInfo.tag == "Bubble") { Destroy(bullet); } }
void OnTriggerEnter2D(Collider2D hitInfo) { //Debug.Log(hitInfo.name); EnemyHealth enemy = hitInfo.GetComponent <EnemyHealth>(); BlobScript blob = hitInfo.GetComponent <BlobScript>(); if (enemy != null) { enemy.TakeDamage(damage); Destroy(bullet); } if (hitInfo.tag == "Walls") { Destroy(bullet); } if (hitInfo.tag == "Blob") { blob.TakeDamage(damage); Destroy(bullet); } if (hitInfo.tag == "Mold") { Destroy(bullet); } }
//clean up parent/attacker references //this should be moved into base attack, with the arrow being passed in as a references public void ShowAttack(BlobScript target, BlobScript source) { //var NewArrow = Instantiate() var pointyThing = (GameObject)Resources.Load("Prefabs/PointyArrow", typeof(GameObject)); //Debug.Log(pointyThing); var myThing = UnityEngine.Object.Instantiate(pointyThing, new Vector3(source.transform.position.x, source.transform.position.y, source.transform.position.z - 1), Quaternion.identity); ArrowScript myScript = myThing.GetComponent <ArrowScript>(); myScript.setTargetAndParent(source, target, this, 0); }
void Start() { parentScript = this.GetComponentInParent <BlobScript>(); if (parentScript != null) { parentFound = true; thisButtonText = this.GetComponentInChildren <Text>(); if (buttonName != null && thisButtonText != null) { thisButtonText.text = buttonName; } //thisButtonText.text = buttonName; } }
public override bool FireAttack(BlobScript source, List <BlobScript> targets) { //Debug.Log("Firing Punch Attack"); //Not done, needs a lot of work. foreach (var target in targets) { ShowAttack(target, source); int dmg = source.GetAttack() - target.GetDefense(); if (dmg < 0) { dmg = 0; } //Debug.Log(dmg); target.TakeDamage(dmg); source.ChargeUlt(dmg, 0); } return(true); }
//Not Bound to range, not needed as handled clearned elsewhere public Vector2 FindSafestInRange(BlobScript myPos, List <BlobScript> otherPosition) { var loc = myPos.GetGridLocation(); MarkDownGridSpiral(myPos, otherPosition); var min = 100; var safest = new Vector2(); for (int i = 0; i < Grid.GetLength(0); i++) { for (int j = 0; j < Grid.GetLength(1); j++) { if (Grid[i, j] < min) { min = Grid[i, j]; safest.x = i; safest.y = j; } } } return(safest); }
//TODO if team members go back to back can skip this to save frames, ADD CHECK FOR THIS /// <summary> /// Using a spiral pattern mark the threat provided by the given team /// </summary> public void MarkDownGridSpiral(BlobScript myPos, List <BlobScript> otherPositions) { Grid = new int[20, 20]; var touched = new bool[20, 20]; List <Tuple <int, int> > foundItems = new List <Tuple <int, int> >(); for (int i = 0; i < Grid.GetLength(0); i++) { for (int j = 0; j < Grid.GetLength(1); j++) { Grid[i, j] = 0; touched[i, j] = false; } } foreach (var item in otherPositions) { var itemLoc = item.GetGridLocation(); touched[(int)itemLoc.x, (int)itemLoc.y] = false; foundItems.Add(new Tuple <int, int>((int)itemLoc.x, (int)itemLoc.y)); touched[(int)itemLoc.x, (int)itemLoc.y] = true; } foreach (var item in foundItems) { var currX = item.Item1; var currY = item.Item2; int direction = 0; var count = 0; var toAdd = 6; var numMoves = 1; var upNumMoves = false; while (count < numMovesSpiral) { //number of moves determines how for (int i = 0; i < numMoves; ++i) { switch (direction) { //Up case 0: if (i == numMoves - 1) { toAdd -= 1; } currX += 1; try { if (Grid[currX, currY] != 99) { if (toAdd < 0 && touched[currX, currY]) { break; } if (toAdd > 0 && Grid[currX, currY] < 0) //safe? areas from an earlier spiral are no longer safe { Grid[currX, currY] = 0; } Grid[currX, currY] += toAdd; } touched[currX, currY] = true; } catch (IndexOutOfRangeException) { //swallow out of bounds } break; //Right case 1: currY += 1; try { if (Grid[currX, currY] != 99) { if (toAdd < 0 && touched[currX, currY]) // don't reduce danger areas of other spirals { break; } if (toAdd > 0 && Grid[currX, currY] < 0) //safe? areas from an earlier spiral are no longer safe { Grid[currX, currY] = 0; } Grid[currX, currY] += toAdd; } touched[currX, currY] = true; } catch (IndexOutOfRangeException) { //swallow out of bounds } if (i == numMoves - 1) { upNumMoves = true; } break; // Down case 2: currX -= 1; try { if (Grid[currX, currY] != 99) { if (toAdd < 0 && touched[currX, currY]) // don't reduce danger areas of other spirals { break; } if (toAdd > 0 && Grid[currX, currY] < 0) //safe? areas from an earlier spiral are no longer safe { Grid[currX, currY] = 0; } Grid[currX, currY] += toAdd; } touched[currX, currY] = true; } catch (IndexOutOfRangeException) { //swallow out of bounds } break; //Left case 3: currY -= 1; try { if (Grid[currX, currY] != 99) { if (toAdd < 0 && touched[currX, currY]) // don't reduce danger areas of other spirals { break; } if (toAdd > 0 && Grid[currX, currY] < 0) //safe? areas from an earlier spiral are no longer safe { Grid[currX, currY] = 0; } Grid[currX, currY] += toAdd; } touched[currX, currY] = true; } catch (IndexOutOfRangeException) { //swallow out of bounds } if (i == numMoves - 1) { upNumMoves = true; } break; default: break; } } if (upNumMoves) { numMoves += 1; upNumMoves = false; } switch (direction) { //Up case 0: direction = 3; break; //Right case 1: direction = 0; break; // Down case 2: direction = 1; break; //Left case 3: direction = 2; break; default: break; } count += numMoves; } var Min = 0; for (int i = 0; i < Grid.GetLength(0); i++) { for (int j = 0; j < Grid.GetLength(1); j++) { if (Grid[i, j] < Min) { Min = Grid[i, j]; } } } for (int i = 0; i < touched.GetLength(0); i++) { for (int j = 0; j < touched.GetLength(1); j++) { if (!touched[i, j]) { Grid[i, j] = Min; } } } } }