/// <summary> /// New stage in the game where new invaders created /// </summary> public void NextWave() { Wave++; Invaders.Clear(); for (var row = 0; row <= 1; row++) { for (var column = 0; column < 11; column++) { var location = new Point(column * Invader.InvaderSize.Width * 1.4, row * Invader.InvaderSize.Height * 1.4); Invader invader; switch (row) { case 0: invader = new Invader(InvaderType.Enemy2, location, 20); break; default: invader = new Invader(InvaderType.Enemy1, location, 10); break; } Invaders.Add(invader); TriggerShipChanged(invader, false); } } }
/// <summary> /// Adds a bomb from an invader /// </summary> /// <param name="bombLocation"> /// the location where the bomb should be dropped from, if it is not assigned then a random /// location will be assigned /// </param> public void FireBomb(Point bombLocation = new Point()) { if (_isPlayerDead) { return; } if (!Invaders.Any()) { return; } if (!_helper.CanFireBomb(InvaderShots.Count, Wave)) { return; } if (!bombLocation.Initialized) { bombLocation = _helper.GetRandomBombLocation(Invaders); } var invaderShot = new Shot(bombLocation, Direction.Down, ShotType.Bomb); InvaderShots.Add(invaderShot); TriggerShotMoved(invaderShot, false); }
public void RestartLevel() { RemoveInvaders(); Invaders.Clear(); Invaders.TrimExcess(); CurrentLevelKills = 0; _CoreTicks = 0; }
public void RemoveInvaders() { foreach (Mobile target in Invaders.ToArray()) { target.Delete(); } Invaders.Clear(); Invaders.TrimExcess(); }
/// <summary> /// Sets the game from the initial state /// </summary> public void InitializeGameStatus() { GameOver = false; Lives = 2; Wave = 0; PlayerShots.Clear(); InvaderShots.Clear(); Invaders.Clear(); }
/// <summary> /// Check for winners among invaders. /// /// For now simply counts number of /// invaders that <c>HasScored</c>. /// /// And if more than 0, then /// <c>Winner</c> is set to /// <c>WinnerType.Invader</c> /// /// </summary> internal void CheckForWinnersAmongInvaders() { int numberOfScoredInvaders = Invaders.Count( i => i.HasScored ); if (numberOfScoredInvaders > 0) { Winner = WinnerType.Invader; } }
public void ClearGame()//Removes all Gameobjects from the Gamedisplay and resets the Gamevalues { Player.HealthPoints = 3; score = 0; levelcounter = 1; PlayerProjectiles.Clear(); EnemyProjectiles.Clear(); Invaders.Clear(); Ufos.Clear(); Walls.Clear(); GameDisplay.Children.Clear(); }
public void CleanTemporaryGameLists()//gameobject lists are cleaned up { GameDisplay.Children.Clear(); //lists are updated EnemyProjectiles = EnemyProjectiles.Except(TemporaryEnemyProjectiles).ToList(); PlayerProjectiles = PlayerProjectiles.Except(TemporaryPlayerProjectiles).ToList(); Ufos = Ufos.Except(TemporaryUfos).ToList(); Walls = Walls.Except(TemporaryWalls).ToList(); Invaders = Invaders.Except(TemporaryInvaders).ToList(); //temporary lists are cleared TemporaryWalls.Clear(); TemporaryPlayerProjectiles.Clear(); TemporaryInvaders.Clear(); TemporaryEnemyProjectiles.Clear(); TemporaryUfos.Clear(); }
/*public void DeleteInvasion() * { * if (Status == InvasionStatus.Running) * { * Status = InvasionStatus.Finished; * _CoreTimer.Stop(); * } * * Levels.Clear(); * RemoveInvaders(); * if (ValidSpawnPoints != null) * { * ValidSpawnPoints.Clear(); * } * * foreach (PlayerInvasionProfile profile in EventInvasions.PlayerProfiles.Values) * { * if (profile.SpecificInvasionScores.ContainsKey(UID)) * { * profile.OverallScore -= profile.SpecificInvasionScores[UID]; * profile.SpecificInvasionScores.Remove(UID); * } * } * * EventInvasions.Invasions.Remove(UID); * * }*/ public void SpawnInvaders(int amount) { for (int i = 0; i < amount; i++) { if (Invaders.Count >= CurrentLevel.SpawnAmount) { break; } Type selected = CurrentLevel.Creatures.GetRandom(); if (selected.IsEqualOrChildOf <Mobile>()) { var mob = selected.CreateInstanceSafe <BaseCreature>(); if (mob != null) { if (!String.IsNullOrWhiteSpace(CurrentLevel.InvaderTitles)) { mob.SpecialTitle = CurrentLevel.InvaderTitles; } else { mob.SpecialTitle = "Invader"; } mob.TitleHue = 1174; mob.GuardImmune = true; mob.Invasion = this; if (Utility.RandomDouble() <= 0.01) { mob.IsParagon = true; } if (CurrentLevel.Plat > 0 && mob.Backpack != null) { mob.AddToBackpack(new Platinum(CurrentLevel.Plat)); } Invaders.Add(mob); } } } if (ValidSpawnPoints == null || ValidSpawnPoints.Count == 0) { ValidSpawnPoints = GenerateSpawnLocations(); } foreach (Mobile invader in Invaders.Where(invader => invader.Map == Map.Internal)) { invader.MoveToWorld(ValidSpawnPoints.GetRandom(), Map.Felucca); } }
/// <summary> /// Kontruktor der Klasse Game, nimmt die SpaceInvaderForm entgegen /// </summary> /// <param name="container"></param> public Game(SpaceInvadersForm container) { _container = container; _gameTimer = new Timer(); _gameTimer.Interval = 1; _gameTimer.Tick += Play; _rocks = new Rocks(this); _ship = new SpaceShip(this); _infobar = new Infobar(this); _invaders = new Invaders(this); _bulletItem = new BulletItem(this); _movespeedItem = new MovespeedItem(this); _itemWatch = new Stopwatch(); }
public void RestartInvasion() { CurrentLevel = Levels.First(); Invaders.Clear(); Invaders.TrimExcess(); CurrentLevelKills = 0; _CoreTicks = 0; DateStarted = DateTime.UtcNow; ParticipantsScores.Clear(); SpawnInvaders(CurrentLevel.SpawnAmount); Status = InvasionStatus.Running; Notify.Broadcast <HydraMotMNotifyGump>( "The " + InvasionName + " has begun!", true, 1.0, 10.0); init(); }
public GameState(params Spirit[] spirits) { if (spirits.Length == 0) { throw new ArgumentException("Game must include at least 1 spirit"); } this.Spirits = spirits; // Note: don't init invader deck here, let users substitute RoundNumber = 1; Fear = new Fear(this); Invaders = new Invaders(this); Tokens = new Tokens_ForIsland(this); TimePasses_WholeGame += TokenCleanUp; TimePasses_WholeGame += ModifyBlightAddedEffect.ForRound.Clear; TimePasses_WholeGame += PreRavaging.ForRound.Clear; TimePasses_WholeGame += PreBuilding.ForRound.Clear; TimePasses_WholeGame += PreExplore.ForRound.Clear; }
public void CheckForInvaderHit() { if (_isPlayerDead) { return; } var shotsHit = new List <Shot>(); var invadersKilled = new List <Invader>(); foreach (var shot in PlayerShots) { var invadersShot = (from invader in Invaders where invader.Area.Contains(shot.Location) && shot.Direction == Direction.Up select new { InvaderKilled = invader, ShotHit = shot }).ToList(); if (!invadersShot.Any()) { continue; } foreach (var invadershot in invadersShot) { shotsHit.Add(invadershot.ShotHit); invadersKilled.Add(invadershot.InvaderKilled); } } foreach (var invader in invadersKilled) { Score += invader.Score; Invaders.Remove(invader); TriggerShipChanged(invader, true); } foreach (var shot in shotsHit) { PlayerShots.Remove(shot); TriggerShotMoved(shot, true); } }
/// <summary> /// Checks if there is a collision between the player with an invador /// </summary> /// <returns></returns> public bool IsPlayerInvadorCollision() { if (_isPlayerDead) { return(false); } var collidedInvaders = (from invader in Invaders where invader.Area.IntersectsWith(_player.Area) select invader).ToList(); if (!collidedInvaders.Any()) { return(false); } foreach (var invader in collidedInvaders.ToList()) { Score += invader.Score; Invaders.Remove(invader); TriggerShipChanged(invader, true); } return(true); }
public static void InitializeMap() { Walls.Clear(); Nodes.Clear(); EmptySquares.Clear(); Dots.Clear(); Powerups.Clear(); Ghosts.Clear(); Invaders.Clear(); //Initializes border of map string line = ""; int number = 0; using (StreamReader sr = new StreamReader("Maps/pacman" + PacmanGame.maps[PacmanGame.mapNumber].ToString() + ".txt")) { while (true) { line = sr.ReadLine(); if (line == null) { break; } for (int counter = 0; counter < line.Length; counter++) { wallMap[counter, number] = line[counter].ToString() == "0"; } number++; } } //Fills in rest of map using two dimensional bool array wallMap for (int x = 0; x < wallMap.GetLength(0); x++) { for (int y = 0; y < wallMap.GetLength(1); y++) { if (!wallMap[x, y]) { Walls.Add(new Wall(new Rectangle(x * PacmanGame.gridSize + PacmanGame.horizontalSpace, y * PacmanGame.gridSize + PacmanGame.verticalSpace, PacmanGame.gridSize, PacmanGame.gridSize))); } } } //Fills map with empty squares, dots and nodes in all places without walls //variable used to count nodes int variable = 0; for (int y = 1; y < PacmanGame.mapHeight / PacmanGame.gridSize - 1; y++) { for (int x = 1; x < PacmanGame.mapWidth / PacmanGame.gridSize - 1; x++) { Rectangle rectangle = new Rectangle(PacmanGame.gridSize * x + PacmanGame.horizontalSpace, PacmanGame.gridSize * y + PacmanGame.verticalSpace, PacmanGame.gridSize, PacmanGame.gridSize); bool value = true; foreach (Wall wall in Walls) { if (wall.Position == rectangle) { value = false; } } if (value) { EmptySquares.Add(new EmptySquare(rectangle)); Dots.Add(new Dot(rectangle)); Nodes.Add(new Node(variable, rectangle)); variable++; } } } //Remove the dot where the pacman starts Dots.Remove(new Dot(new Rectangle(PacmanGame.gridSize, PacmanGame.gridSize, PacmanGame.gridSize, PacmanGame.gridSize))); //Adds powerups Random random = new Random(); int[] values = Enumerable.Range(0, Map.Nodes.Count).OrderBy(x => random.Next()).ToArray(); for (int counter = 0; counter < 4; counter++) { int index = values[counter]; Rectangle rectangleValue = Map.Nodes.ElementAt(index).Position; Powerups.Add(new Powerup(rectangleValue)); //Remove the dot where the powerup is Dots.Remove(new Dot(rectangleValue)); } createAdjacencyList(); Paddles[0] = new Paddle(new Rectangle(PacmanGame.horizontalSpace / 2, PacmanGame.screenHeight / 2, PacmanGame.gridSize, PacmanGame.gridSize * 5), Player.Left); Paddles[1] = new Paddle(new Rectangle(PacmanGame.screenWidth - PacmanGame.horizontalSpace / 2, PacmanGame.screenHeight / 2, PacmanGame.gridSize, PacmanGame.gridSize * 5), Player.Right); }
private void SetInvaderRows() //generate Invaders { int randomInt = Rnd.Next(0, 4); //random invader skin //generates five rows of aliens for (int j = 0; j < 5; j++) { //generates 15 aliens per row for (int i = 0; i < 15; i++) { //new object of the type Invader Invader OneInvader = new Invader(GameDisplay, 5 + difficultyIndex * 2.1) { X = i * 35 + 5, Y = (j * 35 + 5) + 50 }; Invaders.Add(OneInvader); switch (randomInt)//instanciates a new Image foreach Invader { case 0: switch (j) { case 0: OneInvader.reci.Fill = new ImageBrush(new BitmapImage(new Uri("Images/Enemies/enemyRed1.PNG", UriKind.Relative))); break; case 1: OneInvader.reci.Fill = new ImageBrush(new BitmapImage(new Uri("Images/Enemies/enemyRed2.PNG", UriKind.Relative))); break; case 2: OneInvader.reci.Fill = new ImageBrush(new BitmapImage(new Uri("Images/Enemies/enemyRed3.PNG", UriKind.Relative))); break; case 3: OneInvader.reci.Fill = new ImageBrush(new BitmapImage(new Uri("Images/Enemies/enemyRed4.PNG", UriKind.Relative))); break; case 4: OneInvader.reci.Fill = new ImageBrush(new BitmapImage(new Uri("Images/Enemies/enemyRed5.PNG", UriKind.Relative))); break; } break; case 1: switch (j) { case 0: OneInvader.reci.Fill = new ImageBrush(new BitmapImage(new Uri("Images/Enemies/enemyBlue1.PNG", UriKind.Relative))); break; case 1: OneInvader.reci.Fill = new ImageBrush(new BitmapImage(new Uri("Images/Enemies/enemyBlue2.PNG", UriKind.Relative))); break; case 2: OneInvader.reci.Fill = new ImageBrush(new BitmapImage(new Uri("Images/Enemies/enemyBlue3.PNG", UriKind.Relative))); break; case 3: OneInvader.reci.Fill = new ImageBrush(new BitmapImage(new Uri("Images/Enemies/enemyBlue4.PNG", UriKind.Relative))); break; case 4: OneInvader.reci.Fill = new ImageBrush(new BitmapImage(new Uri("Images/Enemies/enemyBlue5.PNG", UriKind.Relative))); break; } break; case 2: switch (j) { case 0: OneInvader.reci.Fill = new ImageBrush(new BitmapImage(new Uri("Images/Enemies/enemyBlack1.PNG", UriKind.Relative))); break; case 1: OneInvader.reci.Fill = new ImageBrush(new BitmapImage(new Uri("Images/Enemies/enemyBlack2.PNG", UriKind.Relative))); break; case 2: OneInvader.reci.Fill = new ImageBrush(new BitmapImage(new Uri("Images/Enemies/enemyBlack3.PNG", UriKind.Relative))); break; case 3: OneInvader.reci.Fill = new ImageBrush(new BitmapImage(new Uri("Images/Enemies/enemyBlack4.PNG", UriKind.Relative))); break; case 4: OneInvader.reci.Fill = new ImageBrush(new BitmapImage(new Uri("Images/Enemies/enemyBlack5.PNG", UriKind.Relative))); break; } break; case 3: switch (j) { case 0: OneInvader.reci.Fill = new ImageBrush(new BitmapImage(new Uri("Images/Enemies/enemyGreen1.PNG", UriKind.Relative))); break; case 1: OneInvader.reci.Fill = new ImageBrush(new BitmapImage(new Uri("Images/Enemies/enemyGreen2.PNG", UriKind.Relative))); break; case 2: OneInvader.reci.Fill = new ImageBrush(new BitmapImage(new Uri("Images/Enemies/enemyGreen3.PNG", UriKind.Relative))); break; case 3: OneInvader.reci.Fill = new ImageBrush(new BitmapImage(new Uri("Images/Enemies/enemyGreen4.PNG", UriKind.Relative))); break; case 4: OneInvader.reci.Fill = new ImageBrush(new BitmapImage(new Uri("Images/Enemies/enemyGreen5.PNG", UriKind.Relative))); break; } break; } } } }
/// <summary> /// For now we simply move all invaders /// by calling <c>Move</c> method on each /// of them using LINQ and <c>List.ForEach</c> /// </summary> private void MakeInvadersStep() { Invaders.ForEach( i => i.Move() ); }
/// <summary> /// Removes all Invaders that were /// neutralized after Towers step /// using LINQ with <c>List.RemoveAll</c> method /// with filter for <c>IsNeutralized</c> /// property /// </summary> internal void RemoveNeutralizedInvaders() { Invaders.RemoveAll( i => i.IsNeutralized ); }
public void CheckBulletCollisions() { List <Bullet> bulletsToRemove = new List <Bullet>(); List <Invader> invadersToRemove = new List <Invader>(); List <SuperUFO> UFOtoRemove = new List <SuperUFO>(); List <CaveBlock> CaveBlocksToRemove = new List <CaveBlock>(); foreach (var bullet in Player.Bullets) { if (bullet.IsOffScreen(GameWindow)) { bulletsToRemove.Add(bullet); } if (Invaders.Count != 0) { foreach (Invader invader in Invaders) { if (bullet.CollidedWith(invader)) { bulletsToRemove.Add(bullet); invadersToRemove.Add(invader); // invader.IsDead = true; int addScore = 100; Player.Score = Player.Score + addScore; bullet.CollisionSound.Play(); } } } foreach (var UFO in SuperUFOs) { if (UFO.IsOffScreenWidth(GameWindow)) { UFOtoRemove.Add(UFO); } if (bullet.CollidedWith(UFO)) { bulletsToRemove.Add(bullet); UFOtoRemove.Add(UFO); UFO.IsDead = true; Player.Score = Player.Score + 1000; bullet.CollisionSound.Play(); } } foreach (var cBlock in CaveBlocks) { if (cBlock.CollidedWith(bullet)) { bulletsToRemove.Add(bullet); CaveBlocksToRemove.Add(cBlock); Player.Score -= 500; cBlock.CaveCollide.Play(); } } } foreach (var bullet in bulletsToRemove) { Player.Bullets.Remove(bullet); } foreach (var invader in invadersToRemove) { Invaders.Remove(invader); } foreach (var UFO in UFOtoRemove) { SuperUFOs.Remove(UFO); } foreach (var cBlock in CaveBlocksToRemove) { CaveBlocks.Remove(cBlock); } CaveBlocksToRemove.Clear(); invadersToRemove.Clear(); UFOtoRemove.Clear(); CaveBlocksToRemove.Clear(); }
public void RemoveInvader(Mobile invader) { Invaders.Remove(invader); }
private void Awake() { instance = this; source = GetComponent <AudioSource>(); }