SuperSquid.Entities.Behaviors.BlockBuilderBehavior.Update C# (CSharp) Method

Update() protected method

Allows this instance to execute custom logic during its Update.
This method will not be executed if the T:WaveEngine.Framework.Component, or the T:WaveEngine.Framework.Entity owning it are not Active.
protected Update ( System.TimeSpan gameTime ) : void
gameTime System.TimeSpan The game time.
return void
        protected override void Update(TimeSpan gameTime)
        {
            float virtualScreenHeight = this.vm.BottomEdge - this.vm.TopEdge;

            foreach (RocksBlock block in this.visibleBlocks.ToList())
            {
                block.Transform2D.Y += scrollVelocity * (float)gameTime.TotalMilliseconds;

                if (block.CheckStarCollision(this.squidCollider))
                {
                    this.soundManager.PlaySound(SoundManager.SOUNDS.Star);
                    if (this.OnStarCollected != null)
                    {
                        this.OnStarCollected(this, null);
                    }
                }

                bool gameOverDetected = false;

                if (block.CheckRockCollision(this.squidCollider))
                {
                    this.soundManager.PlaySound(SoundManager.SOUNDS.RockCrash);
                    gameOverDetected = true;
                }
                else if (block.CheckJellyFishCollision(this.squidCollider))
                {
                    this.soundManager.PlaySound(SoundManager.SOUNDS.JellyCrash);
                    gameOverDetected = true;
                }

                if (gameOverDetected)
                {
                    if (this.OnCollision != null)
                    {
                        this.OnCollision(this, null);
                    }

                    break;
                }

                var diff = block.Transform2D.Y - this.vm.BottomEdge;
                if (diff > 0)
                {
                    // Remove this block
                    block.Reset();
                    this.visibleBlocks.Remove(block);
                    block.Owner.Enabled = false;

                    // Add a new block instead
                    var selectedBlock = this.avaibleBlocks[WaveServices.Random.Next(this.avaibleBlocks.Count)];
                    selectedBlock.Transform2D.Y = diff - virtualScreenHeight;
                    this.avaibleBlocks.Remove(selectedBlock);
                    this.visibleBlocks.Add(selectedBlock);
                    selectedBlock.Owner.Enabled = true;

                    // Set removed block as avaible again
                    this.avaibleBlocks.Add(block);
                }
            }

            // Decrease scroll velocity
            if (this.scrollVelocity > MIN_SCROLL_VELOCITY)
            {
                this.scrollVelocity -= 0.01f * (float)gameTime.TotalSeconds * 60;
            }
        }