void ChoosePlayer(GameTime gameTime) { if (playerMokepon == null) { if (currentCanvas == null) { bool lost = true; foreach (var pok in player.Mokepons) { if (pok.HP > 0) { lost = false; } } if (lost) { currentState = BattleState.LOST; return; } currentCanvas = new PlayerChooseMokeponCanvas(player.Mokepons); currentCanvas.LoadContent(); } currentCanvas.Update(gameTime); if ((currentCanvas as PlayerChooseMokeponCanvas).MokeponChosen == true) { playerMokepon = player.Mokepons[(currentCanvas as PlayerChooseMokeponCanvas).Choice]; currentCanvas.UnloadContent(); currentCanvas = null; GC.Collect(); Dialogues.AddText(string.Format("Go! {0}!", playerMokepon.Name)); Dialogues.DisplayNext(); playerMokeponImage = new Image("Mokepons/" + playerMokepon.DefaultName); playerMokeponImage.LoadContent(); playerMokeponImage.MoveMid(new Vector2(Globals.ScreenWidth / 4, 3 * Globals.ScreenHeight / 4 - 100)); PulseEffect pulse = new PulseEffect(2f, 1.5); playerMokeponImage.AddEffect("PulseEffect", ref pulse); playerMokeponImage.ActivateEffect("PulseEffect"); playerStats = new MokeponBattleStats(ref playerMokepon, new Vector2(500, 400), true); playerStats.LoadContent(); wait = 3.0; SwitchState(BattleState.CHOOSE_ACTION); return; } } else { SwitchState(BattleState.CHOOSE_ACTION); return; } }
/// <summary> /// Loads content for the active screen. /// </summary> /// <param name="contentManager">Content manager object.</param> public void LoadContent(ContentManager contentManager) { // Set content manager reference this.contentManager = contentManager; // Create texture for screen transitions Texture2D transitionTexture = new Texture2D(graphicsDevice, graphicsDevice.Viewport.Width, graphicsDevice.Viewport.Height, false, SurfaceFormat.Color); Color[] colors = new Color[transitionTexture.Width * transitionTexture.Height]; for (int i = 0; i < colors.Length; i++) { colors[i] = Color.Black; } transitionTexture.SetData(colors); transitionTextureImage = new Image(transitionTexture); transitionTextureImage.LoadContent(contentManager); transitionTextureImage.Alpha = 0.0f; // Pulse effect used for fading during screen transitions PulseEffect pulseEffect = new PulseEffect(); pulseEffect.MaxAlphaReached += transition_FadeFull; pulseEffect.MinAlphaReached += transition_Done; pulseEffect.PulseSpeed = 2.0f; transitionTextureImage.AddEffect <PulseEffect>(ref pulseEffect, "PulseEffect"); transitionTextureImage.DeactivateEffect("PulseEffect"); // Load content for the current screen if (currentScreen != null) { currentScreen.LoadContent(contentManager); } }
void ChooseEnemy(GameTime gameTime) { if (enemyMokepon == null) { if (enemy.Mokepons.Count == 0) { SwitchState(BattleState.WON); return; } foreach (var mok in enemy.Mokepons) { if (mok.HP > 0) { enemyMokepon = mok; break; } } Dialogues.AddText(string.Format(enemy.MokeponChoiceText, enemyMokepon.Name)); Dialogues.DisplayNext(); enemyMokeponImage = new Image("Mokepons/" + enemyMokepon.Name); enemyMokeponImage.LoadContent(); enemyMokeponImage.MoveMid(new Vector2(3 * Globals.ScreenWidth / 4, Globals.ScreenHeight / 4)); PulseEffect pulse = new PulseEffect(2f, 1.5); enemyMokeponImage.AddEffect("PulseEffect", ref pulse); enemyMokeponImage.ActivateEffect("PulseEffect"); enemyStats = new MokeponBattleStats(ref enemyMokepon, new Vector2(450, 100)); enemyStats.LoadContent(); wait = 3.0; } SwitchState(BattleState.PLAYER_CHOICE); }
void ChooseAction(GameTime gameTime) { if (!MoveChosen) { if (currentCanvas == null) { Dialogues.AddText("What will " + playerMokepon.Name + " do?"); Dialogues.DisplayNext(); currentCanvas = new PlayerActionChoiceCanvas(player, playerMokepon); currentCanvas.LoadContent(); } currentCanvas.Update(gameTime); } else { if (currentCanvas.GetType() == typeof(PlayerActionChoiceCanvas)) { currentCanvas.UnloadContent(); currentCanvas = null; GC.Collect(); } if (PlayerMove == "Run") { foreach (var pok in player.Mokepons) { pok.HP = 0; } Dialogues.AddText(player.Name + " has fled from the battle!"); Dialogues.AddText(player.Name + "\'s Mokepons have fainted!"); Dialogues.DisplayNext(); wait = 3.0; SwitchState(BattleState.LOST); return; } else if (PlayerMove == "SwitchMokepon") { if (currentCanvas == null) { currentCanvas = new PlayerChooseMokeponCanvas(player.Mokepons, playerMokepon); currentCanvas.LoadContent(); } if ((currentCanvas as PlayerChooseMokeponCanvas).MokeponChosen == false) { currentCanvas.Update(gameTime); } if ((currentCanvas as PlayerChooseMokeponCanvas).MokeponChosen == true) { if (playerMokepon != null) { hideCanvas = true; Dialogues.AddText(playerMokepon.Name + ", go back!"); Dialogues.DisplayNext(); playerMokepon = null; playerMokeponImage.UnloadContent(); playerMokeponImage = null; playerStats.UnloadContent(); playerStats = null; GC.Collect(); wait = 3.0; return; } playerMokepon = player.Mokepons[(currentCanvas as PlayerChooseMokeponCanvas).Choice]; currentCanvas.UnloadContent(); currentCanvas = null; hideCanvas = false; GC.Collect(); playerMokeponImage = new Image("Mokepons/" + playerMokepon.DefaultName); playerMokeponImage.LoadContent(); playerMokeponImage.MoveMid(new Vector2(Globals.ScreenWidth / 4, 3 * Globals.ScreenHeight / 4 - 100)); PulseEffect pulse = new PulseEffect(2f, 1.5); playerMokeponImage.AddEffect("PulseEffect", ref pulse); playerMokeponImage.ActivateEffect("PulseEffect"); playerStats = new MokeponBattleStats(ref playerMokepon, new Vector2(500, 400), true); playerStats.LoadContent(); Dialogues.AddText(string.Format("Go! {0}!", playerMokepon.Name)); Dialogues.DisplayNext(); wait = 3.0; EnemyMove = EnemyAI.ChooseMove(enemyMokepon, playerMokepon, enemy.AILevel); enemyAbility = (Ability)Activator.CreateInstance(Type.GetType("MokeponGame.Gameplay.Abilities." + EnemyMove)); SwitchState(BattleState.USE_ABILITIES); return; } } else if (PlayerMove == "Wait") { Dialogues.AddText(playerMokepon.Name + " decides to wait!"); Dialogues.DisplayNext(); wait = 3.0; EnemyMove = EnemyAI.ChooseMove(enemyMokepon, playerMokepon, enemy.AILevel); enemyAbility = (Ability)Activator.CreateInstance(Type.GetType("MokeponGame.Gameplay.Abilities." + EnemyMove)); SwitchState(BattleState.USE_ABILITIES); return; } else if (PlayerMove.StartsWith("Item_")) { string[] strings = PlayerMove.Split('_'); EnemyMove = EnemyAI.ChooseMove(enemyMokepon, playerMokepon, enemy.AILevel); enemyAbility = (Ability)Activator.CreateInstance(Type.GetType("MokeponGame.Gameplay.Abilities." + EnemyMove)); playerAbility = (Ability)Activator.CreateInstance(Type.GetType("MokeponGame.Gameplay.Abilities." + strings[2])); playerAbility.UsedWithItem = true; playerAbility.ItemName = strings[1]; SwitchState(BattleState.USE_ABILITIES); return; } else { EnemyMove = EnemyAI.ChooseMove(enemyMokepon, playerMokepon, enemy.AILevel); enemyAbility = (Ability)Activator.CreateInstance(Type.GetType("MokeponGame.Gameplay.Abilities." + EnemyMove.Replace(" ", ""))); playerAbility = (Ability)Activator.CreateInstance(Type.GetType("MokeponGame.Gameplay.Abilities." + PlayerMove.Replace(" ", ""))); SwitchState(BattleState.USE_ABILITIES); return; } } }