//Enemy public static void HandleEnemy() { //Update Enemy Animation foreach (Enemy e in npcs) { int r = rand.Next(1, 10); e.Update(anyKey, timeDelta, r); } //Enemy Attack calcs foreach (Enemy bg in npcs) { if (bg.DoAttack && bg.IsDead == false) { int speed = 0; int r = rand.Next(2); if (r == 1) { speed = 5; } else { speed = -5; } Ammo aa = new Ammo(graphics, bg.X, bg.Y, bg.CharacterImage, speed, bg.UniqueID); npcAmmo.Add(aa); } } ////Enemy Attack Update foreach (Ammo a in npcAmmo) { a.Update(); } //Enemy Attack Cleanup for (int i = npcAmmo.Count - 1; i >= 0; i--) { if (npcAmmo[i].CleanUp) { npcAmmo.RemoveAt(i); } } bool isBGDead = true; foreach (Enemy bg in npcs) { if (bg.CleanUp && isBGDead) { isBGDead = true; } else { isBGDead = false; } } if (isBGDead) { currentState = GameState.GameOver; } }
//Player Controls private static void HandlePlayer() { //player 1 if (doButtonLeft) { heroMoveX--; player1IsRight = false; } if (doButtonRight) { heroMoveX++; player1IsRight = true; } if (doButtonUp) { heroMoveY--; } if (doButtonDown) { heroMoveY++; } heroes[0].Update(heroMoveX, heroMoveY, heroes); //player 2 if (character2 != "") { if (doButtonSquare) { hero2MoveX--; player2IsRight = false; } if (doButtonCircle) { hero2MoveX++; player2IsRight = true; } if (doButtonTriangle) { hero2MoveY--; } if (doButtonCross) { hero2MoveY++; } heroes[1].Update(hero2MoveX, hero2MoveY, heroes); } //Player 1 atk P1AtkTimeCounter += timeDelta; if (P1AtkTimeCounter > 1000) { if (doButtonR && heroes[0].IsDead == false) { int speed = 0; if (player1IsRight) { speed = 5; } else { speed = -5; } Ammo aa = new Ammo(graphics, heroes[0].X, heroes[0].Y, heroes[0].CharacterImage, speed, heroes[0].UniqueID); pcAmmo.Add(aa); P1AtkTimeCounter = 0; } } //Player 2 Attack P2AtkTimeCounter += timeDelta; if (P2AtkTimeCounter > 1000) { if (doButtonL && heroes[1].IsDead == false) { int speed = 0; if (player2IsRight) { speed = 5; } else { speed = -5; } Ammo aa = new Ammo(graphics, heroes[1].X, heroes[1].Y, heroes[1].CharacterImage, speed, heroes[1].UniqueID); pcAmmo.Add(aa); P2AtkTimeCounter = 0; } } //Player Attack Update foreach (Ammo a in pcAmmo) { a.Update(); } //Player Attack Cleanup for (int i = pcAmmo.Count - 1; i >= 0; i--) { if (pcAmmo[i].CleanUp) { pcAmmo.RemoveAt(i); } } //Both Players are Dead if (heroes[0].CleanUp && heroes[1].CleanUp) { currentState = GameState.Dead; } }