public void KeyInput(KeyEventArgs e) { if (!Paused && !GameOver) { switch (e.Key) { case Key.LeftCtrl: _model.FireShot(true); break; case Key.P: if (Paused == true) { _model.GamePaused = false; OnPropertyChanged("Paused"); } else { _model.GamePaused = true; OnPropertyChanged("Paused"); } break; default: _model.MovePlayer(e); break; } } else { if (e.Key == Key.P) { if (Paused == true) { _model.GamePaused = false; OnPropertyChanged("Paused"); } else { _model.GamePaused = true; OnPropertyChanged("Paused"); } } } if (e.Key == Key.Space) { if (!GameOver) { if (!Paused) { _model.FireShot(false); } } else { StartGame(); } } }
internal void KeyDown(Key key) { switch (key) { case Key.D1: _model.CurrentShotType = ShotType.BasicShot; break; case Key.D2: _model.CurrentShotType = ShotType.LazerShot; break; case Key.Space: _model.FireShot(); break; case Key.A: _leftAction = DateTime.Now; break; case Key.D: _rightAction = DateTime.Now; break; case Key.Escape: Paused = !Paused; break; } }
internal void KeyDown(Windows.System.VirtualKey virtualKey) { if (virtualKey == Windows.System.VirtualKey.Space) { _model.FireShot(); } if (virtualKey == Windows.System.VirtualKey.Left) { _leftAction = DateTime.Now; } if (virtualKey == Windows.System.VirtualKey.Right) { _rightAction = DateTime.Now; } }
internal void KeyDown(VirtualKey virtualKey) { switch (virtualKey) { case VirtualKey.Space: _model.FireShot(); break; case VirtualKey.Left: _leftAction = DateTime.Now; break; case VirtualKey.Right: _rightAction = DateTime.Now; break; default: break; } }
internal void KeyDown(Key key) { if (key == Key.Space) { _model.FireShot(); } if (key == Key.Left) { _leftAction = DateTime.Now; } if (key == Key.Right) { _rightAction = DateTime.Now; } }
private void TimerTickEventHandler(object sender, object e) { if (_lastPaused != Paused) { _lastPaused = Paused; OnPropertyChanged("Paused"); } if (!Paused) // Move player { if (_leftAction != null && _rightAction != null) { if (_leftAction > _rightAction) { if (_fireAction != null && _fireAction > _leftAction) { _model.FireShot(); } else { _model.MovePlayer(Direction.Left); } } else { if (_fireAction != null && _fireAction > _leftAction) { _model.FireShot(); } else { _model.MovePlayer(Direction.Right); } } } else if (_leftAction != null) { _model.MovePlayer(Direction.Left); } else if (_rightAction != null) { _model.MovePlayer(Direction.Right); } else if (_fireAction != null) { _model.FireShot(); } } _model.Update(Paused); // Update score if (Score != _model.Score) { Score = _model.Score; OnPropertyChanged("Score"); } // Update lives if (_lives.Count > _model.Lives) { _lives.RemoveAt(_lives.Count - 1); if (_lives.Count == 0) { EndGame(); } } else if (_lives.Count < _model.Lives) { _lives.Add(new object()); } OnPropertyChanged("Lives"); // Remove dead invaders who have finished fading out foreach (FrameworkElement control in _shotInvaders.Keys.ToList()) { DateTime invaderDiedTime = _shotInvaders[control]; TimeSpan timeSinceInvaderDied = DateTime.Now - invaderDiedTime; if (timeSinceInvaderDied > _timeLimitInvadersFadeoutSeconds) { _sprites.Remove(control); _shotInvaders.Remove(control); } } if (GameOver) { OnPropertyChanged("GameOver"); _timer.Stop(); } }