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;
}
}