public override void Update(GameHandler gameHandler) //Check if the player is within a certain distance { this.screenPos = Camera.WorldToScreen(worldPos); this.villagerAnim.Update(gameHandler.gameTime); //drawWelcomeBox = false; if (this.worldPos.X - gameHandler.player.worldPos.X <= 50) { if (this.worldPos.Y - gameHandler.player.worldPos.Y <= 50) { if (openingBox == false) { drawWelcomeBox = true; openingBox = true; closingBox = false; welcomeBoxOpenAnimation.loops = 0; welcomeBoxCloseAnimation.loops = 0; } } else { closingBox = true; openingBox = false; } } else { closingBox = true; openingBox = false; } if (drawWelcomeBox) { if (openingBox) { if (welcomeBoxOpenAnimation.loops <= 0) { welcomeBoxOpenAnimation.Update(gameHandler.gameTime); } else { closingBox = true; } } else if (closingBox) { if (welcomeBoxCloseAnimation.loops <= 0) { welcomeBoxCloseAnimation.Update(gameHandler.gameTime); } else { closingBox = false; drawWelcomeBox = false; } } } }
public void Update(GameHandler gh) { InputHandler input = gh.inputHandler; if (input.keyboardState.IsKeyUp(Keys.A) && input.keyboardState_old.IsKeyDown(Keys.A)) { if (this.curFolder - 1 < 0) { this.curFolder = folders.Count() - 1; } else { this.curFolder--; } } if (input.keyboardState.IsKeyUp(Keys.D) && input.keyboardState_old.IsKeyDown(Keys.D)) { if (this.curFolder + 1 > folders.Count() - 1) { this.curFolder = 0; } else { this.curFolder++; } } folderArrow_Left.Update(gh.gameTime); folderArrow_Right.Update(gh.gameTime); expBar.Update(gh.gameTime.ElapsedGameTime.Milliseconds, gh.worldData.curExp); }
public override void Update(StateHandler sh, GameTime gameTime) { this.gameHandler.gameTime = gameTime; this.gameHandler.inputHandler.UpdateVars(Keyboard.GetState(), Mouse.GetState()); if (gameHandler.curSceneID == Scene.ID_OVERWORLD) { this.worldScene.Update(gameHandler); this.lastTickWasBattle = false; if (gameHandler.switchingToBattle) { this.worldScene.startBattle(this.gameHandler); if (this.worldScene.readyForBattle) { gameHandler.curSceneID = Scene.ID_BATTLE; } } } else if (gameHandler.curSceneID == Scene.ID_BATTLE) { if (this.lastTickWasBattle == false) { this.battleScene.startBattle(gameHandler.battle_enemyIDs, 0, 0, this.gameHandler); //Replace these zeroes with valus from a "getBattleStageDataFromID" method this.lastTickWasBattle = true; } this.battleScene.Update(this.gameHandler); if (gameHandler.switchingToOverworld) { this.battleScene.winBattle(this.gameHandler); this.worldScene.winBattle(); if (this.battleScene.readyForOverworld) { gameHandler.curSceneID = Scene.ID_OVERWORLD; this.worldScene.gameWorld.zones[this.worldScene.gameWorld.curZoneID].enemies.Remove(gameHandler.lastEncounteredEnemy); } } } //PLACEHOLDER if (gameHandler.inputHandler.keyboardState_old.IsKeyDown(Keys.Escape) && gameHandler.inputHandler.keyboardState.IsKeyUp(Keys.Escape)) { sh.setCurState(State.MENU); } //PLACEHOLDER mousePointer.Update(gameTime); }
public void Update(GameHandler gameHandler) { if (curBattleState == Fighter.STATE_IDLE) { this.curTimeMod = timeMod_slow; } else { this.curTimeMod = timeMod_normal; } this.fightTime = gameHandler.gameTime.ElapsedGameTime.Milliseconds * curTimeMod; switch (this.curBattleState) { case Fighter.STATE_IDLE: //This is the "selecting moves" part KeyboardState keyboardState = gameHandler.inputHandler.keyboardState; KeyboardState keyboardState_old = gameHandler.inputHandler.keyboardState_old; foreach (EnemyFighter enemy in enemies) { enemy.Update(fightTime, this.curBattleState); } player.Update(fightTime, this.curBattleState); if (!drawingFightWheel) { this.mainSelectionWheel.Update(gameHandler.inputHandler, gameHandler.gameTime); if (keyboardState_old.IsKeyDown(Keys.Space) && keyboardState.IsKeyUp(Keys.Space)) { if (!mainSelectionWheel.isRotating) { switch (mainSelectionWheel.curSelectedID) { case 0: //Attack //this.timeUntilFightState = 0; drawingFightWheel = true; selectingEnemy = false; enemySelected = false; break; case 1: //Item break; case 2: //Pass break; case 3: //Flee gameHandler.curSceneID = Scene.ID_OVERWORLD; gameHandler.ranFromBattle = true; break; } } } } else //This is the else that is when fight wheel is being drawn { if (selectingEnemy) { if (enemySelected) { //execute selected move this.timeUntilFightState = 10; this.drawingFightWheel = false; player.hasAttacked = false; } else { enemySelectorAnim.Update(fightTime); if (keyboardState_old.IsKeyDown(Keys.W) && keyboardState.IsKeyUp(Keys.W) || keyboardState_old.IsKeyDown(Keys.A) && keyboardState.IsKeyUp(Keys.A)) //If WA is used for going back { if (curEnemyHighlightIndex <= 0) { curEnemyHighlightIndex = enemies.Count() - 1; } else { curEnemyHighlightIndex--; } curEnemyHighlightID = /*aliveEnemyPositions[curEnemyHighlightIndex];*/ curEnemyHighlightIndex; } else if (keyboardState_old.IsKeyDown(Keys.S) && keyboardState.IsKeyUp(Keys.S) || keyboardState_old.IsKeyDown(Keys.D) && keyboardState.IsKeyUp(Keys.D)) //If SD is used for going up { if (curEnemyHighlightIndex >= enemies.Count() - 1) { curEnemyHighlightIndex = 0; } else { curEnemyHighlightIndex++; } curEnemyHighlightID = /*aliveEnemyPositions[curEnemyHighlightIndex];*/ curEnemyHighlightIndex; } else if (keyboardState_old.IsKeyDown(Keys.Space) && keyboardState.IsKeyUp(Keys.Space)) //If the spacebar is pressed { finalEnemySelectionID = curEnemyHighlightID; selectingEnemy = false; enemySelected = true; this.player.attackList[player.curAttackID].targetPos = enemyScreenPositions[finalEnemySelectionID]; doneSelecting = true; } } } else { this.fightWheel.Update(gameHandler.inputHandler, gameHandler.gameTime); if (keyboardState_old.IsKeyDown(Keys.Space) && keyboardState.IsKeyUp(Keys.Space)) { if (!fightWheel.isRotating) { selectingEnemy = true; } } } } this.timeUntilFightState -= gameHandler.gameTime.ElapsedGameTime.Milliseconds; if (this.timeUntilFightState <= 0 || doneSelecting) //This is the conditional for when the timer runs out or the player is done selecting { this.curBattleState = Fighter.STATE_FIGHT; doneSelecting = false; selectingEnemy = false; enemySelected = false; drawingFightWheel = false; this.player.hasAttacked = false; foreach (EnemyFighter enemy in enemies) { enemy.hasAttacked = false; } } break; case Fighter.STATE_FIGHT: //This is when the fighting takes place, and where health/mana is affected bool doneFighting = true; if (!player.hasAttacked) { player.isFighting = true; //Move updating player.attackList[player.curAttackID].UpdateMove(fightTime); // doneFighting = false; if (player.attackList[player.curAttackID].finished) { enemies[finalEnemySelectionID].curHealth -= gameHandler.worldData.stats[PlayerSaver.STAT_ATK]; if (enemies[finalEnemySelectionID].curHealth <= 0) { enemies.Remove(enemies[finalEnemySelectionID]); aliveEnemyPositions.Remove(finalEnemySelectionID); if (enemies.Count() <= 0) { int wonExp = (int)(EnemyData.expRewardVals[gameHandler.lastEncounteredEnemy.enemyID] * enemyTemplate.level * (new Random().Next(100, 110) / 100.0)); //times the amount of enemies too int wonMoney = (int)(EnemyData.moneyRewardVals[gameHandler.lastEncounteredEnemy.enemyID] * enemyTemplate.level * (new Random().Next(100, 110) / 100.0)); gameHandler.winBattle(wonExp, wonMoney); } else { curEnemyHighlightID = aliveEnemyPositions[0]; //this.finalEnemySelectionID = 0; } } //doneFighting = true; player.hasAttacked = true; player.isFighting = false; doneFighting = false; player.attackList[player.curAttackID].finished = false; } } else { } foreach (EnemyFighter enemy in enemies) { enemy.Update(fightTime, this.curBattleState); if (!enemy.hasAttacked) { //doneFighting = false; //This has to be on later, but its commented out so i can see what would happen after the enemies attack } } if (doneFighting) { this.curBattleState = Fighter.STATE_IDLE; this.timeUntilFightState = 8 * 1000; //All subsequent idle stages are 8 seconds, unless modified by an ability } break; case Fighter.STATE_FLEE: //This is the case dealing with fleeing the battle foreach (EnemyFighter enemy in enemies) { enemy.Update(fightTime, this.curBattleState); } break; } }