protected override void Update(GameTime gameTime)
{
// Allows the game to exit
if (Keyboard.GetState().IsKeyDown(Keys.Escape))
this.Exit();
p.Update(gameTime);
p.CheckBoundries(GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height);
hud.Update(gameTime);
foreach (Asteroid ast in asteroid)
{
ast.Update(gameTime);
ast.CheckBoundries(graphics.PreferredBackBufferWidth, graphics.PreferredBackBufferHeight);
if (p.GetPlayerHitbox().Intersects(ast.GetAsteroidHitbox()))
{
switch (ast.GetSize())
{
case 1:
asteroidList.Add(ast);
p.SetLives((p.GetLife() - 1));
break;
case 2:
for (int i = 0; i < 2; i++)
{
double angle = r.NextDouble() * 2 * Math.PI;
newAsteroidList.Add(new Asteroid(ast.getXPos(), ast.getYPos(), 1, 3.0f, dir = new Vector2((float)Math.Cos(angle), (float)Math.Sin(angle))));
}
asteroidList.Add(ast);
p.SetLives((p.GetLife() - 1));
break;
case 3:
for (int i = 0; i < 2; i++)
{
double angle = r.NextDouble() * 2 * Math.PI;
newAsteroidList.Add(new Asteroid(ast.getXPos(), ast.getYPos(), 2, 3.0f, dir = new Vector2((float)Math.Cos(angle), (float)Math.Sin(angle))));
}
asteroidList.Add(ast);
p.SetLives((p.GetLife() - 1));
break;
default:
break;
}
}
}
if (asteroid.Count == 0)
{
LevelsIncrease();
}
foreach (Asteroid a in newAsteroidList)
{
asteroid.Add(a);
}
foreach (Asteroid a in asteroidList)
{
asteroid.Remove(a);
}
asteroidList.Clear();
newAsteroidList.Clear();
foreach (Weapon wep in p.weapList)
{
wep.Update(gameTime, wep.GetDirection());
wep.CheckBoundries(GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height);
if (wep.GetFadeTime() == 0)
{
wep.SetIsVisable(false);
killListWep.Add(wep);
}
foreach (Asteroid a in asteroid)
{
if (wep.GetHitbox().Intersects(a.GetAsteroidHitbox()))
{
switch (a.GetSize())
{
case 1:
asteroidList.Add(a);
killListWep.Add(wep);
hud.SetScore(10);
break;
case 2:
for (int i = 0; i < 2; i++)
{
double angle = r.NextDouble() * 2 * Math.PI;
newAsteroidList.Add(new Asteroid(a.getXPos(), a.getYPos(), 1, 3.0f, dir = new Vector2((float)Math.Cos(angle), (float)Math.Sin(angle))));
}
asteroidList.Add(a);
killListWep.Add(wep);
hud.SetScore(25);
break;
case 3:
for (int i = 0; i < 2; i++)
{
double angle = r.NextDouble() * 2 * Math.PI;
newAsteroidList.Add(new Asteroid(a.getXPos(), a.getYPos(), 2, 3.0f, dir = new Vector2((float)Math.Cos(angle), (float)Math.Sin(angle))));
}
asteroidList.Add(a);
killListWep.Add(wep);
hud.SetScore(50);
break;
default:
break;
}
}
}
}
foreach (Weapon weap in killListWep)
{
p.weapList.Remove(weap);
}
base.Update(gameTime);
}