public static void InsertAtPlaceOf(LinkedListNode <NumberNode> nodeInGutter, NumberNode node) { newlyInsertedNode = node; dispersing = true; float distTravelled = nodeInGutter.Value.pathFollower.distanceTravelled - NumberNode.RADIUS / 2f; newlyInsertedNode.pathFollower.SetDistanceTravelled(distTravelled); newlyInsertedNode.transform.position = nodeInGutter.Value.pathFollower.pathCreator.path.GetPointAtDistance(distTravelled); //TODO: weghalen dat dit nodig is (projectile state zorgt voor de nodecontroller) node.SetState(NodeState.STANDSTILL); numberList.numberLinkedList.AddBefore(nodeInGutter, newlyInsertedNode); }
private void Shoot(Vector3 mousePos) { if (Input.GetMouseButtonDown(0) && timeStamp < Time.time) { NumberNode newNode = Instantiate(node, transform.position, Quaternion.identity, parentTransform).GetComponent <NumberNode>(); //newNode.SetValue(Random.Range(NumberList.BOUND_LOW, NumberList.BOUND_HIGH)); newNode.SetValue(2); newNode.SetState(NodeState.PROJECTILE); Vector3 heading = mousePos - transform.position; float distance = heading.magnitude; newNode.nodeController.SetDirection(heading / distance); timeStamp = Time.time + COOLDOWN; } }
private void SpawnNodeAtDistance(float distanceTravelled) { // Get the coordinates of the point at the distance travelled Vector3 pointOnPath = pathCreator.path.GetPointAtDistance(distanceTravelled); // Spawn a new node under the parent transform at those coordinates NumberNode newNode = Instantiate(numberBall, pointOnPath, Quaternion.identity, parentTransform).GetComponent <NumberNode>(); newNode.Init(); // Set the pathfollower's distance travelled acoordingly newNode.pathFollower.SetDistanceTravelled(distanceTravelled); // Set the node state to be in the gutter newNode.SetState(NodeState.GUTTER); // Disable the node's motor as the pathfollower takes care of movement in the gutter newNode.nodeMotor.enabled = false; newNode.SetColorToValue(); // Add the node to the node manager NodeManager.AddNode(newNode); }
void Update() { if (!GameStateManager.IsPaused()) { if (timeStamp < Time.time) { LayerMask nodeMask = LayerMask.GetMask("NodeLayer"); if (!Physics2D.OverlapCircle(transform.position, NumberNode.RADIUS, nodeMask)) { NumberNode newNode = Instantiate(numberBall, pathStart, Quaternion.identity, parentTransform).GetComponent <NumberNode>(); NodeManager.AddNode(newNode); newNode.SetState(NodeState.FORWARD); newNode.Init(); newNode.SetValue(Random.Range(NumberList.BOUND_LOW, NumberList.BOUND_HIGH)); timeStamp = Time.time + cooldown; } } } }
// Instantiates a new node and fires it towards the mouse position. private void Shoot(Vector3 mousePos) { // Only accept shooting when we're in Pre-insertion if (GameStateManager.GetGameState() == GameState.PREINSERTION) { // Create a new node newNode = Instantiate(nodePrefab, transform.position, Quaternion.identity, parentTransform).GetComponent <NumberNode>(); // Get the directional vector towards the mouse position Vector3 heading = mousePos - transform.position; newNode.nodeMotor.SetDirection(heading.normalized); // Set the node state newNode.SetState(NodeState.PROJECTILE); // Set it's value and it's corresponding color int ballValue = NodeManager.GetNextBallValue(); newNode.SetValue(ballValue); newNode.SetColorToValue(); particles.setNode(newNode); // Let the gamestate manager know we're shooting now GameStateManager.SwitchToShooting(); } }