void Scene5() { // TODO fix this bug that gets the ball stuck in the corner of the second segment PlatformSegment seg = new PlatformSegment (25, Vector3.zero, Vector2.zero); seg.AddSegment (3, new Vector3 (2,0,0), new Vector2(0, 0)); seg.Draw (); }
public void addSegmentOrigin(PlatformSegment seg) { if (seg.originSegment != seg) { throw new UnityException ("only origin segments can be added to this class"); } segmentOrigins.Add (seg); seg.parentTransform = this.origin; }
public void OnStaminaAbility(PlatformSegment platformSegment) { if (BallHaveAbility) { platformSegment.GetComponentInParent <Platform>().Break(GameTheme.Instante.CurrentTheme._ball); _countDestoyPlatform++; } StaminaZero(); }
private void Jump(PlatformSegment platformSegment) { _canJump = false; if (_ball.BallHaveAbility) { TouchFloorAbility?.Invoke(platformSegment); } TouchFloor?.Invoke(platformSegment); _rigidbody.velocity = Vector3.zero; _rigidbody.AddForce(Vector3.up * _jumpForce, ForceMode.Impulse); Invoke("CanJump", _timeCanJump); Managers.SoundController.Instance.TouchFloor(); }
/// <summary> /// Updates gameplay logic any time a new frame is displayed to the screen /// </summary> void Update() { if (activeSegments.Count > 0) { foreach (PlatformSegment segment in activeSegments) { // If the segment has just been deactivated, don't bother processing it if (!segment.isActiveAndEnabled) { break; } // Move the segment towards the left side of screen to give the illusion of the player running over it segment.transform.position = Vector3.Lerp(segment.transform.position, segment.transform.position - (Vector3.right * movementSpeed), Time.smoothDeltaTime); } // If the end of a segment has gone off the left side of screen if (activeSegments[0].segmentEnd.position.x < -screenRightBound.x) { // Deactivate the segment and transfer it into the pile of available segments PlatformSegment removedSegment = activeSegments[0]; removedSegment.gameObject.SetActive(false); TransferSegmentToAvailable(removedSegment); } // If the end of the segment is just about to travel past the right side of the screen and a new segment can be spawned if ((activeSegments[activeSegments.Count - 1].segmentStart.position.x < screenRightBound.x)) { if (availableSegments.Count > 0) { // Pick an available segment at random and place it immediately behind the segment above int newSegmentIndex = Random.Range(0, availableSegments.Count); PlatformSegment newSegment = availableSegments[newSegmentIndex]; newSegment.transform.position = new Vector3(activeSegments[activeSegments.Count - 1].segmentEnd.position.x + gapBetweenPlatforms, newSegment.transform.position.y, 0.0f); // Enable a random assortment of coins and obstacles on the segment newSegment.GenerateCoins(); newSegment.GenerateObstacles(); // Activate the segment newSegment.gameObject.SetActive(true); // Transfer the segment into the list of active segments TransferSegmentToActive(newSegment); } } } }
void Scene1() { PlatformSegment seg = new PlatformSegment (7f, Vector3.zero, Vector2.zero); seg.parentTransform = this.gameObject; int sides = 9; for (int i=1; i < sides-1; i++) { if (i == 1) seg.AddSegment (3.5f, Vector3.zero, new Vector2 (360/sides, 0)); else seg.AddSegment (3.5f, new Vector3 (1.5f, 0, 0), new Vector2 (360/sides, 0)); } seg.AddSegment (3f, new Vector3 (2.5f, 0, 0), new Vector2 (360/sides, 0)); // seg.CloseCircuit(); seg.Draw (); }
void Scene4() { PlatformSegment seg = new PlatformSegment (3, Vector3.zero, Vector2.zero); seg.AddSegment (3, Vector3.zero, new Vector2(0, 0)); seg.AddSegment (3, Vector3.zero, new Vector2(0, 15)); seg.AddSegment (3, Vector3.zero, new Vector2(0, 0)); seg.AddSegment (3, Vector3.zero, new Vector2(0, 15)); seg.AddSegment (3, Vector3.zero, new Vector2(0, 0)); seg.AddSegment (3, Vector3.zero, new Vector2(0, 15)); seg.AddSegment (3, Vector3.zero, new Vector2(0, 0)); seg.AddSegment (3, Vector3.zero, new Vector2(0, 15)); seg.AddSegment (3, Vector3.zero, new Vector2(0, 0)); seg.AddSegment (3, Vector3.zero, new Vector2(0, 15)); seg.AddSegment (3, Vector3.zero, new Vector2(0, 0)); seg.AddSegment (3, Vector3.zero, new Vector2(0, 15)); seg.Draw (); }
void Scene6() { PlatformSegment seg = new PlatformSegment (16f, new Vector3(-4,20,0), new Vector2(0, -90)); seg.AddSegment (1f, Vector3.zero, new Vector2(0, -70)); seg.AddSegment (1f, Vector3.zero, new Vector2(0, -60)); seg.AddSegment (1f, Vector3.zero, new Vector2(0, -40)); seg.AddSegment (1f, Vector3.zero, new Vector2(0, -20)); seg.AddSegment (3f, Vector3.zero, new Vector2(0, 0)); seg.AddSegment (1f, Vector3.zero, new Vector2(0, 20)); seg.AddSegment (1f, Vector3.zero, new Vector2(0, 40)); seg.AddSegment (1f, Vector3.zero, new Vector2(0, 60)); seg.AddSegment (1f, Vector3.zero, new Vector2(0, 70)); seg.AddSegment (16f, Vector3.zero, new Vector2(0, 80)); seg.AddSegment (1f, Vector3.zero, new Vector2(0, 70)); seg.AddSegment (1f, Vector3.zero, new Vector2(0, 60)); seg.AddSegment (1f, Vector3.zero, new Vector2(0, 40)); seg.AddSegment (1f, Vector3.zero, new Vector2(0, 20)); seg.AddSegment (20f, Vector3.zero, new Vector2(0, 0)); seg.Draw (); }
// void Scene2 () { // PlatformSegment arc = DrawArc (new Vector3(0,0,0)); // arc.parentTransform = this.gameObject; // arc.Draw (); // } void Scene3() { PlatformSegment seg = new PlatformSegment (3, Vector3.zero, Vector2.zero); seg.AddSegment (3, new Vector3 (2, 1, 0), new Vector2(15, 0)); seg.AddSegment (3, new Vector3 (2, 1, 0), new Vector2(15, 15)); seg.AddSegment (3, new Vector3 (2, 1, 0), new Vector2(15, 0)); seg.AddSegment (3, new Vector3 (2, 1, 0), new Vector2(15, 15)); seg.AddSegment (3, new Vector3 (2, 1, 0), new Vector2(15, 0)); seg.AddSegment (3, new Vector3 (2, 1, 0), new Vector2(15, 15)); seg.AddSegment (3, new Vector3 (2, 1, 0), new Vector2(15, 0)); seg.AddSegment (3, new Vector3 (2, 1, 0), new Vector2(15, 15)); seg.AddSegment (3, new Vector3 (2, 1, 0), new Vector2(15, 0)); seg.AddSegment (3, new Vector3 (2, 1, 0), new Vector2(15, 15)); seg.AddSegment (3, new Vector3 (2, 1, 0), new Vector2(15, 0)); seg.AddSegment (3, new Vector3 (2, 1, 0), new Vector2(15, 15)); seg.AddSegment (3, new Vector3 (2, 1, 0), new Vector2(15, 0)); seg.AddSegment (3, new Vector3 (2, 1, 0), new Vector2(15, 15)); seg.AddSegment (3, new Vector3 (2, 1, 0), new Vector2(15, 0)); seg.AddSegment (3, new Vector3 (2, 1, 0), new Vector2(15, 15)); seg.Draw (); }
/// <summary> /// Processes gameplay logic prior to the first frame being displayed /// </summary> void Start() { // Store the location startingSegmentPos = new Vector3(-screenRightBound.x, platformSpawnHeight, 0.0f); availableSegmentPos = new Vector3(screenRightBound.x + 10.0f, platformSpawnHeight, 0.0f); // If there are platform segment 'blueprints' to use if (platformSegments.Length > 0) { // Create an instance of each segment and store it foreach (PlatformSegment Segment in platformSegments) { PlatformSegment SpawnedSegment = Instantiate(Segment) as PlatformSegment; SpawnedSegment.transform.position = availableSegmentPos; availableSegments.Add(SpawnedSegment); } // Always make sure that the simplest segment is the one first encountered by the player startingSegment = availableSegments[0]; startingSegment.transform.position = startingSegmentPos; TransferSegmentToActive(startingSegment); } }
void DetectFlyingSegmentChange() { if (! inAir) { flyingCollision.GetComponent<Renderer>().enabled = false; return; } flyingCollision.GetComponent<Renderer>().enabled = true; PlatformSegment newSegment = null; float r = flyingCollisionRadius; flyingCollision.transform.localScale = new Vector3 (r*2, r*2, r*2); float smallestDistance = float.PositiveInfinity; float offset = 0; //the size of the collision sphere is dependent on the speed because if the character is too fast it might //not overlap with other segments between each FixedUpdate call foreach (Collider col in Physics.OverlapSphere(bodyPosition, r)) { if (col.gameObject.tag == "platform-segment") { PlatformSegment colSeg = col.gameObject.GetComponent<GameObjectMetadata> ().segment; if (colSeg.visible) { float[] a = colSeg.GetClosestOffset (bodyPosition); float distance = a[0]; float offset2 = a[1]; if (distance < smallestDistance) { smallestDistance = distance; offset = offset2; newSegment = colSeg; } } } } if (newSegment != null) { this.segment = newSegment; this.segmentOffset = offset; inAir = false; } }
PlatformSegment AddSegment(PlatformSegment segment) { if (IsClosed ()) throw new UnityException ("can not add segment to a closed circuit"); if (! IsLastSegment()) return GetLastSegment ().AddSegment (segment); if (segment.position != Vector3.zero) { //creating an invisible segment fills that connects the current segment and the new one Vector3 endPosition = this.segmentEnd.transform.position + segment.position; segment.position = Vector3.zero; PlatformSegment invisibleSeg = this.AddSegmentGlobalPosition (endPosition); invisibleSeg.visible = false; segment.parentTransform = invisibleSeg.segmentEnd; segment.previousSegment = invisibleSeg; invisibleSeg.nextSegment = segment; } else { segment.parentTransform = this.segmentEnd; segment.previousSegment = this; this.nextSegment = segment; } segment.originSegment = this.originSegment; return segment; }
// creates a segment that starts at local position [0,0,0] and ends at globalEndPosition public PlatformSegment AddSegmentGlobalPosition(Vector3 globalEndPosition) { if (IsClosed()) throw new UnityException ("can not add segment to a closed circuit"); if (! IsLastSegment()) return GetLastSegment ().AddSegmentGlobalPosition (globalEndPosition); Vector3 segmentEndGlobalPosition = this.segmentEnd.transform.position; float size = Vector3.Distance (globalEndPosition, segmentEndGlobalPosition); Vector3 rotation = globalEndPosition - segmentEndGlobalPosition; float x = Mathf.Atan (rotation.z / rotation.x) * Mathf.Rad2Deg; float y = Mathf.Asin (rotation.y / size) * Mathf.Rad2Deg; Vector2 segRotation = new Vector2 (x, y); // Debug.Log (this.gameObject.name); // Debug.Log (size); // Debug.Log (segmentEndGlobalPosition); // Debug.Log (globalEndPosition); // Debug.Log (rotation); // Debug.Log (segRotation); // Debug.Log ("-----------------"); PlatformSegment seg = new PlatformSegment (size, new Vector3 (0, 0, 0), segRotation); this.AddSegment (seg); return seg; }
public PlatformSegment AddSegment(float size, Vector3 position, Vector2 rotation) { PlatformSegment seg = new PlatformSegment(size, position, rotation); return AddSegment (seg); }
/// <summary> /// Transfers a segment instance from active to available /// </summary> /// <param name="_segment">A reference to the platform segment to transfer</param> public void TransferSegmentToAvailable(PlatformSegment _segment) { availableSegments.Add(_segment); activeSegments.Remove(_segment); }
private void OnSplashEffectAbility(PlatformSegment platformSegment) { SplashEffect(platformSegment.transform, _particleSplash3, GameTheme.Instante.CurrentTheme._splash); }
// returns how many visible segments the floor is touching int DetectFloorSegmentChange() { PlatformSegment newSegment = null; int count = 0; float r = floorCollisionRadius; floorCollision.transform.localScale = new Vector3 (r*2, r*2, r*2); //the size of the collision sphere is dependent on the speed because if the character is too fast it might //not overlap with other segments between each FixedUpdate call foreach (Collider col in Physics.OverlapSphere(floorPosition, r)) { if (col.gameObject.tag == "platform-segment") { PlatformSegment colSeg = col.gameObject.GetComponent<GameObjectMetadata> ().segment; count ++; if (this.segment.nextSegment == colSeg) { newSegment = colSeg; segmentOffset = segmentChangeOffset * r; } else if (this.segment.previousSegment == colSeg) { newSegment = colSeg; segmentOffset = this.segment.previousSegment.size - segmentChangeOffset * r; } else if (colSeg.visible && this.segment != colSeg) { //touched a segment that is not a nextSegmnet/previousSegment to the current one // TODO is necessary to check if multiples collisions like this case happen? if so which one should we attach the floor to? float[] a = colSeg.GetClosestOffset (floorPosition); this.segmentOffset = a[1]; newSegment = colSeg; } } } if (newSegment != null) { this.segment = newSegment; if ( ! this.segment.visible) inAir = true; } return count; }
void Scene7() { PlatformSegment seg = new PlatformSegment (4f, Vector3.zero, new Vector2(60, 20)); seg.AddSegment (4f, Vector3.zero, new Vector2(60, 20)); seg.AddSegment (4f, Vector3.zero, new Vector2(60, 20)); seg.AddSegment (4f, Vector3.zero, new Vector2(60, 20)); seg.AddSegment (4f, Vector3.zero, new Vector2(60, 20)); seg.AddSegment (4f, Vector3.zero, new Vector2(60, 20)); seg.AddSegment (4f, Vector3.zero, new Vector2(60, 20)); seg.AddSegment (4f, Vector3.zero, new Vector2(60, 20)); seg.AddSegment (4f, Vector3.zero, new Vector2(60, 20)); seg.AddSegment (4f, Vector3.zero, new Vector2(60, 20)); seg.AddSegment (4f, Vector3.zero, new Vector2(60, 20)); seg.AddSegment (4f, Vector3.zero, new Vector2(60, 20)); seg.AddSegment (4f, Vector3.zero, new Vector2(60, 20)); seg.AddSegment (4f, Vector3.zero, new Vector2(60, 20)); seg.AddSegment (4f, Vector3.zero, new Vector2(60, 20)); seg.AddSegment (4f, Vector3.zero, new Vector2(60, 20)); PlatformSegment seg2 = new PlatformSegment (4f, Vector3.zero, new Vector2(60, 0)); seg2.AddSegment (4f, Vector3.zero, new Vector2(60, 0)); seg2.AddSegment (4f, Vector3.zero, new Vector2(60, 0)); seg2.AddSegment (4f, Vector3.zero, new Vector2(60, 0)); seg2.AddSegment (4f, Vector3.zero, new Vector2(60, 0)); seg2.AddSegment (4f, Vector3.zero, new Vector2(60, 0)); seg.Draw (); seg2.Draw (); }