/// <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> protected override void Update(GameTime gameTime) { //Get keyboard state keystate = Keyboard.GetState(); //At Menu screen if (state == gamestate.menu) { //play "in-game" audio audioHomeInst.Volume = 0.5f; audioHomeInst.Play(); audioInGameInst.Stop(); audioCollisionInst.Stop(); audioGameLostInst.Stop(); audioScene2Inst.Stop(); audioVictoryInst.Stop(); // Allows the game to exit if ((keystate.IsKeyDown(Keys.Escape) == true) && (lastKeyState.IsKeyUp(Keys.Escape) == true)) this.Exit(); // Go to playing state if ((keystate.IsKeyDown(Keys.Space) == true) && (lastKeyState.IsKeyUp(Keys.Space) == true)) { state = gamestate.story1; //Load First Map MapState = gamemap.start; previousMapState = MapState; //Healthy. Default state of player Action.PlayerState = ActionHandler.CharacterStatus.Play; player.status = 6; //StartMap Load StartMap_Load(); } //get player to help menu if ((keystate.IsKeyDown(Keys.F1) == true) && (lastKeyState.IsKeyUp(Keys.F1) == true)) { state = gamestate.help; } } // allow player to quit help screen else if (state == gamestate.help) { if ((keystate.IsKeyDown(Keys.Escape) == true) && (lastKeyState.IsKeyUp(Keys.Escape) == true)) state = gamestate.menu; } else if (state == gamestate.story1) { player.CharacterUpdate(gameTime); player.HandleSourceRect(gameTime); if ((keystate.IsKeyDown(Keys.Space) == true) && (lastKeyState.IsKeyUp(Keys.Space) == true)) state = gamestate.play; } else if (state == gamestate.story2) { player.CharacterUpdate(gameTime); player.HandleSourceRect(gameTime); Zelda.ZeldaUpdate(gameTime); Zelda.HandleSourceRect(gameTime); if ((keystate.IsKeyDown(Keys.Space) == true) && (lastKeyState.IsKeyUp(Keys.Space) == true)) state = gamestate.play; } //At playing screen else if (state == gamestate.play) { // GO to Menu state if ((keystate.IsKeyDown(Keys.Escape) == true) && (lastKeyState.IsKeyUp(Keys.Escape) == true)) state = gamestate.menu; //Default state of Character Action.PlayerState = ActionHandler.CharacterStatus.Play; //Enemy and Player action has to be called here if (MapState == gamemap.lose) { audioInGameInst.Stop(); audioCollisionInst.Stop(); audioScene2Inst.Stop(); audioScene3Inst.Stop(); audioScene4Inst.Stop(); audioScene5Inst.Stop(); audioGameLostInst.Volume = 0.7f; audioGameLostInst.Play(); player.CharacterUpdate(gameTime); player.HandleSourceRect(gameTime); Zelda.ZeldaUpdate(gameTime); Zelda.HandleSourceRect(gameTime); } else if (MapState == gamemap.win) { audioInGameInst.Stop(); audioCollisionInst.Stop(); audioScene2Inst.Stop(); audioScene3Inst.Stop(); audioScene4Inst.Stop(); audioScene5Inst.Stop(); audioVictoryInst.Volume = 0.7f; audioVictoryInst.Play(); player.CharacterUpdate(gameTime); player.HandleSourceRect(gameTime); Zelda.ZeldaUpdate(gameTime); Zelda.HandleSourceRect(gameTime); player.status = 5;//Indicate WIN Zelda.status = 5; } //First(default) map setting else if (MapState == gamemap.start) { audioHomeInst.Pause(); audioInGameInst.Volume = 0.7f; audioInGameInst.Play(); //StartMap Update CollisionUpdate(gameTime); //This means Move to Next map //Replace Objects for the New Map if (Action.PlayerState == ActionHandler.CharacterStatus.Next) { MapState = gamemap.second; //SecondMap Loading SecondMap_Load(); } //Lose killed by Enemy else if (Action.PlayerState == ActionHandler.CharacterStatus.Lose) MapState = gamemap.lose; } //Second Map basically same as First except Enamy2 added here else if (MapState == gamemap.second) { audioScene2Inst.Volume = 0.5f; audioScene2Inst.Play(); audioInGameInst.Stop(); audioHomeInst.Stop(); //Second Map Update CollisionUpdate(gameTime); if (Action.PlayerState == ActionHandler.CharacterStatus.Lose) MapState = gamemap.lose; else if (Action.PlayerState == ActionHandler.CharacterStatus.Next) { previousMapState = MapState; MapState = gamemap.third; //Final Map loading ThirdMap_Load(); } } else if (MapState == gamemap.third) { audioScene3Inst.Volume = 0.5f; audioScene3Inst.Play(); audioScene2Inst.Stop(); audioHomeInst.Stop(); //Third Map Collision and Update CollisionUpdate(gameTime); if (Action.PlayerState == ActionHandler.CharacterStatus.Save) { previousMapState = MapState; MapState = gamemap.Escape1; //Escape map loaded state = gamestate.story2; player.status = 6;//Stop moving for story Zelda.status = 5; Escape1_Load(); } else if (Action.PlayerState == ActionHandler.CharacterStatus.Lose) MapState = gamemap.lose; } else if (MapState == gamemap.Escape1) { audioScene4Inst.Volume = 0.5f; audioScene4Inst.Play(); audioScene3Inst.Stop(); audioHomeInst.Stop(); //Escape1 Map Collision and Update CollisionUpdate(gameTime); if (Action.PlayerState == ActionHandler.CharacterStatus.Next) { previousMapState = MapState; MapState = gamemap.Escape2; Escape2_Load(); } else if (Action.PlayerState == ActionHandler.CharacterStatus.Lose) MapState = gamemap.lose; } else if (MapState == gamemap.Escape2) { audioScene5Inst.Volume = 0.5f; audioScene5Inst.Play(); audioScene4Inst.Stop(); audioHomeInst.Stop(); //Escape2 Map Collision and Update CollisionUpdate(gameTime); if (Action.PlayerState == ActionHandler.CharacterStatus.Next) { MapState = gamemap.win; player.updatePos(new Vector2(450, 100)); Zelda.updatePos(new Vector2(410, 100)); } else if (Action.PlayerState == ActionHandler.CharacterStatus.Lose) MapState = gamemap.lose; } } lastKeyState = keystate; base.Update(gameTime); }
/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { // TODO: Add your initialization logic here //Game starts with the menu state = gamestate.menu; //Game play starts with start map MapState = gamemap.start; previousMapState = MapState; //Player that can move around player = new Character(); //ID number 0 indicate character that is only one exist. player.SpriteID = 0; //ID number 2xx indicate Enemy Enemy1 = new EnemyCharacter(); Enemy1.SpriteID = 201; Dragon1 = new Dragon(); Dragon1.SpriteID = 202; Enemy2 = new EnemyCharacter(); Enemy2.SpriteID = 203; Enemy3 = new EnemyCharacter(); Enemy3.SpriteID = 204; Enemy4 = new EnemyCharacter(); Enemy4.SpriteID = 205; //ID number 1 indicate PrincessZelda Zelda = new PrincessZelda(); Zelda.SpriteID = 1; //Backgrounds menu = new Sprite(); help = new Sprite(); BG0 = new Sprite(); Blood = new Sprite(); Thanks = new Sprite(); Story1 = new Sprite(); Story2 = new Sprite(); //ID 9xx indicate non object sprite menu.SpriteID = 901; //ID 1xx indicate stationary object tree1 = new Sprite(101); tree2 = new Sprite(102); tree3 = new Sprite(103); tree4 = new Sprite(104); tree5 = new Sprite(105); //ID 5xx indicate Key acition abject that cause some action Arrow = new Sprite(501); //Action Handling including Collision Detection and EnemySight Action = new Collision(); base.Initialize(); }