public void Execute() { owner.transform.LookAt(PlayerController.Instance.transform); shootTimeElapsed += EnemyController.SM_EXECUTE_RATE; if (shootTimeElapsed >= owner.TimeToShoot) { shootCommand.Execute(); shootTimeElapsed = 0F; } }
/// <summary> /// The method to call to start a shoot attack with the weapon. /// </summary> public override void Shoot() { lock (this) { if (!CurrentWeaponConditionState.CanBeUsed || LastShot.AddSeconds((double)ShotRate) >= DateTime.UtcNow) { return; } LastShot = DateTime.UtcNow; var bulletsForAttack = Math.Min(IsBurstFireEngaged ? 3 : 1, AmmunitionContainer.AmmunitionCount); AmmunitionContainer.AmmunitionCount -= bulletsForAttack; switch (bulletsForAttack) { case 3: // Command would create gun fire sound, // bullets and sound, etc. These // could be done asynchronously. // Would prob be best to have M16 burst // fire shoot commands vs. single fire, etc. // for animation purposes instead of calling // ShootCommand 3 times here. ShootCommand.Execute(); CurrentWeaponConditionState.WeaponUsed(); ShootCommand.Execute(); CurrentWeaponConditionState.WeaponUsed(); ShootCommand.Execute(); CurrentWeaponConditionState.WeaponUsed(); break; case 2: ShootCommand.Execute(); CurrentWeaponConditionState.WeaponUsed(); ShootCommand.Execute(); CurrentWeaponConditionState.WeaponUsed(); break; case 1: ShootCommand.Execute(); CurrentWeaponConditionState.WeaponUsed(); break; default: EmptyGunFireCommand.Execute(); break; } } }
void Update() { if (shallMoveLeft) { ICommand moveCommand = new MoveCommand(Direction.left); moveCommand.Execute(toControl); } if (shallMoveRight) { ICommand moveCommand = new MoveCommand(Direction.right); moveCommand.Execute(toControl); } if (shallShoot) { ICommand shootCommant = new ShootCommand(); shootCommant.Execute(toControl); } }
void Update() { // Every tick the enemy shall fly downward and into the direction of // the player if (player != null) { float xDistance = player.transform.position.x - this.transform.position.x; Direction direction = Direction.left; ICommand moveCommand = new MoveCommand(direction); moveCommand.Execute(toControl); // if distance on the x-axis of this enemies and the players // position is smaller than a given range the enemy shall shoot if (Mathf.Abs(xDistance) < shootingRange) { ICommand shootCommand = new ShootCommand(); shootCommand.Execute(toControl); } } }
public virtual void Execute() { shootCommand.Execute(); }