/// <summary> /// This is called when the game should draw itself. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.Black); spriteBatch.Begin(); spriteBatch.Draw(background, Vector2.Zero, Color.White); player.Draw(spriteBatch); spriteBatch.End(); base.Draw(gameTime); }
public virtual async void GameLoop() { long time = DateTime.Now.Ticks; int dt; Counter++; if (gameLoopRunning) { foreach (SpaceThing thing in Enemies) { thing.Simulate(this); } foreach (Blastable debris in Debris) { debris.Simulate(this); } foreach (Blastable bullet in Bullets) { bullet.Simulate(this); } foreach (SpaceAlien a in Aliens) { a.Simulate(this); a.Shoot(this, Player.GetLocation()); } if ((((Counter * 50000000 + 345) * (Counter + 55)) % 125 == 0) && Aliens.Count < 2) { Aliens.Add(factory.GiveMeAnAlien(Score)); } CollideAsteroidsAliensBullets(); if (PlayerTimer < 0) { CollidePlayerAndAsteroidsAndBullets(); } await Task.Delay(1); //if (Counter == 3) //MessageBox.Show("hullo"); PlayerTimer--; view.Children.Clear(); // Player Draw if (PlayerTimer < 0) { Player.Draw(view); } else if (((Counter / 5) % 2 == 0) /*&&(Counter < 50)*/) { Player.Draw(view); } foreach (Blastable thing in Enemies) { thing.Draw(view); } foreach (Blastable debris in Debris) { debris.Draw(view); } foreach (Blastable bullet in Bullets) { bullet.Draw(view); } foreach (SpaceAlien a in Aliens) { a.Draw(view); } // LIVES Point p; int i; for (i = 0; i < Lives; i++) { p = new Point(60 + i * 30, 60); view.Children.Add(SpaceThing.MakeLine((new Point(0, -25)), (new Point(10, 9)), p, new Matrix())); view.Children.Add(SpaceThing.MakeLine((new Point(0, -25)), (new Point(-10, 9)), p, new Matrix())); view.Children.Add(SpaceThing.MakeLine((new Point(-8, 2)), (new Point(8, 2)), p, new Matrix())); } // END LIVES Player.Simulate(this); //Player.Draw(view); HandleBlasts(); } //if (Counter > 50) //MessageBox.Show(time + ""); await Task.Delay(1); time = DateTime.Now.Ticks - time; dt = 60 - (int)(time / 10000); if (dt > 0) { await Task.Delay(60 - (int)(time / 10000)); } if (Enemies.Count < 1) { StartLevel((int)Math.Sqrt(Score / 600) + 6); } if (!stopped) { GameLoop(); } }