Example #1
0
        /// <summary>
        /// Update the entity. This is usually performed in the gameloop
        /// </summary>
        /// <param name="inputManager">The input manager</param>
        /// <param name="gameTime">The current game time</param>
        public override void Update(InputManager inputManager, GameTime gameTime)
        {
            Animation.Position = Position;
            Animation.Update(gameTime);

            Move(CurrentSpeed.X, CurrentSpeed.Y);
        }
Example #2
0
 /// <summary>
 /// Update the ship on the game loop
 /// </summary>
 /// <param name="inputManager"></param>
 /// <param name="gameTime"></param>
 public override void Update(InputManager inputManager, GameTime gameTime)
 {
     this.gameTime = gameTime;
     Move(speed.X, speed.Y);
     Move(0, random.Next(-1, 1));
     var vec = new Vector2((float)random.Next(-(int)MaxSpeed, (int)MaxSpeed), (float)random.Next(-(int)MaxSpeed, (int)MaxSpeed));
     vec.Normalize();
     FireBullet(vec);
     base.Update(inputManager, gameTime);
 }
Example #3
0
        /// <summary>
        /// Handle updates in the gameloop for all entities
        /// </summary>
        /// <param name="inputManager"></param>
        /// <param name="gameTime"></param>
        public void Update(InputManager inputManager, GameTime gameTime)
        {
            /// We need a copy, because the list may change while iterating
            /// over the entities
            var copy = entities.ToList();
            foreach (var entity in copy)
            {
                entity.Update(inputManager, gameTime);
            }

            CheckCollisions(animatedEntities);
        }
Example #4
0
        /// <summary>
        /// Update the entity. This is usually performed in the gameloop
        /// </summary>
        /// <param name="inputManager"></param>
        /// <param name="gameTime"></param>
        public override void Update(InputManager inputManager, GameTime gameTime)
        {
            /// Handle controls
            var keyboard = inputManager.CurrentKeyboardState;
            var gamepad = inputManager.CurrentGamePadState;

            if (TitlescreenStatus == Entities.TitlescreenStatus.Start)
            {
                if (keyboard.IsKeyDown(Keys.F1) ||
                    gamepad.Buttons.Y == ButtonState.Pressed)
                {
                    if (gamepad.Buttons.Y == ButtonState.Pressed)
                    {
                        isGamepad = true;
                    }
                    TitlescreenStatus = TitlescreenStatus.Help;
                }
                else if (keyboard.IsKeyDown(Keys.Space) ||
                    keyboard.IsKeyDown(Keys.Enter) ||
                    gamepad.Buttons.A == ButtonState.Pressed)
                {
                    if (Player.Alive)
                    {
                        /// Resume game
                        Visible = false;
                    }
                    else
                    {
                        /// Start new game
                        Visible = false;
                        NewGameRequested = true;
                    }
                }
                else if (inputManager.WasKeyPressed(Keys.Escape) ||
                    inputManager.WasButtonPressed(Buttons.Back))
                {
                    ExitRequested = true;
                }
            }
            else
            {
                if (inputManager.WasKeyPressed(Keys.Escape) ||
                    inputManager.WasButtonPressed(Buttons.Back))
                {
                    TitlescreenStatus = TitlescreenStatus.Start;
                }
            }

            base.Update(inputManager, gameTime);
        }
Example #5
0
        /// <summary>
        /// Initialize the new game. Creates any entities that need to be created
        /// in order to run the game.
        /// </summary>
        private void NewGame()
        {
            if (entityManager == null)
            {
                /// Create a new entity manager.
                entityManager = new EntityManager(Content, GraphicsDevice);
            }
            else
            {
                entityManager.Clear();
            }

            if (inputManager == null)
            {
                inputManager = new InputManager();
            }
            /// Create a new player.
            player = new Player(entityManager);
            if (asteroidManager == null)
            {
                asteroidManager = new GameManager(entityManager, player);
            }
            else
            {
                asteroidManager.Clear();
            }
            if (titleScreen == null)
            {
                /// Create a new title screen
                titleScreen = new Titlescreen(player);
            }
            else
            {
                titleScreen.Player = player;
            }
            entityManager.Add(new Background());
            entityManager.Add(player);
            entityManager.Add(new ScoreDisplay(new List<Player>(new Player[] { player })));
        }
