protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.Black); frameCounter.Tick(gameTime); _spriteBatch.Begin(); _playingField.Draw(_spriteBatch); Window.Title = $"SpaceGame by Zintom - FPS: {frameCounter.TicksPerSecond}"; // Draw points _spriteBatch.DrawString(_textureProvider.GameFont, _playingField.Points.ToString().PadLeft(2, '0'), new Vector2(13, 10), Color.White); // Draw lives for (int i = 0; i < _playingField.Lives; i++) { _spriteBatch.Draw(_textureProvider.Ship, new Rectangle(13 + (i * 20), 50, 20, 24), Color.White); } if (!_playingField.InGame) { string pushEnterText = "Push Enter"; var textSize = _textureProvider.GameFont.MeasureString(pushEnterText); _spriteBatch.DrawString( _textureProvider.GameFont, pushEnterText, new Vector2((int)(GraphicsDevice.Viewport.Width / 2 - textSize.X / 2), (int)(GraphicsDevice.Viewport.Height / 4 - textSize.Y / 2)), Color.White); } //_spriteBatch.Draw(Blank, new Rectangle(0, 0, 10, 10), Color.White); _spriteBatch.End(); _spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, null, null, null, null, null); //_spriteBatch.Draw(new Texture2D(GraphicsDevice, 45, 75), chumpPos, Color.White); //_spriteBatch.Draw(chump, chumpPos, Color.White); //_spriteBatch.DrawCircle(GraphicsDevice, chumpPos, 100);d //_spriteBatch.DrawLineFx(GraphicsDevice, new Vector2(150, 150), Mouse.GetState().Position.ToVector2(), Color.White); //_spriteBatch.DrawLine(new Vector2(150, 150), Mouse.GetState().Position.ToVector2(), 1, Color.White); //_spriteBatch.DrawCircle(new Vector2(150, 150) - new Vector2(10), 20, Color.White); //_spriteBatch.DrawCircle(Mouse.GetState().Position.ToVector2() - new Vector2(10), 20, 0.5f, Color.Red); _spriteBatch.End(); base.Draw(gameTime); }
public bool Tick() { _stateMachine.Start(); _tick.Tick(); _gameDraw.ClearSprites(); _scoreAnimation.Tick(); _invincibleAnimation.Tick(); Inputs.Invincible.On(() => _invincible = !_invincible); Inputs.LevelSkip.On(() => _stateMachine.ChangeState(GameState.Complete)); _stateMachine .OnEntry(GameState.Intro, () => _tick.NextEventAfter(120), StartLevel) .During(GameState.Intro, () => _gameDraw.DisplayReadyText(), () => _tick.AtEvent(() => _stateMachine.ChangeState(GameState.StartOfLife)) ); _stateMachine.OnEntry(GameState.StartOfLife, () => _lives--); _stateMachine.OnEntry(GameState.NewLevel, StartLevel); _stateMachine.During(new [] { GameState.StartOfLife, GameState.NewLevel }, () => _stateMachine.ChangeState(GameState.GetReady)); _stateMachine.OnEntry(GameState.GetReady, () => _tick.NextEventAfter(120), ResetGhostsAndPacMan); _stateMachine.During(GameState.GetReady, () => _gameDraw.ClearReadyText(), () => _tick.AtEvent(() => _stateMachine.ChangeState(GameState.Playing)), () => _scatterChase.Reset(_level), () => _speeds.SetLevel(_level)); _stateMachine.During(new[] { GameState.Playing, GameState.Frightened }, MainLoop); _stateMachine.OnEntry(GameState.Complete, () => _tick.NextEventAfter(120)); _stateMachine.During(GameState.Complete, () => _tick.AtEvent(() => _stateMachine.ChangeState(GameState.Flash))); _stateMachine .OnEntry(GameState.Flash, () => _tick.NextEventAfter(12), () => { _flashCounter = 0; }) .During(GameState.Flash, () => _tick.AtEvent(FlashMap)); _stateMachine .OnEntry(GameState.Caught, () => _tick.NextEventAfter(60)) .During(GameState.Caught, () => _tick.AtEvent(() => { _stateMachine.ChangeState(GameState.Dying); _pacMan.Die(); }), () => { _powerPillAnimation.Tick(); DoToGhosts(g => g.Animate()); } ); _stateMachine .OnEntry(GameState.Dying, () => _tick.NextEventAfter(4 * 60)) .During(GameState.Dying, () => _pacMan.Animation.Tick(), () => _tick.AtEvent(() => { if (_lives > 0) { _stateMachine.ChangeState(GameState.StartOfLife); ResetGhostsAndPacMan(); _ghostHouse.LifeLost(); } else { _stateMachine.ChangeState(GameState.GameOver); } })); _stateMachine .OnEntry(GameState.GameOver, () => _tick.NextEventAfter(4 * 60)) .During(GameState.GameOver, () => _tick.AtEvent(() => { _stateMachine.End(); })); Draw(); return(!_stateMachine.HasEnded); }
private void NextFrame() { TickCounter.Tick(); _frameContext.NextFrame(); }