public BulletPattern Duplicate() { var result = new BulletPattern { Trigger = Trigger.Duplicate(), DelayFrame = DelayFrame, IntervalFrame = IntervalFrame, CoolDownFrame = CoolDownFrame, CoolingDown = CoolingDown, CurrentFrame = CurrentFrame, Playing = Playing, Completed = Completed, BulletCount = BulletCount, Angle = Angle, BulletAngle = BulletAngle, AngleOffset = AngleOffset, AngleOffsetStepper = AngleOffsetStepper, LockedOnAvatar = LockedOnAvatar, CurrentShootAngle = CurrentShootAngle, DestroyableProportion = DestroyableProportion, PosOffset = new Vector2(PosOffset.x, PosOffset.y), RandomAngleRange = new Vector2(RandomAngleRange.x, RandomAngleRange.y), SpeedCorrection = SpeedCorrection, SpeedCorrectionOffset = SpeedCorrectionOffset, LoopAngleOffset = LoopAngleOffset, CurrentBaseAngle = CurrentBaseAngle }; result.RandomSpeedRange = null; if (RandomSpeedRange != null) { result.RandomSpeedRange = new Vector2(((Vector2)RandomSpeedRange).x, ((Vector2)RandomSpeedRange).y); } return(result); }
public SceneActionBuilder AddPattern(BulletPattern pattern) { _action.Patterns.Add(pattern); if (Random.Range(0.0f, 1.0f) <= _action.ShootProbability) { _action.Shoots = true; } return(this); }
private void CalcAngle(BulletPattern pattern) { pattern.CurrentShootAngle += pattern.AngleOffset; pattern.AngleOffset += pattern.AngleOffsetStepper; pattern.AngleOffset = pattern.AngleOffset > 360 ? pattern.AngleOffset - 360 : pattern.AngleOffset; pattern.CurrentShootAngle = pattern.CurrentShootAngle > 360 ? pattern.CurrentShootAngle - 360 : pattern.CurrentShootAngle; }
private static bool IsCoolingDown(BulletPattern pattern) { if (!pattern.CoolingDown) { return(false); } pattern.CurrentFrame--; if (pattern.CurrentFrame <= 0) { pattern.CoolingDown = false; } return(true); }
public BulletPatternBuilder CreatePattern(string name) { if (_patternDictionary.ContainsKey(name)) { Debug.LogError("Can't create pattern with existing name."); return(null); } _currentBuildingPattern = new BulletPattern { Trigger = new ShootOnceAtFirst() }; _patternDictionary.Add(name, _bulletPatterns.Count); _bulletPatterns.Add(_currentBuildingPattern); return(this); }
private void ShootBullet(BulletPattern pattern) { if (ParentController != null) { var defaultAngle = pattern.CurrentShootAngle; // Are we locking on avatar? if (pattern.LockedOnAvatar) { var avaPos = ParentController.GetAvartarPosition(); var pos = new Vector2( transform.position.x + pattern.PosOffset.x, transform.position.y + pattern.PosOffset.y); if (avaPos != null) { var targetVec = new Vector3(((Vector2)avaPos).x - pos.x, ((Vector2)avaPos).y - pos.y, 0); var baseVec = new Vector3(1, 0, 0); // Change our angle and Aim to Avatar if (Vector3.Cross(baseVec, targetVec).z >= 0) { defaultAngle = (int)Vector2.Angle(baseVec, targetVec); } else { defaultAngle = -(int)Vector2.Angle(baseVec, targetVec); } } } defaultAngle += Random.Range(pattern.RandomAngleRange.x, pattern.RandomAngleRange.y); // code to deal with N-way bullet if (pattern.BulletCount % 2 == 0) { var angleCorrection = pattern.BulletAngle / 2; var stepper = 0; var pos = new Vector2( transform.position.x + pattern.PosOffset.x, transform.position.y + pattern.PosOffset.y); for (int i = 0; i < pattern.BulletCount; i = i + 2) { var angle = defaultAngle + angleCorrection + stepper; ParentController.ShootBullet( pos, angle, pattern.DestroyableProportion, pattern.SpeedCorrection, pattern.SpeedCorrectionOffset, pattern.RandomSpeedRange); angle = defaultAngle - angleCorrection - stepper; ParentController.ShootBullet( pos, angle, pattern.DestroyableProportion, pattern.SpeedCorrection, pattern.SpeedCorrectionOffset, pattern.RandomSpeedRange); stepper += pattern.BulletAngle; } } else { var stepper = pattern.BulletAngle; var pos = new Vector2( transform.position.x + pattern.PosOffset.x, transform.position.y + pattern.PosOffset.y); ParentController.ShootBullet( pos, defaultAngle, pattern.DestroyableProportion, pattern.SpeedCorrection, pattern.SpeedCorrectionOffset, pattern.RandomSpeedRange); for (int i = 1; i < pattern.BulletCount; i = i + 2) { var angle = defaultAngle + stepper; ParentController.ShootBullet( pos, angle, pattern.DestroyableProportion, pattern.SpeedCorrection, pattern.SpeedCorrectionOffset, pattern.RandomSpeedRange); angle = defaultAngle - stepper; ParentController.ShootBullet( pos, angle, pattern.DestroyableProportion, pattern.SpeedCorrection, pattern.SpeedCorrectionOffset, pattern.RandomSpeedRange); stepper += pattern.BulletAngle; } } CalcAngle(pattern); } }