public void CreateLinks(LinkedListNode <GameObject> node) { scrNode nodeScript = node.Value.GetComponent <scrNode>(); Bounds nodeBounds = new Bounds(node.Value.transform.position, new Vector3(CELL_SIZE * 2, CELL_SIZE * 2, CELL_SIZE * 2)); // Instead, could look for nodes at the adjacent positions of positions array, derp. LinkedList <GameObject> .Enumerator activeNode = nodePool.GetEnumerator(); for (int i = 0; i < inactiveNodeCount; ++i) { activeNode.MoveNext(); } while (activeNode.MoveNext() && nodeScript.CurrentLinks != scrNode.LINKS_MAX) { // Don't link to fully infected nodes. if (nodeScript.FullyInfected ^ activeNode.Current.GetComponent <scrNode>().FullyInfected) { if (nodeBounds.Contains(activeNode.Current.transform.position)) { // Determine which order to link the nodes. if (nodeScript.FullyInfected) { nodeScript.Link(activeNode.Current); } else { activeNode.Current.GetComponent <scrNode>().Link(node.Value); } } } } }
public void Init(LinkedListNode <GameObject> cube, scrNode parent, Vector3 position, DataState state) { transform.position = position; transform.rotation = Quaternion.identity; Parent = parent; Cube = cube; StatePrev = state; State = state; if (State == DataState.INFECTED) { infectionTransitionCompleted = true; renderer.material = scrNodeMaster.Instance.MatCubeInfected; } else { infectionTransitionCompleted = false; infectionTransitionTimer = 0.0f; if (State == DataState.BLOCKED) { renderer.material = scrNodeMaster.Instance.MatCubeBlocked; } else { renderer.material = scrNodeMaster.Instance.MatCubeUninfected; } } damageTimer = 0; Uploading = false; pathfinder.Pause(); }
public IEnumerator Destroy(LinkedListNode <GameObject> node) { scrNode nodeScript = node.Value.GetComponent <scrNode>(); CellStates[ToCellSpace(nodeScript.transform.position.x), ToCellSpace(nodeScript.transform.position.y)] = CellState.FREE; // Clear and reset the nodes cubes and make them available to future nodes. for (int i = 0, numLoops = 0; i < nodeScript.Cubes.Length; ++i) { LinkedListNode <GameObject> cube = nodeScript.Cubes[i]; DeactivateCube(cube); if (++numLoops == LOOPS_PER_FRAME) { numLoops = 0; yield return(new WaitForEndOfFrame()); } } DeactivateNode(node); }
public override void Init() { GetComponentInChildren <TextMesh>().text = Name; SiegeNode = null; pathfinder = GetComponent <scrPathfinder>(); pathfinder.Target = scrPlayer.Instance.gameObject; powerup.Colour = NameToColour(Name); powerup.Size = 0.5f + (Mathf.Max(Name.Length, 16)) / 10.0f; powerup.Speed = 220.0f / powerup.Size; powerup.Wiggle = Name[0] < 'M' ? Name[0] * 0.5f : 0; powerup.Erratic = (Mathf.Abs(Name[Name.Length - 1] - Name[0]) % 10) / 7.0f; powerup.Homing = Name[0].ToString().ToUpper()[0] < 'H'; powerup.Penetrative = Name[Name.Length - 1] <= '9'; Transform ship = transform.Find("Ship"); ship.Find("Core_Core").renderer.material.color = powerup.Colour; ship.Find("Core_Glow").renderer.material.SetColor("_TintColor", new Color(powerup.Colour.r * 0.5f, powerup.Colour.g * 0.5f, powerup.Colour.b * 0.5f, 0.0625f)); transform.GetComponentInChildren <TrailRenderer>().material.SetColor("_TintColor", powerup.Colour); ExplosionColour = powerup.Colour; }
// Update is called once per frame protected override void Update() { if (damageTimer >= DamageToDestroy) { scrPlayer.Instance.Powerups.Enqueue(powerup); scrGUI.Instance.EnqueuePowerup(Name, powerup.Colour); } pathfinder.Resume(); // If sieging, shoot at the node. if (SiegeNode != null && SiegeNode.Cubes != null) { if (!SiegeNode.gameObject.activeSelf || SiegeNode.Infected) { SiegeNode = null; pathfinder.Target = scrPlayer.Instance.gameObject; base.Update(); return; } if (targetCubeIndex >= SiegeNode.Cubes.Length) { targetCubeIndex = 0; } // Change cube if target cube is destroyed. if (SiegeNode.Cubes[targetCubeIndex] == null) { ++targetCubeIndex; } else { Vector2 direction = SiegeNode.Cubes[targetCubeIndex].Value.transform.position - transform.position; transform.rotation = Quaternion.RotateTowards(transform.rotation, Quaternion.Euler(0, 0, Mathf.Rad2Deg * Mathf.Atan2(direction.y, direction.x)), 180 * Time.deltaTime); // Check the distance. if (direction.magnitude < scrNodeMaster.CELL_SIZE) { fireTimer += Time.deltaTime * fireRate; if (fireTimer >= 1) { fireTimer = 0; StartCoroutine(Shoot(Random.Range(3, 8))); } } } } // If not sieging, check for a node to siege. else { // Aim towards the player. Vector2 direction = scrPlayer.Instance.transform.position - transform.position; transform.rotation = Quaternion.RotateTowards(transform.rotation, Quaternion.Euler(0, 0, Mathf.Rad2Deg * Mathf.Atan2(direction.y, direction.x)), 180 * Time.deltaTime); if (direction.magnitude < scrNodeMaster.CELL_SIZE) { fireTimer += Time.deltaTime * fireRate; if (fireTimer >= 1) { fireTimer = 0; StartCoroutine(Shoot(Random.Range(3, 8))); } } // Get nodes that are close by. Collider2D[] nearNodes = Physics2D.OverlapCircleAll(transform.position, scrNodeMaster.CELL_SIZE, 1 << LayerMask.NameToLayer("Node")); // Get a near node that is clean. scrNode clean = null; foreach (Collider2D c in nearNodes) { scrNode n = c.GetComponent <scrNode>(); if (!n.Infected && !n.Blocked) { clean = n; break; } } // If the clean node was set, start sieging. if (clean != null) { SiegeNode = clean; pathfinder.Target = SiegeNode.gameObject; } } base.Update(); }
public IEnumerator Create(Message message, bool infected) { creating = true; creatingMessage = message; yield return(StartCoroutine(Parse())); // Check if vandal tags detected. if (creating == false) { SpawnBoss(message); yield break; } if (scrMaster.Instance.Transitioning) { if (infected) { infectedBufferQueue.Enqueue(message); } else { scrGUI.Instance.AddToFeed(message.page_title, new Color(0.1f, 0.1f, 0.1f)); } creating = false; yield break; } if (freePositionsCount == 0) { // Debug.Log("There are no free positions left to create a node for \"" + message.page_title + "\"."); creating = false; if (!infected) { yield break; } } // Don't create a node if there are no nodes available. if (inactiveNodeCount == 0) { // Debug.Log("There are no inactive nodes left to create a node for \"" + message.page_title + "\"."); creating = false; if (!infected) { yield break; } } // Don't create a node if there are no cubes available. if (inactiveCubeCount == 0) { // Debug.Log("There are no inactive cubes left to create a node for \"" + message.page_title + "\"."); creating = false; if (!infected) { yield break; } } // Set the size of the core based on the change_size of the message. int coreSize = Mathf.Clamp(Mathf.CeilToInt(Mathf.Log10(Mathf.Abs(message.change_size) + 1)), scrNode.CORE_SIZE_MIN, scrNode.CORE_SIZE_MAX); // Get the number of cubes there would be around this core. int numCubes = scrNode.CubePositions[coreSize - 1].Length; // Don't create a node if there aren't enough cubes available. if (inactiveCubeCount < numCubes) { Debug.Log("There are not enough inactive cubes (" + inactiveCubeCount + "/" + numCubes + ") in the pool to create a node for \"" + message.page_title + "\"."); creating = false; if (!infected) { yield break; } } // If not creating but got this far, node is infected and must replace an existing one, if (creating == false) { creating = true; // Loop through the active nodes until one is found that is completely out of the player's view. LinkedListNode <GameObject> n = nodePool.Last; for (int i = 0; i < TOTAL_NODES - inactiveNodeCount; ++i) { scrNode nScript = n.Value.GetComponent <scrNode>(); // Don't replace nodes in view, fully infected nodes, the node being uploaded, or nodes that arent being infected. if (!(nScript.VisibleToPlayer || nScript.FullyInfected || !nScript.Infected || NodeBeingUploaded != null && n.Value == NodeBeingUploaded.gameObject)) { // Convert the node. nScript.ConvertToInfected(message); break; } // Move back one node. n = n.Previous; yield return(new WaitForEndOfFrame()); } scrGUI.Instance.AddToFeed(message.page_title, ColCoreInfected); yield return(new WaitForSeconds(3.0f)); // 3 Second delay between node creation. creating = false; yield break; } // All checks have passed - a node can be made. Get the first inactive node in the node pool. LinkedListNode <GameObject> node = nodePool.First; // Activate, position and initialise the node. ActivateNode(node); node.Value.transform.position = PopRandomFreePosition(); scrNode nodeScript = node.Value.GetComponent <scrNode>(); nodeScript.Init(node, message, coreSize, infected, creatingWords); // Set the cell's state to either infected or, if contribution is positive, clean else blocked. CellStates[ToCellSpace(nodeScript.transform.position.x), ToCellSpace(nodeScript.transform.position.y)] = infected ? CellState.INFECTED : nodeScript.Data.change_size > 0 ? CellState.CLEAN : CellState.BLOCKED; // Assign cubes to the node. LinkedListNode <GameObject> cube = cubePool.First; for (int i = 0, numLoops = 0; i < numCubes; ++i) { // Get the next cube before the cube is activated. LinkedListNode <GameObject> next = cube.Next; // Activate the cube and add it to the node. ActivateCube(cube); nodeScript.AddCube(cube); // Move to the next cube in the pool. cube = next; if (++numLoops == LOOPS_PER_FRAME) { numLoops = 0; yield return(new WaitForEndOfFrame()); } } // Query surrounding nodes for links. CreateLinks(node); // Release the node! Go! Go free!! nodeScript.MakeReady(); scrGUI.Instance.AddToFeed(message.page_title, infected ? ColCoreInfected : (message.change_size > 0 ? Color.cyan : Color.grey)); creating = false; }
public void Upload() { Uploading = true; Parent = null; pathfinder.Resume(); }