AlienSprite FindBottomAlienInCol(int col) { AlienSprite Found = null; Found = aliens.Where(a => a.Col == col && a.State == AlienStates.Alive).OrderByDescending(a => a.Row).FirstOrDefault(); return(Found); }
void AlienShoot() { List <AlienSprite> ShootingAliens = new List <AlienSprite>(); for (int col = 1; col <= 11; col++) { AlienSprite Alien; Alien = FindBottomAlienInCol(col); if (Alien != null) { ShootingAliens.Add(Alien); } } if (ShootingAliens.Count > 0 && Mode == PlayScreenModes.Playing) { int ShooterIndex = Random.Next(0, ShootingAliens.Count() - 1); AlienSprite ShootingAlien = ShootingAliens[ShooterIndex]; /* * foreach (AlienSprite alien in aliens) * { * alien.GhostEffect = 0; * } * foreach (AlienSprite alien in ShootingAliens) * { * alien.GhostEffect = 50; * } * ShootingAlien.GhostEffect = 70; */ AlienShoot(ShootingAlien); ScheduleAlienShoot(); } }
/// <summary> /// Create all of the aliens when a level starts /// </summary> public void CreateAliens() { Sprites.RemoveAll(s => s is AlienSprite); aliens.Clear(); AlienCount = 0; // Create 55 alien sprites in 5 rows of 11 for (int row = 1; row <= 5; row++) { for (int col = 1; col <= 11; col++) { AlienSprite newAlien = AddSprite <AlienSprite>(); newAlien.X = -100 + col * 14; newAlien.Y = 80 - row * 10; newAlien.Col = col; newAlien.Row = row; if (row == 1) { newAlien.Setup(3); } if (row == 2 || row == 3) { newAlien.Setup(2); } if (row == 4 || row == 5) { newAlien.Setup(1); } aliens.Add(newAlien); AlienCount++; } } }
void AlienShoot(AlienSprite ShootingAlien) { AlienMissileSprite AlienMissile; AlienMissile = new AlienMissileSprite(); alienMissiles.Add(AlienMissile); AddSprite(AlienMissile); AlienMissile.Fire(ShootingAlien.Position, ShootingAlien.Rotation); }
}
/// <summary> /// Start the title screen /// This happens at the beginning of the game, and when you're done playing /// </summary> public override void StartScene() { Texts.Clear(); Sprites.Clear(); // Add the title text AddText(new Text { Value = "Space Invaders", Position = new Vector2(0f, 80f), Alignment = HorizontalAlignments.Center, AnimationType = TextAnimations.Typewriter, AnimationSeconds = 0.15, Scale = 1f, //Font = FancyFont, OnAnimationComplete = (Text text) => { // When the title text is done typing, show the high score HighScoreText = AddText(new Text { Value = "High Score:", Position = new Vector2(80f, 90f), Alignment = HorizontalAlignments.Center, VerticalAlign = VerticalAlignments.Top, AnimationType = TextAnimations.SeeSaw, AnimationSeconds = 0.2, AnimationIntensity = 0.15, Scale = 0.4f, }); UfoSprite ufo = AddSprite <UfoSprite>(); ufo.X = -49; ufo.Y = 45; Wait(2.3f, () => { AlienSprite alien = AddSprite <AlienSprite>(); alien.X = -40; alien.Y = 13; alien.Setup(1); }); Wait(5.2f, () => { AlienSprite alien = AddSprite <AlienSprite>(); alien.X = -40; alien.Y = -13; alien.Setup(2); }); Wait(8.7, () => { AlienSprite alien = AddSprite <AlienSprite>(); alien.X = -40; alien.Y = -43; alien.Setup(3); }); AlienScoreText = AddText(new Text { Value = "= ? POINTS" + Text.NewLine + Text.NewLine + "= 10 POINTS" + Text.NewLine + Text.NewLine + "= 20 POINTS" + Text.NewLine + Text.NewLine + "= 30 POINTS", Position = new Vector2(0, 0), Alignment = HorizontalAlignments.Center, VerticalAlign = VerticalAlignments.Center, AnimationType = TextAnimations.Typewriter, AnimationSeconds = 0.2, Scale = 0.8f, Color = Color.White }); } }); // Add the 1p start key text Player1StartText = AddText(new Text { Value = "1 Player Start", Position = new Vector2(-65f, -85f), Alignment = HorizontalAlignments.Center, VerticalAlign = VerticalAlignments.Center, AnimationType = TextAnimations.None, AnimationIntensity = 0.2, Scale = 0.6f, Color = Color.Lime }); // Add the 2p start key text Player2StartText = AddText(new Text { Value = "2 Player Start", Position = new Vector2(65f, -85f), Alignment = HorizontalAlignments.Center, VerticalAlign = VerticalAlignments.Center, AnimationType = TextAnimations.None, AnimationIntensity = 0.2, Scale = 0.6f, Color = Color.Lime }); if (SpaceInvaders.NumberOfPlayers == 1) { Player1StartText.AnimationType = TextAnimations.Throb; Player1StartText.Scale = 0.6f; Player1StartText.Start(); } else { Player2StartText.AnimationType = TextAnimations.Throb; Player2StartText.Scale = 0.6f; Player2StartText.Start(); } }