public override void Update(GameTime gameTime)
{
TouchCollection touchCollection = TouchPanel.GetState();
if (touchCollection.Count != 0)
{
IsAlive = true;
}
if (isActive)
{
if (!gameOver)
{
// Add points
int airborne = 1;
if (airtime > 10) { airborne = 3; } // add extra if he's in the air
Score.Points += Constants.POINTS * airborne;
}
//Position.X++;
int difference = World.getPositionDifference();
adjustSpeed(difference);
// Check if touching the world
if (difference == 0)
{
// Touching world
airtime = 0;
}
else if (difference < 0)
{
airtime++;
// In the air
float dropSize = Math.Abs(Position.Y + Texture.Height - (TouchPanel.DisplayHeight - World.getLine((int)Position.X).Height));
int yDiff = 3;
if (dropSize > 45)
{
yDiff = (airtime / (6 * gameTime.ElapsedGameTime.Milliseconds));
}
Position.Y += yDiff;
int diff2 = World.getPositionDifference();
while (diff2 > 0)
{
Position.Y -= 1;
diff2 = World.getPositionDifference();
}
}
else // difference > 0
{
// Collision
airtime = 0;
if (difference > TouchPanel.DisplayHeight * 0.1)
{
IsAlive = false;
gameOver = true;
Position.Y = TouchPanel.DisplayHeight;
}
do
{
Position.Y--;
} while (World.getPositionDifference() > 0);
}
if ((Position.Y + Texture.Height) > TouchPanel.DisplayHeight)
{
IsAlive = false;
gameOver = true;
}
base.Update(gameTime);
}
}