This looks fun.
Here's the Update loop for my last game.
protected override void Update(GameTime gameTime)
{
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || (keyState.IsKeyDown(Keys.Escape) && keyPrev.IsKeyDown(Keys.Escape)))
this.Exit();
keyPrev = keyState;
keyState = Keyboard.GetState();
padPrev = padState;
padState = GamePad.GetState(padPlayer);
if (setupTime > 0f)
{
setupTime -= (float)gameTime.ElapsedGameTime.TotalSeconds;
if (keyState.IsKeyDown(Keys.Space) || keyState.IsKeyDown(Keys.Z) || keyState.IsKeyDown(Keys.X) || keyState.IsKeyDown(Keys.C))
setupTime = 0f;
}
else
{
if (Player.alive)
{
Player.Update(gameTime, keyState, padState); //run this before (does collchecks)
}
else
{
if (keyState.IsKeyDown(Keys.Space) && keyPrev.IsKeyUp(Keys.Space))
{
EnemyManager.Initiate();
Player.Initiate(Vector2.Zero);
EffectManager.Initiate();
}
}
EnemyManager.Update(gameTime); //run this after (clears enemies)
EffectManager.Update(gameTime);
}
base.Update(gameTime);
}
And the Draw loop. Slightly sloppy. Bleh.
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.Black);
spriteBatch.Begin();
if (setupTime > 0f)
{
spriteBatch.Draw(GJsetup, new Rectangle(0, 0, 640, 640), Color.White * Math.Min(setupTime*2f,1f));
}
else
{
EffectManager.Draw(spriteBatch);
EnemyManager.Draw(spriteBatch);
if (Player.alive)
{
Player.Draw(spriteBatch);
Player.DrawHud(spriteBatch, gameTime);
if (EnemyManager.win)
{
spriteBatch.DrawString(fontBig, "YOU WIN", new Vector2(320, 300), Color.Cyan, 0f, new Vector2(65, 0), 1f, SpriteEffects.None, 0f);
spriteBatch.DrawString(font, "YOU MAY NOW RESUME YOUR LIFE o.O", new Vector2(320, 340), Color.Cyan, 0f, new Vector2(55, 0), 1f, SpriteEffects.None, 0f);
}
else
{
if (EnemyManager.waveDetected)
{
float det = (2f - EnemyManager.waveTime) / 2f;
float rotate = (float)Math.Sign(det) * 50f * (float)Math.Pow(det, 4f);
for (int i = 0; i < 7; i++)
{
spriteBatch.DrawString(fontBig, "WAVE " + EnemyManager.wave.ToString(), new Vector2(320, 200), Color.DarkCyan, rotate * (1f + ((float)(3 - i) / 30f)), new Vector2(40, 20), 1f, SpriteEffects.None, 0f);
}
spriteBatch.DrawString(fontBig, "WAVE " + EnemyManager.wave.ToString(), new Vector2(320, 200), Color.Cyan, rotate, new Vector2(40, 20), 1f, SpriteEffects.None, 0f);
}
}
}
else
{
spriteBatch.DrawString(fontBig, "GAME OVER", new Vector2(320, 300), Color.Cyan, 0f, new Vector2(65, 0), 1f, SpriteEffects.None, 0f);
spriteBatch.DrawString(font, "AT WAVE " + EnemyManager.wave.ToString(), new Vector2(320, 330), Color.Cyan, 0f, new Vector2(30, 0), 1f, SpriteEffects.None, 0f);
spriteBatch.DrawString(font, "PRESS SPACE TO START", new Vector2(320, 340), Color.Cyan, 0f, new Vector2(40, 0), 1f, SpriteEffects.None, 0f);
}
}
spriteBatch.End();
base.Draw(gameTime);
}