/// <summary> /// /// </summary> public GameModel() { GameModel.XDistanceBetweenSprites = 100; GameModel.YDistanceBetweenSprites = 300; GameModel.YDistanceBetweenStars = 50; GameModel.YDistanceBetweenStars = 200; GameModel.YDistanceBetweenBlueStars = 50; GameModel.YDistanceBetweenSmallStars = 200; GameModel.LeftDisplayBorder = 50; GameModel.RightDisplayBorder = 200; GameModel.BottomDisplayBorder = 140; _background = new Background(); _enemies[0] = new Enemy1(4, 3); _enemies[1] = new Enemy2(4, 3); _enemies[2] = new Enemy3(4, 3); _enemies[3] = new Enemy4(4, 3); _spaceShip = new AnimatedSprite(5, 4); for (int i = 0; i < _meteors.Length; i++) _meteors[i] = new Meteor(9, 8); for (int i = 0; i < _stars.Length; i++) { _stars[i] = new Star(15, 7); _stars[i].Speed = new Vector2(0, 0.5f); } for (int i = 0; i < _fastStars.Length; i++) { _fastStars[i] = new Star(15, 10); _fastStars[i].Speed = new Vector2(0, 1f); } _InitializeLives(); _progress = new ProgressSprite(); }
/// <summary> /// /// </summary> /// <param name="sprites"></param> /// <param name="framesCount"></param> /// <param name="pointsForKill"></param> private void _SolveEnemiesCollisions(AnimatedSprite[] sprites, int framesCount, uint pointsForKill) { // Solve collisions between boxes. var distance = _window.ClientBounds.Width - GameModel.XDistanceBetweenSprites; foreach (var enemy in sprites) { var maxValue = distance - enemy.SpriteTexture.Width / 4; var rocket = new Rocket(); if ((rocket = _IsRocketBitTheEnemy(enemy.BoundingBox)) != null) { // Recalculate position of the bugs... (could be BOOOM! or POINTS++). enemy.SpritePosition = new Vector2( _randomizer.Next(GameModel.LeftDisplayBorder, maxValue), -GameModel.YDistanceBetweenSprites); _model.Rockets.Remove(rocket); AudioPlayer.PlayEnemyDestroyed(); GameState.CurrentScore += pointsForKill; } if (_model.SpaceShip.BoundingBox.Intersects(enemy.BoundingBox)) { // Recalculate position of the bugs... (could be BOOOM! or POINTS++). enemy.SpritePosition = new Vector2( _randomizer.Next(GameModel.LeftDisplayBorder, maxValue), -GameModel.YDistanceBetweenSprites); if (_model.Lives.Count > 1) { _model.RemoveLive(); TimeSpan span = AudioPlayer.PlayEnemySuperShoot(); } else _GameOver(); } } }
/// <summary> /// /// </summary> /// <param name="sprites"></param> /// <param name="xDistanceBetweenSprites"></param> /// <param name="yDistanceBetweenSprites"></param> /// <param name="spriteFramesCount"></param> private void _MoveSprite(AnimatedSprite[] sprites, int xDistanceBetweenSprites, int yDistanceBetweenSprites, int spriteFramesCount) { var distance = _window.ClientBounds.Width - xDistanceBetweenSprites; for (int i = 0; i < sprites.Length; i++) { sprites[i].SpritePosition += sprites[i].Speed; // When sprite comes over the Screen, bring him back if (sprites[i].SpritePosition.Y > _window.ClientBounds.Height) { sprites[i].SpritePosition = new Vector2(_randomizer.Next( GameModel.LeftDisplayBorder, distance - sprites[i].SpriteTexture.Width / spriteFramesCount), -yDistanceBetweenSprites); } } }