public void Initialize() { //Fill game maps : can change during execution //************************************************************************************************ //LevelCount = 7; //Do not forget !!! //WorldCount = 5; if (TGPAContext.Instance.IsTrialMode == false) { //Level bonus test //maps = new World(new String[] { "level0.tgpa", "level1.tgpa", "level2_1.tgpa", "level2_2.tgpa", "level3_1.tgpa", "level3_2.tgpa", "level4_1.tgpa", "level4_2.tgpa", "level5.tgpa", "level_b1_2.tgpa", "level_b1_1.tgpa" }, // new int[] { 0, 1, 2, 2, 3, 3, 4, 4, 5, 6, 6 }); //LevelCount = 10; //WorldCount = 7; //Classic game config maps = new World(new String[] { "level0.tgpa", "level1.tgpa", "level2_1.tgpa", "level2_2.tgpa", "level3_1.tgpa", "level3_2.tgpa", "level4_1.tgpa", "level4_2.tgpa", "level5.tgpa" }, new int[] { 0, 1, 2, 2, 3, 3, 4, 4, 5 }); LevelCount = 9; WorldCount = 6; } else //Demo mode { maps = new World(new String[] { "level0.tgpa", "level1.tgpa" }, new int[] { 0, 1 }); WorldCount = 2; LevelCount = 2; } alphaColorForLevelBlinking = 0.5f; blinkingDelta = 0.01f; aimedlevel = -1; pointedIndex = -1; //Level pointed by mouse or next mevem focus = LevelSelectionScreenButton.Level; LoadOverview(selectedIndex); shipIsMoving = false; shipAngle = 0.0f; shipFlip = SpriteEffects.None; this.scoreType = ScoreType.Single; if (TGPAContext.Instance.Player2 != null) { this.scoreType = ScoreType.Coop; } //Difficulty launchLevel = false; difficultyChoosen = false; fadeoutAlpha = 0.9f; loadingLaunched = false; }
/// <summary> /// Level selection, launch game, come back, etc /// </summary> /// <param name="gameTime"></param> /// <param name="Game"></param> public void Update(GameTime gameTime) { if (loadingLaunched == true) return; float elapsedTime = (float)gameTime.ElapsedGameTime.TotalSeconds; alphaColorForLevelBlinking += blinkingDelta; if (alphaColorForLevelBlinking >= 1f) { alphaColorForLevelBlinking = 1f; blinkingDelta = -blinkingDelta; } else if (alphaColorForLevelBlinking <= 0f) { alphaColorForLevelBlinking = 0f; blinkingDelta = -blinkingDelta; } if (TGPAContext.Instance.InputManager.PlayerPressButtonBack(TGPAContext.Instance.Player1)) { if (launchLevel) { launchLevel = false; } else { TGPAContext.Instance.CurrentGameState = GameState.TitleScreen; return; } } #region Level launch if (launchLevel) { fadeoutAlpha += 0.01f; if (fadeoutAlpha > 0.75f) fadeoutAlpha = 0.75f; if (difficultyChoosen) { Thread t = new Thread(new ThreadStart( delegate() { TGPAContext.Instance.PrepareGame(); })); t.Start(); loadingLaunched = true; } else { difficultyListControl.Update(gameTime); } } else { fadeoutAlpha -= 0.01f; if (fadeoutAlpha < 0f) fadeoutAlpha = 0f; } #endregion #region Input management if ((!launchLevel) & (!shipIsMoving)) // controls are enabled only if the ship is on a point otherwise you have to wait { //PC Management if (TGPAContext.Instance.Player1.IsPlayingOnWindows()) { Rectangle mouseEnhancedDst = TGPAContext.Instance.MouseDst; mouseEnhancedDst.Inflate(10, 10); if (playDst.Intersects(mouseEnhancedDst)) { focus = LevelSelectionScreenButton.Play; if (TGPAContext.Instance.InputManager.PlayerPressButtonConfirm(TGPAContext.Instance.Player1)) { launchLevel = true; } } else if (backDst.Intersects(mouseEnhancedDst)) { focus = LevelSelectionScreenButton.Back; if (TGPAContext.Instance.InputManager.PlayerPressButtonConfirm(TGPAContext.Instance.Player1)) { TGPAContext.Instance.CurrentGameState = GameState.TitleScreen; } } else { //Click on a level = change selected index for (int i = 0; i < WorldCount; i++) { Rectangle levelDst = Rectangle.Empty; //The player need to have unlocked the level to display it if ((i <= TGPAContext.Instance.Saver.SaveData.LastLevel) && (i < WorldCount)) { Vector2 loc = levelPositionOnMap[i]; levelDst = new Rectangle( (int)loc.X - levelSrc.Width / 2, (int)loc.Y - levelSrc.Height / 2, levelSrc.Width, levelSrc.Height ); } pointedIndex = -1; if (levelDst.Intersects(mouseEnhancedDst)) { //if (Math.Abs(i - selectedIndex) > 1) break; //not allow player to select a too far point pointedIndex = i; if (TGPAContext.Instance.InputManager.PlayerPressButtonConfirm(TGPAContext.Instance.Player1)) { aimedlevel = i; } break; } } focus = LevelSelectionScreenButton.Level; } } #region Move with gamepad / Joystick bool goBack = false; bool goNext = false; Dictionary<ShipDirection,ShipAction> directionAndAction = availableShipDirectionByLevel[selectedIndex].Directions; if (TGPAContext.Instance.InputManager.PlayerGoLeft(TGPAContext.Instance.Player1) > 0f) { goBack = (directionAndAction[ShipDirection.Left] == ShipAction.GoBack); goNext = (directionAndAction[ShipDirection.Left] == ShipAction.GoNext); } if (TGPAContext.Instance.InputManager.PlayerGoRight(TGPAContext.Instance.Player1) > 0f) { goBack = (directionAndAction[ShipDirection.Right] == ShipAction.GoBack); goNext = (directionAndAction[ShipDirection.Right] == ShipAction.GoNext); } if (TGPAContext.Instance.InputManager.PlayerGoUp(TGPAContext.Instance.Player1) > 0f) { goBack = (directionAndAction[ShipDirection.Up] == ShipAction.GoBack); goNext = (directionAndAction[ShipDirection.Up] == ShipAction.GoNext); } if (TGPAContext.Instance.InputManager.PlayerGoDown(TGPAContext.Instance.Player1) > 0f) { goBack = (directionAndAction[ShipDirection.Down] == ShipAction.GoBack); goNext = (directionAndAction[ShipDirection.Down] == ShipAction.GoNext); } if (goNext) { //Go to next level if ((selectedIndex + 1 > TGPAContext.Instance.Saver.SaveData.LastLevel) || (selectedIndex + 1 >= WorldCount)) { aimedlevel = 0; } else { aimedlevel = selectedIndex + 1; } } else if (goBack) { if (selectedIndex - 1 < 0) { aimedlevel = TGPAContext.Instance.Saver.SaveData.LastLevel; if (aimedlevel >= WorldCount) { aimedlevel = WorldCount - 1; } } else { aimedlevel = selectedIndex - 1; } } #endregion if (TGPAContext.Instance.Player1.IsPlayingOnWindows() == false) { pointedIndex = aimedlevel; if (TGPAContext.Instance.InputManager.PlayerPressButtonConfirm(TGPAContext.Instance.Player1)) { launchLevel = true; } } //Both if (TGPAContext.Instance.InputManager.PlayerPressButtonSwitch(TGPAContext.Instance.Player1)) { this.scoreType = (this.scoreType == ScoreType.Single ? ScoreType.Coop : ScoreType.Single); } } #endregion #region Shipanimation Bezier if ((aimedlevel != -1) && (aimedlevel != selectedIndex) && (!shipIsMoving)) //if we have to move to the next destination { bezier_time = 0; shipIsMoving = true; duration = bezierDuration + (int)(Math.Sqrt(Math.Pow(levelPositionOnMap[selectedIndex].X - levelPositionOnMap[aimedlevel].X, 2) + Math.Pow(levelPositionOnMap[selectedIndex].Y - levelPositionOnMap[aimedlevel].Y, 2))) - (Math.Abs(aimedlevel - selectedIndex) - 1) * 200; } if ((shipIsMoving) && (aimedlevel != -1)) { bezier_time += gameTime.ElapsedGameTime.Milliseconds; Vector2 p1, p2, p3, p4; if (TGPAContext.Instance.Player1.IsPlayingOnWindows() == false) { if (selectedIndex < aimedlevel) //waypoints depend of the direction { p1 = levelPositionOnMap[selectedIndex]; p2 = pointsBezier[selectedIndex][0]; p3 = pointsBezier[selectedIndex][1]; p4 = levelPositionOnMap[selectedIndex + 1]; delta = 1; } else { p1 = levelPositionOnMap[selectedIndex]; p3 = pointsBezier[selectedIndex - 1][0]; p2 = pointsBezier[selectedIndex - 1][1]; p4 = levelPositionOnMap[selectedIndex - 1]; delta = -1; } } else { delta = aimedlevel - selectedIndex; p1 = levelPositionOnMap[selectedIndex]; p4 = levelPositionOnMap[aimedlevel]; if (selectedIndex < aimedlevel) { p2 = pointsBezier[selectedIndex + Math.Min(delta, 0)][0]; p3 = pointsBezier[selectedIndex + Math.Min(delta, 0)][1]; } else { p2 = pointsBezier[selectedIndex + Math.Min(delta, 0)][1]; p3 = pointsBezier[selectedIndex + Math.Min(delta, 0)][0]; } } float t = bezier_time / duration; //quadratic bezier equation need a parameter t, with 0<=t<=1 if (t <= 1) { shipDst.X = (int)((Math.Pow(1 - t, 3)) * p1.X + 3 * (Math.Pow(1 - t, 2)) * t * p2.X + 3 * (1 - t) * t * t * p3.X + t * t * t * p4.X) - shipSrc.Width / 2; shipDst.Y = (int)((Math.Pow(1 - t, 3)) * p1.Y + 3 * (Math.Pow(1 - t, 2)) * t * p2.Y + 3 * (1 - t) * t * t * p3.Y + t * t * t * p4.Y) - shipSrc.Height / 2; } else //if the journey is over { selectedIndex += delta; shipIsMoving = false; if (aimedlevel == selectedIndex) { aimedlevel = -1; LoadOverview(selectedIndex); } } //Post-it fade out alphaPostIt -= 0.05f; if (alphaPostIt < 0) alphaPostIt = 0f; } //spinning ship if (!shipIsMoving) { shipAngle += (gameTime.ElapsedGameTime.Milliseconds * 0.001f) % MathHelper.Pi * 2; shipDst.X = (int)(levelPositionOnMap[selectedIndex].X + 10 * Math.Cos(shipAngle) - shipSrc.Width / 2); shipDst.Y = (int)(levelPositionOnMap[selectedIndex].Y + 10 * Math.Sin(shipAngle) - shipSrc.Height / 2); //Post-it fade in if (aimedlevel == -1) { alphaPostIt += 0.1f; if (alphaPostIt > 1) alphaPostIt = 1f; } } #endregion }
public void Initialize() { //Fill game maps : can change during execution //************************************************************************************************ //LevelCount = 7; //Do not forget !!! //WorldCount = 5; if (TGPAContext.Instance.IsTrialMode == false) { //Level bonus test //maps = new World(new String[] { "level0.tgpa", "level1.tgpa", "level2_1.tgpa", "level2_2.tgpa", "level3_1.tgpa", "level3_2.tgpa", "level4_1.tgpa", "level4_2.tgpa", "level5.tgpa", "level_b1_2.tgpa", "level_b1_1.tgpa" }, // new int[] { 0, 1, 2, 2, 3, 3, 4, 4, 5, 6, 6 }); //LevelCount = 10; //WorldCount = 7; //Classic game config maps = new World(new String[] { "level0.tgpa", "level1.tgpa", "level2_1.tgpa", "level2_2.tgpa", "level3_1.tgpa", "level3_2.tgpa", "level4_1.tgpa", "level4_2.tgpa", "level5.tgpa" }, new int[] { 0, 1, 2, 2, 3, 3, 4, 4, 5 }); LevelCount = 9; WorldCount = 6; } else //Demo mode { maps = new World(new String[] { "level0.tgpa", "level1.tgpa" }, new int[] { 0, 1 }); WorldCount = 2; LevelCount = 2; } alphaColorForLevelBlinking = 0.5f; blinkingDelta = 0.01f; aimedlevel = -1; pointedIndex = -1; //Level pointed by mouse or next mevem focus = LevelSelectionScreenButton.Level; LoadOverview(selectedIndex); shipIsMoving = false; shipAngle = 0.0f; shipFlip = SpriteEffects.None; this.scoreType = ScoreType.Single; if (TGPAContext.Instance.Player2 != null) { this.scoreType = ScoreType.Coop; } //Difficulty launchLevel = false; difficultyChoosen = false; fadeoutAlpha = 0.9f; loadingLaunched = false; }
/// <summary> /// Level selection, launch game, come back, etc /// </summary> /// <param name="gameTime"></param> /// <param name="Game"></param> public void Update(GameTime gameTime) { if (loadingLaunched == true) { return; } float elapsedTime = (float)gameTime.ElapsedGameTime.TotalSeconds; alphaColorForLevelBlinking += blinkingDelta; if (alphaColorForLevelBlinking >= 1f) { alphaColorForLevelBlinking = 1f; blinkingDelta = -blinkingDelta; } else if (alphaColorForLevelBlinking <= 0f) { alphaColorForLevelBlinking = 0f; blinkingDelta = -blinkingDelta; } if (TGPAContext.Instance.InputManager.PlayerPressButtonBack(TGPAContext.Instance.Player1)) { if (launchLevel) { launchLevel = false; } else { TGPAContext.Instance.CurrentGameState = GameState.TitleScreen; return; } } #region Level launch if (launchLevel) { fadeoutAlpha += 0.01f; if (fadeoutAlpha > 0.75f) { fadeoutAlpha = 0.75f; } if (difficultyChoosen) { Thread t = new Thread(new ThreadStart( delegate() { TGPAContext.Instance.PrepareGame(); })); t.Start(); loadingLaunched = true; } else { difficultyListControl.Update(gameTime); } } else { fadeoutAlpha -= 0.01f; if (fadeoutAlpha < 0f) { fadeoutAlpha = 0f; } } #endregion #region Input management if ((!launchLevel) & (!shipIsMoving)) // controls are enabled only if the ship is on a point otherwise you have to wait { //PC Management if (TGPAContext.Instance.Player1.IsPlayingOnWindows()) { Rectangle mouseEnhancedDst = TGPAContext.Instance.MouseDst; mouseEnhancedDst.Inflate(10, 10); if (playDst.Intersects(mouseEnhancedDst)) { focus = LevelSelectionScreenButton.Play; if (TGPAContext.Instance.InputManager.PlayerPressButtonConfirm(TGPAContext.Instance.Player1)) { launchLevel = true; } } else if (backDst.Intersects(mouseEnhancedDst)) { focus = LevelSelectionScreenButton.Back; if (TGPAContext.Instance.InputManager.PlayerPressButtonConfirm(TGPAContext.Instance.Player1)) { TGPAContext.Instance.CurrentGameState = GameState.TitleScreen; } } else { //Click on a level = change selected index for (int i = 0; i < WorldCount; i++) { Rectangle levelDst = Rectangle.Empty; //The player need to have unlocked the level to display it if ((i <= TGPAContext.Instance.Saver.SaveData.LastLevel) && (i < WorldCount)) { Vector2 loc = levelPositionOnMap[i]; levelDst = new Rectangle( (int)loc.X - levelSrc.Width / 2, (int)loc.Y - levelSrc.Height / 2, levelSrc.Width, levelSrc.Height ); } pointedIndex = -1; if (levelDst.Intersects(mouseEnhancedDst)) { //if (Math.Abs(i - selectedIndex) > 1) break; //not allow player to select a too far point pointedIndex = i; if (TGPAContext.Instance.InputManager.PlayerPressButtonConfirm(TGPAContext.Instance.Player1)) { aimedlevel = i; } break; } } focus = LevelSelectionScreenButton.Level; } } #region Move with gamepad / Joystick bool goBack = false; bool goNext = false; Dictionary <ShipDirection, ShipAction> directionAndAction = availableShipDirectionByLevel[selectedIndex].Directions; if (TGPAContext.Instance.InputManager.PlayerGoLeft(TGPAContext.Instance.Player1) > 0f) { goBack = (directionAndAction[ShipDirection.Left] == ShipAction.GoBack); goNext = (directionAndAction[ShipDirection.Left] == ShipAction.GoNext); } if (TGPAContext.Instance.InputManager.PlayerGoRight(TGPAContext.Instance.Player1) > 0f) { goBack = (directionAndAction[ShipDirection.Right] == ShipAction.GoBack); goNext = (directionAndAction[ShipDirection.Right] == ShipAction.GoNext); } if (TGPAContext.Instance.InputManager.PlayerGoUp(TGPAContext.Instance.Player1) > 0f) { goBack = (directionAndAction[ShipDirection.Up] == ShipAction.GoBack); goNext = (directionAndAction[ShipDirection.Up] == ShipAction.GoNext); } if (TGPAContext.Instance.InputManager.PlayerGoDown(TGPAContext.Instance.Player1) > 0f) { goBack = (directionAndAction[ShipDirection.Down] == ShipAction.GoBack); goNext = (directionAndAction[ShipDirection.Down] == ShipAction.GoNext); } if (goNext) { //Go to next level if ((selectedIndex + 1 > TGPAContext.Instance.Saver.SaveData.LastLevel) || (selectedIndex + 1 >= WorldCount)) { aimedlevel = 0; } else { aimedlevel = selectedIndex + 1; } } else if (goBack) { if (selectedIndex - 1 < 0) { aimedlevel = TGPAContext.Instance.Saver.SaveData.LastLevel; if (aimedlevel >= WorldCount) { aimedlevel = WorldCount - 1; } } else { aimedlevel = selectedIndex - 1; } } #endregion if (TGPAContext.Instance.Player1.IsPlayingOnWindows() == false) { pointedIndex = aimedlevel; if (TGPAContext.Instance.InputManager.PlayerPressButtonConfirm(TGPAContext.Instance.Player1)) { launchLevel = true; } } //Both if (TGPAContext.Instance.InputManager.PlayerPressButtonSwitch(TGPAContext.Instance.Player1)) { this.scoreType = (this.scoreType == ScoreType.Single ? ScoreType.Coop : ScoreType.Single); } } #endregion #region Shipanimation Bezier if ((aimedlevel != -1) && (aimedlevel != selectedIndex) && (!shipIsMoving)) //if we have to move to the next destination { bezier_time = 0; shipIsMoving = true; duration = bezierDuration + (int)(Math.Sqrt(Math.Pow(levelPositionOnMap[selectedIndex].X - levelPositionOnMap[aimedlevel].X, 2) + Math.Pow(levelPositionOnMap[selectedIndex].Y - levelPositionOnMap[aimedlevel].Y, 2))) - (Math.Abs(aimedlevel - selectedIndex) - 1) * 200; } if ((shipIsMoving) && (aimedlevel != -1)) { bezier_time += gameTime.ElapsedGameTime.Milliseconds; Vector2 p1, p2, p3, p4; if (TGPAContext.Instance.Player1.IsPlayingOnWindows() == false) { if (selectedIndex < aimedlevel) //waypoints depend of the direction { p1 = levelPositionOnMap[selectedIndex]; p2 = pointsBezier[selectedIndex][0]; p3 = pointsBezier[selectedIndex][1]; p4 = levelPositionOnMap[selectedIndex + 1]; delta = 1; } else { p1 = levelPositionOnMap[selectedIndex]; p3 = pointsBezier[selectedIndex - 1][0]; p2 = pointsBezier[selectedIndex - 1][1]; p4 = levelPositionOnMap[selectedIndex - 1]; delta = -1; } } else { delta = aimedlevel - selectedIndex; p1 = levelPositionOnMap[selectedIndex]; p4 = levelPositionOnMap[aimedlevel]; if (selectedIndex < aimedlevel) { p2 = pointsBezier[selectedIndex + Math.Min(delta, 0)][0]; p3 = pointsBezier[selectedIndex + Math.Min(delta, 0)][1]; } else { p2 = pointsBezier[selectedIndex + Math.Min(delta, 0)][1]; p3 = pointsBezier[selectedIndex + Math.Min(delta, 0)][0]; } } float t = bezier_time / duration; //quadratic bezier equation need a parameter t, with 0<=t<=1 if (t <= 1) { shipDst.X = (int)((Math.Pow(1 - t, 3)) * p1.X + 3 * (Math.Pow(1 - t, 2)) * t * p2.X + 3 * (1 - t) * t * t * p3.X + t * t * t * p4.X) - shipSrc.Width / 2; shipDst.Y = (int)((Math.Pow(1 - t, 3)) * p1.Y + 3 * (Math.Pow(1 - t, 2)) * t * p2.Y + 3 * (1 - t) * t * t * p3.Y + t * t * t * p4.Y) - shipSrc.Height / 2; } else //if the journey is over { selectedIndex += delta; shipIsMoving = false; if (aimedlevel == selectedIndex) { aimedlevel = -1; LoadOverview(selectedIndex); } } //Post-it fade out alphaPostIt -= 0.05f; if (alphaPostIt < 0) { alphaPostIt = 0f; } } //spinning ship if (!shipIsMoving) { shipAngle += (gameTime.ElapsedGameTime.Milliseconds * 0.001f) % MathHelper.Pi * 2; shipDst.X = (int)(levelPositionOnMap[selectedIndex].X + 10 * Math.Cos(shipAngle) - shipSrc.Width / 2); shipDst.Y = (int)(levelPositionOnMap[selectedIndex].Y + 10 * Math.Sin(shipAngle) - shipSrc.Height / 2); //Post-it fade in if (aimedlevel == -1) { alphaPostIt += 0.1f; if (alphaPostIt > 1) { alphaPostIt = 1f; } } } #endregion }