public void ResetGame(Object[] playerIdentifiers, Object thisPlayer) { if (playerIdentifiers.Length != 4) { throw new Exception("This game requires four players."); } // Copy the player identifiers - do not rely on the array parameter not changing. for (int i = 0; i < 4; i++) { this.playerIdentifiers[i] = playerIdentifiers[i]; } // Create new game state and inputs objects. state = new GameState(); inputs = new NextInputs(); // Record 'this' player. this.thisPlayerID = idPlayer(thisPlayer); }
/// <summary> /// Allows the game to run logic such as updating the world, /// checking for collisions, gathering input, and playing audio. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> public long Update(TimeSpan elapsedTime) { currentLevel.update(); state.advanceFrame(inputs, elapsedTime.Milliseconds); // Apply the inputs, advance game state. inputs = new NextInputs(); // Start with inputs cleared on the next frame. if (presses != 0) { cumulAccuracy = ((double)duckHits / presses) * 100; accuracy1 = ((double)duckHits1 / presses1) * 100; accuracy2 = ((double)duckHits2 / presses2) * 100; duckAccuracy = ((double)duckHits / duckCount) * 100; } //Stuff that used to be here is now all done in APPLYMOUSEBUTTONINPUT if (!currentLevel.levelTransition) { //keeps the ducks coming for a set amount fo frames default is 70; if (state.frameNumber % currentLevel.nextFrameToMakeDucks == 0) { System.Random ran = new System.Random(); //creates the number of ducks per cylce //targetName is by default Duck, expandable to be other names for (int i = 0; i < currentLevel.ducksPerCylce; i++) { if (currentLevel.levelNumber % 4 == 3) { duckCount++; getRandom(currentLevel.maxSpeed, "SpaceDuck"); } if (currentLevel.levelNumber % 4 == 1 || currentLevel.levelNumber % 4 == 2 || currentLevel.levelNumber % 4 == 0) { duckCount++; getRandom(currentLevel.maxSpeed, targetName); } if (this.currentLevel.levelNumber % 4 == 0 && gducks.Count < 1) { gducks.Add(new HugeDuck(this, new Vector2(300, 400))); duckCount++; } } } //increases the amount of ducks to be realeased each set amount //this is based off of the frame number if (CurrentFrameNumber % 1500 == 0) { currentLevel.ducksPerCylce++; } //since we have a god duck we only want three coming from the sides if (currentLevel.levelNumber % 4 == 0) { currentLevel.ducksPerCylce = 3 * currentLevel.levelNumber / 4; } //if a gducks mouth is open and your at a frame divisible by 50 have ducks come out of mouth for (int i = 0; i < gducks.Count; i++) { if (gducks[i].mouthOpen && state.frameNumber % 50 == 0) { for (int j = 0; j < 3; j++) { randomMouthDucks(); } } } } //update each duck using the current game time for (int i = 0; i < ducks.Count; i++) { ducks[i].Update(elapsedTime, state.frameNumber); if (ducks[i].location.Y < 0 || ducks[i].location.Y > 800 || ducks[i].location.X < 0 || ducks[i].location.X > 800) { ducks.Remove(ducks[i]); } } for (int i = 0; i < sducks.Count; i++) { sducks[i].Update(elapsedTime, state.frameNumber); if (sducks[i].location.Y < 0 || sducks[i].location.Y > 800 || sducks[i].location.X < 0 || sducks[i].location.X > 800) { sducks.Remove(sducks[i]); } } for (int i = 0; i < gducks.Count; i++) { gducks[i].Update(elapsedTime, state.frameNumber); if (gducks[i].location.Y < 0 || gducks[i].location.Y > 800 || gducks[i].location.X < 0 || gducks[i].location.X > 800) { gducks.Remove(gducks[i]); } } if (cumulPoints >= requiredPoints && cumulAccuracy >= requiredAccuracy) // && cumulAccuracy >= 0.60 && currentLevel.levelNumber == 4 && currentLevel.count > 600) { currentLevel.winLose = true; } else { currentLevel.winLose = false; } return(state.frameNumber); }