/// <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 playerSprite.Update(); fire.Update(); var state = Keyboard.GetState(); int speed = 200; var viewMatrix = camera.GetViewMatrix(); int speedForSprites = (int)(speed * viewMatrix.Scale.X); if (state.IsKeyDown(Keys.A)) { position.X -= speed * gameTime.ElapsedGameTime.Milliseconds / 1000.0f; } if (state.IsKeyDown(Keys.D)) { position.X += speed * gameTime.ElapsedGameTime.Milliseconds / 1000.0f; } if (state.IsKeyDown(Keys.S)) { position.Y += speed * gameTime.ElapsedGameTime.Milliseconds / 1000.0f; } if (state.IsKeyDown(Keys.W)) { position.Y -= speed * gameTime.ElapsedGameTime.Milliseconds / 1000.0f; } fire.MoveUpdate(gameTime, speedForSprites); fire1.MoveUpdate(gameTime, speedForSprites); fire2.MoveUpdate(gameTime, speedForSprites); fire3.MoveUpdate(gameTime, speedForSprites); stone.MoveUpdate(gameTime, speedForSprites); camera.LookAt(position); mapRenderer.Update(map, gameTime); base.Update(gameTime); }
/// <summary> /// This is called when the game should draw itself. /// </summary> /// <param name="gameTime">Provides a snapshot of timing values.</param> protected override void Draw(GameTime gameTime) { GraphicsDevice.Clear(Color.CornflowerBlue); var viewMatrix = camera.GetViewMatrix(); camera.Position = camPos; camera.Rotation = rotation; camera.Zoom = zoom; if (CurrentGameState == GameState.MainMenu) { spriteBatch.Begin(); spriteBatch.Draw(background, mainframe, Color.White); //spriteBatch.DrawString(font, "press enter to start ", new Vector2(0, 0), Color.Black, 0, new Vector2(0, 0),2 , 0, 0); spriteBatch.DrawString(font, "press enter to start", new Vector2((GraphicsDevice.Viewport.Width / 2) - 150, 375), Color.Black); spriteBatch.End(); } else if (CurrentGameState == GameState.PlayingLvl1) { #region GameLvl1; spriteBatch.Begin(); spriteBatch.Draw(background, mainframe, Color.White); spriteBatch.DrawString(font, "Score: " + _hero.Score, new Vector2(750, 0), Color.Black); spriteBatch.DrawString(font, "Hero Life: x" + _hero.HeroLife, new Vector2(0, 0), Color.Black); spriteBatch.End(); spriteBatch.Begin(transformMatrix: viewMatrix); exit_Lvl1.Draw(spriteBatch); _hero.Draw(spriteBatch); fire.Draw(spriteBatch); foreach (coin coin in coins) { coin.Draw(spriteBatch); } foreach (Enemy enemy in _Enemys) { if (enemy.isAlive) { enemy.Draw(spriteBatch); } } foreach (BulletRight Bullet in bulletsright) { Bullet.Draw(spriteBatch); } foreach (BulletLeft Bullet in bulletsleft) { Bullet.Draw(spriteBatch); } map.Draw(spriteBatch); foreach (MovingTiles tile in movingTiles) { tile.Draw(spriteBatch); } spriteBatch.End(); #endregion } else if (CurrentGameState == GameState.PlayingSecretLvl) { spriteBatch.Begin(); spriteBatch.Draw(background, mainframe, Color.White); spriteBatch.DrawString(font, "Score: " + _hero.Score, new Vector2(750, 0), Color.Black); spriteBatch.DrawString(font, "Hero Life: x" + _hero.HeroLife, new Vector2(0, 0), Color.Black); spriteBatch.End(); spriteBatch.Begin(); exit_SecretLvl.Draw(spriteBatch); _hero.Draw(spriteBatch); SecretLvl.Draw(spriteBatch); foreach (coin coin in coins_SecretLvl) { coin.Draw(spriteBatch); } spriteBatch.End(); } else if (CurrentGameState == GameState.PlayingLvl2) { spriteBatch.Begin(); spriteBatch.Draw(background, mainframe, Color.White); spriteBatch.DrawString(font, "Score: " + _hero.Score, new Vector2(750, 0), Color.Black); spriteBatch.DrawString(font, "Hero Life: x" + _hero.HeroLife, new Vector2(0, 0), Color.Black); spriteBatch.End(); spriteBatch.Begin(transformMatrix: viewMatrix); _hero.Draw(spriteBatch); foreach (MovingTiles tile in movingTiles_Lvl2) { tile.Draw(spriteBatch); } foreach (Enemy enemy in _EnemysLvl2) { if (enemy.isAlive) { enemy.Draw(spriteBatch); } } foreach (BulletRight Bullet in bulletsright) { Bullet.Draw(spriteBatch); } foreach (BulletLeft Bullet in bulletsleft) { Bullet.Draw(spriteBatch); } foreach (BulletEnemy Bullet in bulletEnemy) { Bullet.Draw(spriteBatch); } foreach (coin coin in coins_Lvl2) { coin.Draw(spriteBatch); } if (damageEndBoss < 20) { endBoss.Draw(spriteBatch); } else { exit_Lvl2.Draw(spriteBatch); } foreach (Kanon kanon in Kannonen) { kanon.Draw(spriteBatch); } map_Lvl2.Draw(spriteBatch); spriteBatch.End(); } else if (CurrentGameState == GameState.Dead) { spriteBatch.Begin(); spriteBatch.Draw(background, mainframe, Color.White); spriteBatch.DrawString(font, "Game Over!", new Vector2(650, 200), Color.Black); spriteBatch.DrawString(font, "Your score: " + _hero.Score, new Vector2(650, 400), Color.Black); spriteBatch.End(); } else if (CurrentGameState == GameState.End) { spriteBatch.Begin(); spriteBatch.Draw(background, mainframe, Color.White); spriteBatch.DrawString(font, "Yes! You did it!", new Vector2(650, 200), Color.Black); spriteBatch.DrawString(font, "Your score: " + _hero.Score, new Vector2(650, 400), Color.Black); spriteBatch.End(); } base.Draw(gameTime); }