public override void Update(GameTime gameTime, InputManager input) { handleInput(input); if (_primaryGadget.Active) gameTime = new GameTime(gameTime.TotalGameTime, TimeSpan.FromSeconds((float)gameTime.ElapsedGameTime.TotalSeconds / 2)); _blackHole.ApplyToUnit(_player, gameTime); _player.Update(gameTime); _primaryWeapon.Update(gameTime); _secondaryWeapon.Update(gameTime); _primaryGadget.Update(gameTime); _blackHole.Update(gameTime); for (int i = 0; i < _waves.Length; i++) { _waves[i].Update(gameTime, _player, _blackHole, _primaryWeapon, _secondaryWeapon); //check cross-wave collisions if (_waves[i].Active) { for (int j = i + 1; j < _waves.Length; j++) { _waves[i].CheckAndApplyCollisions(_waves[j]); } } } }
/// <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() { _inputManager = new InputManager(); //Set so units stay in screen bounds PhysicalUnit.ScreenWidth = graphics.GraphicsDevice.Viewport.Width; PhysicalUnit.ScreenHeight = graphics.GraphicsDevice.Viewport.Height; Weapon.ScreenBounds = graphics.GraphicsDevice.Viewport.Bounds; base.Initialize(); }
public override void Update(GameTime gameTime, InputManager input, InventoryManager im) { _mousePos = input.MouseLocation; input.SetCameraOffset(_camera.Position); handleInput(input); _camera.Update(gameTime, _player.Position); //if player is outside static area rectangle, call update on camera to update position of camera until //the player is in the static area rectangle or the camera reaches the _levelbounds, in which case, //the camera does not move in that direction (locks) /* if ((_player.HitRect.Bottom > _cameraLock.Bottom && _player.HitRect.Top < _cameraLock.Top && _player.HitRect.Right < _cameraLock.Right && _player.HitRect.Left > _cameraLock.Left) && (player is in level bounds) { * _camera.Update(gameTime); * _cameraLock.X = (int)(_camera.position.X + (_camera.getViewportWidth() * 0.2)); * _cameraLock.Y = (int)(_camera.position.Y + (_camera.getViewportHeight() * 0.2)); * }*/ if (_timeSlowed) gameTime = new GameTime(gameTime.TotalGameTime, TimeSpan.FromSeconds((float)gameTime.ElapsedGameTime.TotalSeconds / 2)); if (_blackHole.State == BlackHole.BlackHoleState.Pulling) { _blackHole.ApplyToUnit(_player, gameTime); } _player.Update(gameTime, _levelBounds); _primaryGadget.Update(gameTime); _blackHole.Update(gameTime); if (_blackHole.State == BlackHole.BlackHoleState.Overdrive) { foreach (Wave w in _waves) { w.SpawnEnable = false; } foreach (Unicorn u in _unicorns) { u.SpawnEnable = false; } } for (int i = 0; i < _waves.Length; i++) { _waves[i].Update(gameTime, _player, _blackHole, _primaryWeapon, _secondaryWeapon, _inventoryManager, _unicorns); //check cross-wave collisions if (_waves[i].Active) { for (int j = i + 1; j < _waves.Length; j++) { _waves[i].CheckAndApplyCollisions(_waves[j]); } } } for (int i = 0; i < _unicorns.Length; i++) { _unicorns[i].Update(gameTime, _levelBounds, _blackHole.Position, _player.Position, _player.HitRect); _unicorns[i].CheckAndApplyCollision(_player, gameTime); _blackHole.TryEatUnicorn(_unicorns[i], gameTime); for (int j = 0; j < _foodCarts.Length; j++) { _unicorns[i].CheckAndApplyCollision(_foodCarts[j], gameTime); } } for (int i = 0; i < _foodCarts.Length; i++) { _foodCarts[i].Update(gameTime, _levelBounds, _blackHole.Position); _primaryWeapon.CheckAndApplyCollision(_foodCarts[i], gameTime.ElapsedGameTime); _secondaryWeapon.CheckAndApplyCollision(_foodCarts[i], gameTime.ElapsedGameTime); _inventoryManager.CheckCollisions(gameTime, _foodCarts[i]); _blackHole.ApplyToUnit(_foodCarts[i], gameTime); } //Update Weapons _primaryWeapon.Update(gameTime); _secondaryWeapon.Update(gameTime); //update all items _inventoryManager.Update(gameTime, input); }
private void handleSwap(InputManager input) { int slotSelected = input.SelectItemNum; if (slotSelected >= 0) { _item = _slots[slotSelected]; _currentSlot = slotSelected; } else if (input.fCycle) { //Cycle items forward if (_currentSlot == 5) { _currentSlot = 0; _item = _slots[0]; } _currentSlot = _currentSlot + 1; _item = _slots[_currentSlot]; } else if (input.bCycle) { //Cycle items backwards if (_currentSlot == 0) { _currentSlot = 5; _item = _slots[5]; } _currentSlot = _currentSlot + 1; _item = _slots[_currentSlot]; } }
//Runs often public void Update(GameTime gameTime, InputManager input) { handleSwap(input); foreach (IConsumable item in _slots) { if (item is ProjectileWeapon) { (item as ProjectileWeapon).Update(gameTime); } } }
public override void Update(GameTime gameTime, InputManager input, InventoryManager im) { }
private void handleSwap(InputManager input) { //check for Primary Swap if(input.Item1) { //Change Primary to slot 0 item = slots[0]; currentSlot = 0; } else if (input.Item2) { //Change Primary to slot 1 item = slots[1]; currentSlot = 1; } else if (input.Item3) { //Change Primary to slot 2 item = slots[2]; currentSlot = 2; } //Check for Secondary Swap if (input.Item4) { //Change Secondary to slot 3 item = slots[3]; currentSlot = 3; } else if (input.Item5) { //Change Primary to slot 4 item = slots[4]; currentSlot = 4; } else if (input.Item6) { //Change Primary to slot 5 item = slots[5]; currentSlot = 5; } if (input.fCycle) { //Cycle items forward if (currentSlot == 5) { currentSlot = 0; item = slots[0]; } currentSlot = currentSlot + 1; item = slots[currentSlot]; } if (input.bCycle) { //Cycle items backwards if (currentSlot == 0) { currentSlot = 5; item = slots[5]; } currentSlot = currentSlot + 1; item = slots[currentSlot]; } }
//Runs often public void Update(InputManager input) { handleSwap(input); }
/// <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() { _inputManager = new InputManager(); _weaponManager = new InventoryManager(); gamestate = GameStates.Menu; base.Initialize(); }
private void handleInput(InputManager input, InventoryManager wm) { // Allows the game to exit if (input.Exit) this.PopState = true; if (input.SelectUp) { this.Iterator--; } else if (input.SelectDown) { this.Iterator++; } if (input.Confirm) { if (this.Iterator == 0) { //load game ReplaceState = new Level(1, wm); } else if (this.Iterator == 1) { //call method to load settings this.PopState = true; } else if (this.Iterator == 2) { //quit game this.PopState = true; } this.Iterator = 0; } //Add more select menu logic here as menu items increase }
public override void Update(GameTime gameTime, InputManager input, InventoryManager wm) { handleInput(input, wm); //update logic goes here }
public abstract void Update(GameTime gameTime, InputManager input, InventoryManager im);
public abstract void Update(GameTime gameTime, InputManager input);
private void handleInput(InputManager input) { if (input.Exit) this.PopState = true; _player.MoveDirection = input.MoveDirection; _player.LookDirection = XnaHelper.DirectionBetween(_player.Center, input.MouseLocation); if (input.FirePrimary) { _primaryWeapon.Trigger(_player.Position, input.MouseLocation); } if (input.FireSecondary) { _secondaryWeapon.Trigger(_player.Position, input.MouseLocation); } if (input.TriggerGadget1) { _primaryGadget.Trigger(); } }
private void handleInput(InputManager input) { if (input.Exit) this.PopState = true; if (_blackHole.State == BlackHole.BlackHoleState.Exhausted) return; _player.MoveDirection = input.MoveDirection; _player.LookDirection = XnaHelper.DirectionBetween(_player.Center, input.MouseLocation); if (_player.UnitLifeState == PhysicalUnit.LifeState.Living) { if (input.FirePrimary) { _primaryWeapon.Trigger(_player.Position, input.MouseLocation); } if (input.FireSecondary) { _secondaryWeapon.Trigger(_player.Position, input.MouseLocation); } if (input.UseItem) { _inventoryManager.CurrentItem.Use(input.MouseLocation); } if (input.TriggerGadget1) { _primaryGadget.Trigger(); } } if (input.DebugKey) { _blackHole.Explode(); } }
/// <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() { Window.SetPosition(new Point(0, 0)); _inputManager = new InputManager(); _weaponManager = new InventoryManager(); gamestate = GameStates.Menu; base.Initialize(); }
private void handleInput(InputManager input) { if (input.Exit) this.PopState = true; if (_blackHole.State == BlackHole.BlackHoleState.Exhausted) return; _player.MoveDirection = input.MoveDirection; _player.LookDirection = XnaHelper.DirectionBetween(_player.Position, input.AbsoluteMousePos); if (_player.UnitLifeState == PhysicalUnit.LifeState.Living) { if (input.FirePrimary) { _player.TriggerWeapon(input.AbsoluteMousePos, 0); } else if (input.FireSecondary) { _player.TriggerWeapon(input.AbsoluteMousePos, 1); } if (input.UseItem) { _inventoryManager.CurrentItem.Use(input.AbsoluteMousePos); } if (input.TriggerGadget1) { _primaryGadget.Trigger(); } if (input.TriggerGadget2) { _secondaryGadget.Trigger(); } } }