Esempio n. 1
0
        public void LateUpdate()
        {
            // Set current TrackTile to measure current falling death offset
            // and camera offset for menu screen
            TrackTile currentTrackTileResult = this.activeTrackTiles.Find(tile => tile.gameObject.transform.position.z < 0 && tile.gameObject.transform.position.z + tile.trackTileLength > 0);

            if (currentTrackTileResult)
            {
                this.currentTrackTile = currentTrackTileResult;
            }

            // Despawn tiles
            List <TrackTile> despawnTiles = this.activeTrackTiles.FindAll(tile => tile.gameObject.transform.position.z < -this.backwardTrackOffset);

            foreach (TrackTile tile in despawnTiles)
            {
                tile.Despawn();
            }

            // Remove the from trackRecorder too
            this.activeTrackTiles.RemoveAll(tile => tile.gameObject.transform.position.z < -this.backwardTrackOffset);

            // The trackResetActive variable needs to be set back to false here
            // because the Physics calculations with colliders triggering are done directly after
            // FixedUpdate and that led to weird effects on PowerUps being collected when the
            // player was already at a different location
            // This assures that physics are already handled when we reset trackResetActive
            TrackGenerator.trackResetActive = false;
        }
Esempio n. 2
0
        /// <summary>
        /// Builds the track.
        /// </summary>
        /// <returns>The track.</returns>
        private IEnumerator BuildTrack()
        {
            while (true)
            {
                // Set the current offset, add player position if available
                float currentOffset = this.forwardTrackOffset;
                if (this.player)
                {
                    currentOffset += this.player.transform.position.z;
                }

                TrackTile lastTile = this.activeTrackTiles[this.activeTrackTiles.Count - 1];
                if (lastTile.gameObject.transform.position.z < currentOffset)
                {
                    // Filter list of all tiles, determine possible next tiles by connectors
                    List <GameObject> tilesList = this.trackTileItems.FindAll(p => p.GetComponent <TrackTile>().inConnector == lastTile.outConnector && p.GetComponent <TrackTile>().stressLevel <= GameController.CurrentStressLevel);

                    // Prepare a list with all possible tiles entered as often as their likelyhood value
                    List <GameObject> tilesLikelyhood = new List <GameObject>();

                    foreach (GameObject trackTile in tilesList)
                    {
                        for (int x = 1; x <= trackTile.GetComponent <TrackTile>().likelyhood; x++)
                        {
                            tilesLikelyhood.Add(trackTile);
                        }
                    }

                    GameObject tileToInstantiate;
                    tileToInstantiate = tilesLikelyhood[Random.Range(0, tilesLikelyhood.Count - 1)];

                    // Instantiate TrackTile
                    Vector3 lastPosition = lastTile.gameObject.transform.position;
                    this.currentHorizontalOffset = this.currentHorizontalOffset + lastTile.horizontalOffset;
                    this.currentVerticalOffset   = this.currentVerticalOffset + lastTile.verticalOffset;

                    Vector3 nextPosition = new Vector3(this.currentHorizontalOffset, this.currentVerticalOffset, lastPosition.z + lastTile.trackTileLength);
                    this.addTrackTile(tileToInstantiate.transform, nextPosition);
                }
                else
                {
                    if (!this.trackReady)
                    {
                        this.trackReady = true;
                        EventManager.TrackReady();
                    }
                }

                yield return(new WaitForEndOfFrame());
            }
        }
Esempio n. 3
0
        /// Add a track tile
        /// <summary>
        /// Adds a track tile.
        /// </summary>
        /// <param name="tileToInstantiate">Tile to instantiate.</param>
        /// <param name="position">Position.</param>/
        private TrackTile addTrackTile(Transform tileToInstantiate, Vector3 position = default(Vector3))
        {
            Transform trackTileTransform = PoolManager.Pools[this.poolName].Spawn(tileToInstantiate, position, Quaternion.identity);

            //Debug.Log ("Track Tile " + trackTileTransform.gameObject.ToString () + " " + trackTileTransform.position.ToString ());

            if (trackTileTransform)
            {
                // Cache trackTile GetComponent() call
                TrackTile trackTile = trackTileTransform.GetComponent <TrackTile>();
                this.activeTrackTiles.Add(trackTile);

                this.currentTrackPosition += (ulong)trackTile.trackTileLength;

                return(trackTile);
            }

            return(new TrackTile());
        }
Esempio n. 4
0
        public void Explode()
        {
            // Check if the enemy is already exploded
            // Prevent multiple explosions triggering
            if (this.exploded == false)
            {
                TrackTile parentTrackTile = this.cachedTransform.GetComponentInParent <TrackTile>();

                // Only replace the prefab if an explode prefab is provided, otherwise stay, e.g. boxes, energy barriers
                if (this.explodePrefab)
                {
                    Transform explodedEnemy = this.pool.Spawn(explodePrefab.transform, this.cachedTransform.position, Quaternion.identity, parentTrackTile.transform);

                    // Catch all debris elements with and Overlapsphere and maybe even other debris not part of the enemy object
                    Collider[] colliders = Physics.OverlapSphere(explodedEnemy.transform.position, 20.0f);
                    foreach (Collider c in colliders)
                    {
                        // If the debris gameobject has no rigidbody component, we can't apply an explosion force to it
                        if (c.GetComponent <Rigidbody>() == null)
                        {
                            continue;
                        }

                        // Set the explosion position to be slightly in front of the enemy to simulate projectile impact force, pushing
                        // the debris forward on the z axis
                        Vector3 explosionPosition = this.cachedTransform.position - new Vector3(0, 0, 10.0f);
                        c.GetComponent <Rigidbody>().AddExplosionForce(Random.Range(240, 360), explosionPosition, 100.0f, 1.0f, ForceMode.Impulse);
                    }

                    this.exploded = true;

                    // Move enemy object down below the track, so it is out of sight
                    // but leave despawn logic to the parent tracktile to not mess with
                    // track despawn workflow
                    this.transform.position += Vector3.down * 2000;

                    // Spawn points prefab
                    int playerAddPoints = GameController.playerInvulnerable ? this.points * 2 : this.points;
                    EventManager.PlayerAddPoints(playerAddPoints, explodedEnemy.position + new Vector3(0, 10, 0), this.cachedTransform.rotation, explodedEnemy);
                }
            }
        }
Esempio n. 5
0
        public void CreateTrack()
        {
            // Stop track building Coroutine if running
            this.StopAllCoroutines();

            this.currentHorizontalOffset = 0;
            this.currentVerticalOffset   = 0;
            this.currentTrackPosition    = 0;

            foreach (TrackTile trackTile in this.activeTrackTiles)
            {
                trackTile.Despawn();
            }
            this.activeTrackTiles.Clear();

            // Instantiate random first prefab from startTileItems
            Transform tileToInstantiate;

            tileToInstantiate     = startTileItems[Random.Range(0, this.startTileItems.Count)].transform;
            this.currentTrackTile = this.addTrackTile(tileToInstantiate);

            this.StartCoroutine(BuildTrack());
            EventManager.TrackCreated(this);
        }