Example #6
0
 /// <summary>
 /// Update the entity. This is usually performed in the gameloop
 /// </summary>
 /// <param name="inputManager"></param>
 /// <param name="gameTime"></param>
 public override void Update(InputManager inputManager, GameTime gameTime)
 {
     Rotate(5.0f);
     if (!Animation.ShouldDraw)
     {
         entityManager.Remove(this);
     }
     base.Update(inputManager, gameTime);
 }
Example #7
0
 /// <summary>
 /// Handle update on gameloop
 /// </summary>
 /// <param name="inputManager">The Input manager.</param>
 /// <param name="gameTime">The current game time.</param>
 public override void Update(InputManager inputManager, GameTime gameTime)
 {
     Rotate(RotationSpeed);
     base.Update(inputManager, gameTime);
 }
Example #8
0
        /// <summary>
        /// Update. This is where we handle the controls.
        /// </summary>
        /// <param name="inputManager"></param>
        /// <param name="gameTime"></param>
        public override void Update(InputManager inputManager, GameTime gameTime)
        {
            this.gameTime = gameTime;
            /// Handle controls
            var keyboard = inputManager.CurrentKeyboardState;
            var gamepad = inputManager.CurrentGamePadState;
            /// If the user is pressing left on the DPad or keyboard
            if (keyboard.IsKeyDown(Keys.Left) ||
                gamepad.DPad.Left == ButtonState.Pressed)
            {
                Rotate(-RotationSpeed);
            }
            /// If the user is pressing right on the DPad or keyboard
            else if (keyboard.IsKeyDown(Keys.Right) ||
                gamepad.DPad.Right == ButtonState.Pressed)
            {
                Rotate(RotationSpeed);
            }
            /// If the user is pressing up on the DPad or keyboard
            if (keyboard.IsKeyDown(Keys.Up) ||
                gamepad.DPad.Up == ButtonState.Pressed)
            {
                Forward();
            }
            else
            {
                /// Handle Deccelerate...
                CurrentSpeed = new Vector2(CurrentSpeed.X / 1.05f, CurrentSpeed.Y / 1.05f);
            }

            base.Update(inputManager, gameTime);

            /// Handle Hyperspace. The condition is that the user can't hold
            /// down a hyperspace.
            if (inputManager.WasKeyPressed(Keys.H) ||
                inputManager.WasButtonPressed(Buttons.B) &&
                (gameTime.TotalGameTime.TotalSeconds - lastHyperspaceTime) > hyperspaceTime)
            {
                var random = new Random();
                float x = random.Next(GraphicsDevice.Viewport.X, GraphicsDevice.Viewport.Width);
                float y = random.Next(GraphicsDevice.Viewport.Y, GraphicsDevice.Viewport.Height);
                Position = new Vector2(x, y);
                lastHyperspaceTime = gameTime.TotalGameTime.TotalSeconds;
            }

            /// Fire bullet
            if (keyboard.IsKeyDown(Keys.Space) ||
                gamepad.Buttons.A == ButtonState.Pressed)
            {
                FireBullet(new Vector2(5.0f, 5.0f));
            }
        }
Example #9
0
 /// <summary>
 /// Update the bullet on the game loop
 /// </summary>
 /// <param name="inputManager">The input manager.</param>
 /// <param name="gameTime">The current game time.</param>
 public override void Update(InputManager inputManager, GameTime gameTime)
 {
     Forward(speed.X, speed.Y);
     base.Update(inputManager, gameTime);
 }
Example #10
0
 /// <summary>
 /// Update on each game loop
 /// </summary>
 /// <param name="inputManager"></param>
 /// <param name="gameTime"></param>
 public abstract void Update(InputManager inputManager, GameTime gameTime);
Example #11
0
 /// <summary>
 /// Update on each game loop
 /// </summary>
 /// <param name="inputManager"></param>
 /// <param name="gameTime"></param>
 public override void Update(InputManager inputManager, GameTime gameTime)
 {
 }