/// <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) { //if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState().IsKeyDown(Keys.Escape)) // Exit(); // TODO: Add your update logic here foreach (MusicController temp in GameVariables.layerList) { temp.Layer.Play(); } previousKbState = kbState; kbState = Keyboard.GetState(); if (g == GameState.Menu) { GameVariables.menuMusicInstance.Play(); moveCamera.viewMatrix = moveCamera.GetTransform(player, width, height); if (SingleKeyPress(Keys.Enter, kbState, previousKbState)) { GameVariables.interfaceStartInstance.Play(); GameVariables.menuMusicInstance.Stop(); g = GameState.Level; world.levels[world.currentLevel].levelTimer.Start(); } MuteSoundEffects(); MuteMusic(); if (SingleKeyPress(Keys.F, kbState, previousKbState)) { graphics.ToggleFullScreen(); } } if (g == GameState.Pause) { FadeLayers(); if (SingleKeyPress(Keys.R, kbState, previousKbState)) { ResetLevel(); GameVariables.interfacePauseInstance.Play(); g = prevState; paused = false; } if (SingleKeyPress(Keys.F, kbState, previousKbState)) { graphics.ToggleFullScreen(); } MuteSoundEffects(); MuteMusic(); if (SingleKeyPress(Keys.Q, kbState, previousKbState)) { Exit(); } } if (g == GameState.Dead) { foreach (MusicController temp in GameVariables.layerList) { temp.Layer.Stop(); } if (GameVariables.deathMusicInstance.State == SoundState.Stopped) { GameVariables.deathMusicInstance.Play(); } if (SingleKeyPress(Keys.R, kbState, previousKbState)) { ResetLevel(); g = GameState.Level; GameVariables.interfaceStartInstance.Play(); GameVariables.deathMusicInstance.Stop(); } } if (g == GameState.Victory) { world.levels[world.currentLevel].levelTimer.Stop(); if (SingleKeyPress(Keys.Enter, kbState, previousKbState)) { g = GameState.Level; player.victory = false; GameVariables.interfaceStartInstance.Play(); world.levels[world.currentLevel].levelTimer.Start(); } if (SingleKeyPress(Keys.F, kbState, previousKbState)) { graphics.ToggleFullScreen(); } MuteSoundEffects(); MuteMusic(); } if (g == GameState.Level) { FadeLayers(); player.Movement(kbState, previousKbState, gameTime, falling); player.Collisions(kbState, previousKbState, world, s, Content, robotMovement); foreach (Enemy enemy in world.levels[world.currentLevel].enemies) { if (enemy.alive) { enemy.Movement(gameTime); enemy.Collisions(world.levels[world.currentLevel].objects, kbState, previousKbState, world); } } if (player.IsDead()) { foreach (SoundEffectInstance temp in GameVariables.GameSounds) { if (temp != GameVariables.deathMusicInstance && temp != GameVariables.deathSoundInstance) { temp.Stop(); } } g = GameState.Dead; } if (player.world != null && player.world != world) { if (player.victory) { tempTime = world.levels[world.currentLevel].levelTimer.Elapsed.Seconds; tempDeaths = world.levels[world.currentLevel].deathCount; player.energy = 280; } world = player.world; world.LoadWorld(); world.levels[world.currentLevel].levelTimer.Start(); } if (player.victory) { g = GameState.Victory; } moveCamera.viewMatrix = moveCamera.GetTransform(player, width, height); gameHUD.Check(); player.Update(gameTime); } if (SingleKeyPress(Keys.P, kbState, previousKbState) && g != GameState.Menu && g != GameState.Victory && g != GameState.Dead) { foreach (SoundEffectInstance temp in GameVariables.GameSounds) { if (temp != GameVariables.layer1Instance && temp != GameVariables.layer2Instance && temp != GameVariables.layer3Instance && temp != GameVariables.layer4Instance && temp != GameVariables.layer5Instance && temp != GameVariables.layer6Instance) { temp.Stop(); } } GameVariables.interfacePauseInstance.Play(); if (!paused) { prevState = g; world.levels[world.currentLevel].levelTimer.Stop(); g = GameState.Pause; paused = true; } else { g = prevState; GameVariables.interfacePauseInstance.Play(); world.levels[world.currentLevel].levelTimer.Start(); paused = false; } } //if(g == GameState.Level && world.levels[world.currentLevel].HudInfo != null) //{ // gameHUD.checkPlayerY(); //} base.Update(gameTime); }
/// <summary> /// LoadContent will be called once per game and is the place to load /// all of your content. /// </summary protected override void LoadContent() { // Create a new SpriteBatch, which can be used to draw textures. spriteBatch = new SpriteBatch(GraphicsDevice); player.LoadContent(Content); GameVariables.LoadContentFiles(Content); // TODO: use this.Content to load your game content here pauseBack = Content.Load<Texture2D>(GameVariables.imgWall); gameFont = Content.Load<SpriteFont>(GameVariables.gFont); gameFont2 = Content.Load<SpriteFont>(GameVariables.gFont2); deathScreen = Content.Load<Texture2D>(@"ContentFiles/Images/Sprites/death"); victoryScreen = Content.Load<Texture2D>(@"ContentFiles/Images/Sprites/Victory"); menu = new AnimatedTexture(Content, @"ContentFiles/Images/Sprites/fronta", 5, .05f); world = new World(GameVariables.menuWorld, s, player, Content); // Menu "world" world.LoadWorld(); player.ObjPos.X = world.levels["main.txt"].playerSpawn.X; player.ObjPos.Y = world.levels["main.txt"].playerSpawn.Y; world.currentLevel = "main.txt"; moveCamera = new Camera(player, GraphicsDevice); gameHUD = new Hud((int)moveCamera.camX + 20, (int)moveCamera.camY + 20, 300, 45, spriteBatch, player, moveCamera, world.levels[world.currentLevel]); falling = new SoundLoop(GameVariables.fallingLoopInstance1, 700, GameVariables.fallingLoopInstance2, 700, GameVariables.fallingAccelerationInstance, 850); robotMovement = new SoundLoop(GameVariables.robotSoundInstance1, 690, GameVariables.robotSoundInstance2, 690); gameHUD.backt = Content.Load<Texture2D>(@"ContentFiles/Images/Sprites/back"); gameHUD.undert = Content.Load<Texture2D>(@"ContentFiles/Images/Sprites/grey"); gameHUD.energyt = Content.Load<Texture2D>(@"ContentFiles/Images/Sprites/energy"); }